mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
feat: sydney is functional
This commit is contained in:
parent
0f54251459
commit
69b3edc52c
15 changed files with 157 additions and 22 deletions
|
|
@ -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,
|
||||
store: new KeyvFile({ filename: './data/cache.json' })
|
||||
cache: new KeyvFile({ filename: './data/cache.json' })
|
||||
});
|
||||
|
||||
let options = {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ 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
|
||||
accessToken: process.env.CHATGPT_TOKEN,
|
||||
// debug: true
|
||||
};
|
||||
|
||||
const browserClient = async ({ text, progressCallback, convo }) => {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ const { askClient } = require('./chatgpt-client');
|
|||
const { browserClient } = require('./chatgpt-browser');
|
||||
const customClient = require('./chatgpt-custom');
|
||||
const { askBing } = require('./bingai');
|
||||
const { askSydney } = require('./sydney');
|
||||
const titleConvo = require('./titleConvo');
|
||||
const detectCode = require('./detectCode');
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ module.exports = {
|
|||
browserClient,
|
||||
customClient,
|
||||
askBing,
|
||||
askSydney,
|
||||
titleConvo,
|
||||
detectCode
|
||||
};
|
||||
34
api/app/sydney.js
Normal file
34
api/app/sydney.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
require('dotenv').config();
|
||||
const { KeyvFile } = require('keyv-file');
|
||||
|
||||
const askSydney = async ({ text, progressCallback, convo }) => {
|
||||
const { BingAIClient } = (await import('@waylaidwanderer/chatgpt-api'));
|
||||
|
||||
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: new KeyvFile({ filename: './data/cache.json' })
|
||||
});
|
||||
|
||||
let options = {
|
||||
jailbreakConversationId: true,
|
||||
onProgress: async (partialRes) => await progressCallback(partialRes),
|
||||
};
|
||||
|
||||
if (convo) {
|
||||
options = { ...options, ...convo };
|
||||
}
|
||||
|
||||
const res = await sydneyClient.sendMessage(text, options
|
||||
);
|
||||
|
||||
return res;
|
||||
|
||||
// for reference:
|
||||
// https://github.com/waylaidwanderer/node-chatgpt-api/blob/main/demos/use-bing-client.js
|
||||
};
|
||||
|
||||
module.exports = { askSydney };
|
||||
|
|
@ -15,6 +15,9 @@ const convoSchema = mongoose.Schema({
|
|||
type: String,
|
||||
default: 'New conversation'
|
||||
},
|
||||
jailbreakConversationId: {
|
||||
type: String
|
||||
},
|
||||
conversationSignature: {
|
||||
type: String
|
||||
},
|
||||
|
|
|
|||
14
api/package-lock.json
generated
14
api/package-lock.json
generated
|
|
@ -11,7 +11,7 @@
|
|||
"dependencies": {
|
||||
"@keyv/mongo": "^2.1.8",
|
||||
"@vscode/vscode-languagedetection": "^1.0.22",
|
||||
"@waylaidwanderer/chatgpt-api": "^1.15.1",
|
||||
"@waylaidwanderer/chatgpt-api": "^1.28.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.3",
|
||||
"express": "^4.18.2",
|
||||
|
|
@ -1492,9 +1492,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@waylaidwanderer/chatgpt-api": {
|
||||
"version": "1.26.1",
|
||||
"resolved": "https://registry.npmjs.org/@waylaidwanderer/chatgpt-api/-/chatgpt-api-1.26.1.tgz",
|
||||
"integrity": "sha512-cv9NqC0owO2EGCkVg4VQO0lcA5pDgv2VJrBE/0P6En27/v0gIC+7MedowX3htIUi4GLDkgyyDDDimst2i8ReMw==",
|
||||
"version": "1.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@waylaidwanderer/chatgpt-api/-/chatgpt-api-1.28.0.tgz",
|
||||
"integrity": "sha512-753dc/Eaf+1XmSXrLu+99LR4N+ACL7fQyA7GlsUXjRVXcH+m/iDqqXrU+o1JKGy84VlNKokAvq3oy9LVunKCIw==",
|
||||
"dependencies": {
|
||||
"@dqbd/tiktoken": "^0.4.0",
|
||||
"@fastify/cors": "^8.2.0",
|
||||
|
|
@ -5781,9 +5781,9 @@
|
|||
"integrity": "sha512-rQ/BgMyLuIXSmbA0MSkIPHtcOw14QkeDbAq19sjvaS9LTRr905yij0S8lsyqN5JgOsbtIx7pAcyOxFMzPmqhZQ=="
|
||||
},
|
||||
"@waylaidwanderer/chatgpt-api": {
|
||||
"version": "1.26.1",
|
||||
"resolved": "https://registry.npmjs.org/@waylaidwanderer/chatgpt-api/-/chatgpt-api-1.26.1.tgz",
|
||||
"integrity": "sha512-cv9NqC0owO2EGCkVg4VQO0lcA5pDgv2VJrBE/0P6En27/v0gIC+7MedowX3htIUi4GLDkgyyDDDimst2i8ReMw==",
|
||||
"version": "1.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@waylaidwanderer/chatgpt-api/-/chatgpt-api-1.28.0.tgz",
|
||||
"integrity": "sha512-753dc/Eaf+1XmSXrLu+99LR4N+ACL7fQyA7GlsUXjRVXcH+m/iDqqXrU+o1JKGy84VlNKokAvq3oy9LVunKCIw==",
|
||||
"requires": {
|
||||
"@dqbd/tiktoken": "^0.4.0",
|
||||
"@fastify/cors": "^8.2.0",
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
"dependencies": {
|
||||
"@keyv/mongo": "^2.1.8",
|
||||
"@vscode/vscode-languagedetection": "^1.0.22",
|
||||
"@waylaidwanderer/chatgpt-api": "^1.15.1",
|
||||
"@waylaidwanderer/chatgpt-api": "^1.28.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.3",
|
||||
"express": "^4.18.2",
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ const express = require('express');
|
|||
const crypto = require('crypto');
|
||||
const router = express.Router();
|
||||
const askBing = require('./askBing');
|
||||
const askSydney = require('./askSydney');
|
||||
const {
|
||||
titleConvo,
|
||||
askClient,
|
||||
|
|
@ -12,7 +13,7 @@ const {
|
|||
const { getConvo, saveMessage, deleteMessages, saveConvo } = require('../../models');
|
||||
const { handleError, sendMessage } = require('./handlers');
|
||||
|
||||
router.use('/bing', askBing);
|
||||
router.use('/bing', askSydney);
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
let { model, text, parentMessageId, conversationId, chatGptLabel, promptPrefix } = req.body;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,11 @@ router.post('/', async (req, res) => {
|
|||
await saveMessage(userMessage);
|
||||
|
||||
if (!convo.conversationSignature) {
|
||||
response.title = await titleConvo(text, response.response, model);
|
||||
response.title = await titleConvo({
|
||||
model,
|
||||
message: text,
|
||||
response: JSON.stringify(response.response)
|
||||
});
|
||||
}
|
||||
|
||||
response.text = response.response;
|
||||
|
|
|
|||
77
api/server/routes/askSydney.js
Normal file
77
api/server/routes/askSydney.js
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
const express = require('express');
|
||||
const crypto = require('crypto');
|
||||
const router = express.Router();
|
||||
const { titleConvo, askSydney } = require('../../app/');
|
||||
const { saveMessage, deleteMessages, saveConvo } = require('../../models');
|
||||
const { handleError, sendMessage } = require('./handlers');
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const { model, text, ...convo } = req.body;
|
||||
if (!text.trim().includes(' ') && text.length < 5) {
|
||||
return handleError(res, 'Prompt empty or too short');
|
||||
}
|
||||
|
||||
const userMessageId = crypto.randomUUID();
|
||||
let userMessage = { id: userMessageId, sender: 'User', text };
|
||||
|
||||
console.log('ask log', { model, ...userMessage, ...convo });
|
||||
|
||||
res.writeHead(200, {
|
||||
Connection: 'keep-alive',
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache, no-transform',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'X-Accel-Buffering': 'no'
|
||||
});
|
||||
|
||||
try {
|
||||
let tokens = '';
|
||||
const progressCallback = async (partial) => {
|
||||
tokens += partial === text ? '' : partial;
|
||||
// tokens = appendCode(tokens);
|
||||
sendMessage(res, { text: tokens, message: true });
|
||||
};
|
||||
|
||||
let response = await askSydney({
|
||||
text,
|
||||
progressCallback,
|
||||
convo
|
||||
});
|
||||
|
||||
console.log('CLIENT RESPONSE');
|
||||
console.dir(response, { depth: null });
|
||||
|
||||
userMessage.conversationSignature =
|
||||
convo.conversationSignature || response.conversationSignature;
|
||||
userMessage.conversationId = convo.conversationId || response.conversationId;
|
||||
userMessage.invocationId = response.invocationId;
|
||||
userMessage.jailbreakConversationId = convo.jailbreakConversationId || response.jailbreakConversationId;
|
||||
await saveMessage(userMessage);
|
||||
|
||||
if (!convo.conversationSignature) {
|
||||
response.title = await titleConvo({
|
||||
model,
|
||||
message: text,
|
||||
response: JSON.stringify(response.response)
|
||||
});
|
||||
}
|
||||
|
||||
response.text = response.response;
|
||||
response.id = response.details.messageId;
|
||||
response.suggestions =
|
||||
response.details.suggestedResponses &&
|
||||
response.details.suggestedResponses.map((s) => s.text);
|
||||
response.sender = model;
|
||||
response.final = true;
|
||||
await saveMessage(response);
|
||||
await saveConvo(response);
|
||||
sendMessage(res, response);
|
||||
res.end();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
await deleteMessages({ id: userMessageId });
|
||||
handleError(res, error.message);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -34,11 +34,12 @@ export default function Conversation({
|
|||
const convo = { title, error: false, conversationId: id, chatGptLabel, promptPrefix };
|
||||
|
||||
if (bingData) {
|
||||
const { conversationSignature, clientId, invocationId } = bingData;
|
||||
const { conversationSignature, jailbreakConversationId, clientId, invocationId } = bingData;
|
||||
dispatch(
|
||||
setConversation({
|
||||
...convo,
|
||||
parentMessageId: null,
|
||||
jailbreakConversationId,
|
||||
conversationSignature,
|
||||
clientId,
|
||||
invocationId
|
||||
|
|
@ -49,6 +50,7 @@ export default function Conversation({
|
|||
setConversation({
|
||||
...convo,
|
||||
parentMessageId,
|
||||
jailbreakConversationId: null,
|
||||
conversationSignature: null,
|
||||
clientId: null,
|
||||
invocationId: null
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export default function Conversations({ conversations, conversationId, showMore
|
|||
conversations.map((convo) => {
|
||||
const bingData = convo.conversationSignature
|
||||
? {
|
||||
jailbreakConversationId: convo.jailbreakConversationId,
|
||||
conversationSignature: convo.conversationSignature,
|
||||
clientId: convo.clientId,
|
||||
invocationId: convo.invocationId
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ export default function TextChat({ messages }) {
|
|||
title,
|
||||
conversationId,
|
||||
parentMessageId: id,
|
||||
jailbreakConversationId: null,
|
||||
conversationSignature: null,
|
||||
clientId: null,
|
||||
invocationId: null,
|
||||
|
|
@ -69,10 +70,18 @@ export default function TextChat({ messages }) {
|
|||
convo.conversationId === null &&
|
||||
convo.invocationId === null
|
||||
) {
|
||||
const { title, conversationSignature, clientId, conversationId, invocationId } = data;
|
||||
const {
|
||||
title,
|
||||
jailbreakConversationId,
|
||||
conversationSignature,
|
||||
clientId,
|
||||
conversationId,
|
||||
invocationId
|
||||
} = data;
|
||||
dispatch(
|
||||
setConversation({
|
||||
title,
|
||||
jailbreakConversationId,
|
||||
conversationSignature,
|
||||
clientId,
|
||||
conversationId,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ const initialState = {
|
|||
title: 'ChatGPT Clone',
|
||||
conversationId: null,
|
||||
parentMessageId: null,
|
||||
jailbreakConversationId: null,
|
||||
conversationSignature: null,
|
||||
clientId: null,
|
||||
invocationId: null,
|
||||
|
|
|
|||
|
|
@ -16,16 +16,16 @@ const initialState = {
|
|||
_id: '2',
|
||||
name: 'BingAI',
|
||||
value: 'bingai'
|
||||
}
|
||||
// {
|
||||
// _id: '3',
|
||||
// name: 'ChatGPT',
|
||||
// value: 'chatgptBrowser'
|
||||
// }
|
||||
},
|
||||
{
|
||||
_id: '3',
|
||||
name: 'ChatGPT',
|
||||
value: 'chatgptBrowser'
|
||||
},
|
||||
],
|
||||
modelMap: {},
|
||||
// initial: { chatgpt: true, chatgptCustom: true, bingai: true, chatgptBrowser: true }
|
||||
initial: { chatgpt: true, chatgptCustom: true, bingai: true, }
|
||||
initial: { chatgpt: true, chatgptCustom: true, bingai: true, chatgptBrowser: true }
|
||||
// initial: { chatgpt: true, chatgptCustom: true, bingai: true, }
|
||||
};
|
||||
|
||||
const currentSlice = createSlice({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue