Rolled back to v0.0.2

This commit is contained in:
Danny Avila 2023-03-10 12:55:45 -05:00
parent 57d3025717
commit 72ff47e204
20 changed files with 87 additions and 142 deletions

View file

@ -2,32 +2,27 @@ require('dotenv').config();
const { KeyvFile } = require('keyv-file');
const askBing = async ({ text, progressCallback, convo }) => {
const { BingAIClient } = await import('@waylaidwanderer/chatgpt-api');
const { BingAIClient } = (await import('@waylaidwanderer/chatgpt-api'));
const clientOptions = {
const bingAIClient = new BingAIClient({
// "_U" cookie from bing.com
userToken: process.env.BING_TOKEN,
// If the above doesn't work, provide all your cookies as a string instead
// cookies: '',
debug: false,
cache: { store: new KeyvFile({ filename: './data/cache.json' }) }
};
const cookies = process.env.BING_COOKIES;
if (cookies?.length > 0) {
clientOptions.cookies = cookies;
delete clientOptions.userToken;
}
const bingAIClient = new BingAIClient(clientOptions);
});
let options = {
onProgress: async (partialRes) => await progressCallback(partialRes)
onProgress: async (partialRes) => await progressCallback(partialRes),
};
if (convo) {
options = { ...options, ...convo };
}
const res = await bingAIClient.sendMessage(text, options);
const res = await bingAIClient.sendMessage(text, options
);
return res;

View file

@ -7,7 +7,6 @@ const clientOptions = {
// Access token from https://chat.openai.com/api/auth/session
accessToken: process.env.CHATGPT_TOKEN,
// debug: true
proxy: process.env.PROXY || null,
};
const browserClient = async ({ text, progressCallback, convo }) => {

View file

@ -5,7 +5,6 @@ const clientOptions = {
modelOptions: {
model: 'gpt-3.5-turbo'
},
proxy: process.env.PROXY || null,
debug: false
};

View file

@ -5,7 +5,6 @@ const clientOptions = {
modelOptions: {
model: 'gpt-3.5-turbo'
},
proxy: process.env.PROXY || null,
debug: false
};

View file

@ -2,39 +2,30 @@ require('dotenv').config();
const { KeyvFile } = require('keyv-file');
const askSydney = async ({ text, progressCallback, convo }) => {
const { BingAIClient } = await import('@waylaidwanderer/chatgpt-api');
const { BingAIClient } = (await import('@waylaidwanderer/chatgpt-api'));
const clientOptions = {
const sydneyClient = new BingAIClient({
// "_U" cookie from bing.com
userToken: process.env.BING_TOKEN,
// If the above doesn't work, provide all your cookies as a string instead
// cookies: '',
debug: false,
cache: { store: new KeyvFile({ filename: './data/cache.json' }) }
};
const cookies = process.env.BING_COOKIES;
if (cookies?.length > 0) {
clientOptions.cookies = cookies;
delete clientOptions.userToken;
}
const sydneyClient = new BingAIClient(clientOptions);
});
let options = {
jailbreakConversationId: true,
onProgress: async (partialRes) => await progressCallback(partialRes)
onProgress: async (partialRes) => await progressCallback(partialRes),
};
if (convo.parentMessageId) {
options = {
...options,
jailbreakConversationId: convo.jailbreakConversationId,
parentMessageId: convo.parentMessageId
};
options = { ...options, jailbreakConversationId: convo.jailbreakConversationId, parentMessageId: convo.parentMessageId };
}
console.log('sydney options', options);
const res = await sydneyClient.sendMessage(text, options);
const res = await sydneyClient.sendMessage(text, options
);
return res;

View file

@ -1,32 +1,24 @@
const { Configuration, OpenAIApi } = require('openai');
const titleConvo = async ({ message, response, model }) => {
try {
const configuration = new Configuration({
apiKey: process.env.OPENAI_KEY
});
const openai = new OpenAIApi(configuration);
const completion = await openai.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: [
{
role: 'system',
content:
'You are a title-generator with one job: titling the conversation provided by a user in title case.'
},
{
role: 'user',
content: `In 5 words or less, summarize the conversation below with a title in title case. Don't refer to the participants of the conversation by name. Do not include punctuation or quotation marks. Your response should be in title case, exclusively containing the title. Conversation:\n\nUser: "${message}"\n\n${model}: "${response}"\n\nTitle: `
}
]
});
const configuration = new Configuration({
apiKey: process.env.OPENAI_KEY
});
const openai = new OpenAIApi(configuration);
const completion = await openai.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: [
{
role: 'system',
content:
'You are a title-generator with one job: titling the conversation provided by a user in title case.'
},
{ role: 'user', content: `In 5 words or less, summarize the conversation below with a title in title case. Don't refer to the participants of the conversation by name. Do not include punctuation or quotation marks. Your response should be in title case, exclusively containing the title. Conversation:\n\nUser: "${message}"\n\n${model}: "${response}"\n\nTitle: ` },
]
});
//eslint-disable-next-line
return completion.data.choices[0].message.content.replace(/["\.]/g, '');
} catch (error) {
console.log(error);
return 'New Chat';
}
//eslint-disable-next-line
return completion.data.choices[0].message.content.replace(/["\.]/g, '');
};
module.exports = titleConvo;

View file

@ -1,29 +1,28 @@
const express = require('express');
const dbConnect = require('../models/dbConnect');
const path = require('path');
const cors = require('cors');
const routes = require('./routes');
const app = express();
const port = process.env.PORT || 3080;
const host = process.env.HOST || 'localhost'
const projectPath = path.join(__dirname, '..', '..', 'client');
dbConnect().then(() => console.log('Connected to MongoDB'));
app.use(cors());
app.use(express.json());
app.use(express.static(path.join(projectPath, 'public')));
app.get('/', function (req, res) {
console.log(path.join(projectPath, 'public', 'index.html'));
res.sendFile(path.join(projectPath, 'public', 'index.html'));
});
app.use('/api/ask', routes.ask);
app.use('/api/messages', routes.messages);
app.use('/api/convos', routes.convos);
app.use('/api/customGpts', routes.customGpts);
app.use('/api/prompts', routes.prompts);
app.listen(port, host, () => {
console.log(`Server listening at http://${host}:${port}`);
});
const express = require('express');
const dbConnect = require('../models/dbConnect');
const path = require('path');
const cors = require('cors');
const routes = require('./routes');
const app = express();
const port = process.env.PORT || 3080;
const projectPath = path.join(__dirname, '..', '..', 'client');
dbConnect().then(() => console.log('Connected to MongoDB'));
app.use(cors());
app.use(express.json());
app.use(express.static(path.join(projectPath, 'public')));
app.get('/', function (req, res) {
console.log(path.join(projectPath, 'public', 'index.html'));
res.sendFile(path.join(projectPath, 'public', 'index.html'));
});
app.use('/api/ask', routes.ask);
app.use('/api/messages', routes.messages);
app.use('/api/convos', routes.convos);
app.use('/api/customGpts', routes.customGpts);
app.use('/api/prompts', routes.prompts);
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
});