fix bingai bugs and add chatgptbrowser client

This commit is contained in:
Daniel Avila 2023-02-21 21:30:56 -05:00
parent 168d5e8075
commit 16932b37c0
7 changed files with 42 additions and 46 deletions

View file

@ -1,4 +1,3 @@
// import { BingAIClient } from '@waylaidwanderer/chatgpt-api';
require('dotenv').config();
const { KeyvFile } = require('keyv-file');
@ -18,21 +17,11 @@ const askBing = async ({ text, progressCallback, convo }) => {
onProgress: async (partialRes) => await progressCallback(partialRes),
};
if (!!convo) {
if (convo) {
options = { ...options, ...convo };
}
const res = await bingAIClient.sendMessage(text, options
// Options for reference
// {
// conversationSignature: response.conversationSignature,
// conversationId: response.conversationId,
// clientId: response.clientId,
// invocationId: response.invocationId,
// onProgress: (token) => {
// process.stdout.write(token);
// },
// }
);
return res;

View file

@ -1,13 +1,11 @@
require('dotenv').config();
const Keyv = require('keyv');
const { KeyvFile } = require('keyv-file');
const proxyOptions = {
reverseProxyUrl: 'https://chatgpt.pawan.krd/api/completions',
modelOptions: {
model: 'text-davinci-002-render'
},
debug: false
// 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 = {
@ -18,14 +16,27 @@ const davinciOptions = {
};
const askClient = async ({ model, text, progressCallback, convo }) => {
// const clientOptions = model === 'chatgpt' ? proxyOptions : davinciOptions;
const ChatGPTClient = (await import('@waylaidwanderer/chatgpt-api')).default;
const client = new ChatGPTClient(process.env.OPENAI_KEY, davinciOptions, {
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 store = {
store: new KeyvFile({ filename: 'cache.json' })
});
};
const params =
model === 'chatgpt'
? [clientOptions, store]
: [
process.env.OPENAI_KEY,
clientOptions,
store
];
const client = new modelClient(...params);
let options = {
onProgress: async (partialRes) => await progressCallback(partialRes)
// onProgress: progressCallback
};
if (!!convo.parentMessageId && !!convo.conversationId) {

View file

@ -22,14 +22,14 @@ const ask = async (question, progressCallback, convo) => {
return res;
};
const titleConvo = async (message, response) => {
const titleConvo = async (message, response, model) => {
const configuration = new Configuration({
apiKey: process.env.OPENAI_KEY
});
const openai = new OpenAIApi(configuration);
const completion = await openai.createCompletion({
model: 'text-davinci-002',
prompt: `Write a short title in title case, ideally in 5 words or less, and do not refer to the user or GPT, that summarizes this conversation:\nUser:"${message}"\nGPT:"${response}"\nTitle: `
prompt: `Write a short title in title case, ideally in 5 words or less, and do not refer to the user or ${model}, that summarizes this conversation:\nUser:"${message}"\n${model}:"${response}"\nTitle: `
});
return completion.data.choices[0].text.replace(/\n/g, '');