add official api, remove davinci, organize root dir

This commit is contained in:
Daniel Avila 2023-03-01 21:39:57 -05:00
parent 90ac43c8c5
commit 1f270d349a
12 changed files with 75 additions and 45 deletions

View file

@ -10,7 +10,7 @@ const askBing = async ({ text, progressCallback, convo }) => {
// If the above doesn't work, provide all your cookies as a string instead
// cookies: '',
debug: false,
cache: new KeyvFile({ filename: 'bingcache.json' })
store: new KeyvFile({ filename: './data/cache.json' })
});
let options = {

32
app/chatgpt-browser.js Normal file
View file

@ -0,0 +1,32 @@
require('dotenv').config();
const { KeyvFile } = require('keyv-file');
const clientOptions = {
// Warning: This will expose your access token to a third party. Consider the risks before using this.
reverseProxyUrl: 'https://chatgpt.duti.tech/api/conversation',
// Access token from https://chat.openai.com/api/auth/session
accessToken: process.env.CHATGPT_TOKEN
};
const browserClient = async ({ text, progressCallback, convo }) => {
const { ChatGPTBrowserClient } = await import('@waylaidwanderer/chatgpt-api');
const store = {
store: new KeyvFile({ filename: './data/cache.json' })
};
const client = new ChatGPTBrowserClient(clientOptions, store);
let options = {
onProgress: async (partialRes) => await progressCallback(partialRes)
};
if (!!convo.parentMessageId && !!convo.conversationId) {
options = { ...options, ...convo };
}
const res = await client.sendMessage(text, options);
return res;
};
module.exports = { browserClient };

View file

@ -1,39 +1,20 @@
require('dotenv').config();
const { KeyvFile } = require('keyv-file');
const proxyOptions = {
// Warning: This will expose your access token to a third party. Consider the risks before using this.
reverseProxyUrl: 'https://chatgpt.duti.tech/api/conversation',
// Access token from https://chat.openai.com/api/auth/session
accessToken: process.env.CHATGPT_TOKEN
};
const davinciOptions = {
const clientOptions = {
modelOptions: {
model: 'text-davinci-003'
model: 'gpt-3.5-turbo'
},
debug: false
};
const askClient = async ({ model, text, progressCallback, convo }) => {
const davinciClient = (await import('@waylaidwanderer/chatgpt-api')).default;
const { ChatGPTBrowserClient } = await import('@waylaidwanderer/chatgpt-api');
const clientOptions = model === 'chatgpt' ? proxyOptions : davinciOptions;
const modelClient = model === 'chatgpt' ? ChatGPTBrowserClient : davinciClient;
const askClient = async ({ text, progressCallback, convo }) => {
const ChatGPTClient = (await import('@waylaidwanderer/chatgpt-api')).default;
const store = {
store: new KeyvFile({ filename: 'cache.json' })
store: new KeyvFile({ filename: './data/cache.json' })
};
const params =
model === 'chatgpt'
? [clientOptions, store]
: [
process.env.OPENAI_KEY,
clientOptions,
store
];
const client = new modelClient(...params);
const client = new ChatGPTClient(process.env.OPENAI_KEY, clientOptions, store);
let options = {
onProgress: async (partialRes) => await progressCallback(partialRes)

View file

@ -1,9 +1,11 @@
const { titleConvo } = require('./chatgpt');
const { askClient } = require('./chatgpt-client');
const { browserClient } = require('./chatgpt-browser');
const { askBing } = require('./bingai');
module.exports = {
titleConvo,
askClient,
askBing,
browserClient,
};