Merge branch 'staging' into neo-server

This commit is contained in:
Cohee
2024-04-20 02:56:05 +03:00
16 changed files with 256 additions and 19 deletions

View File

@ -191,6 +191,7 @@ const CHAT_COMPLETION_SOURCES = {
MISTRALAI: 'mistralai',
CUSTOM: 'custom',
COHERE: 'cohere',
PERPLEXITY: 'perplexity',
};
const UPLOADS_PATH = './uploads';

View File

@ -14,6 +14,7 @@ const API_OPENAI = 'https://api.openai.com/v1';
const API_CLAUDE = 'https://api.anthropic.com/v1';
const API_MISTRAL = 'https://api.mistral.ai/v1';
const API_COHERE = 'https://api.cohere.ai/v1';
const API_PERPLEXITY = 'https://api.perplexity.ai';
/**
* Applies a post-processing step to the generated messages.
@ -439,7 +440,7 @@ async function sendAI21Request(request, response) {
} else {
console.log(r.completions[0].data.text);
}
const reply = { choices: [{ 'message': { 'content': r.completions[0].data.text } }] };
const reply = { choices: [{ 'message': { 'content': r.completions?.[0]?.data?.text } }] };
return response.send(reply);
})
.catch(err => {
@ -896,6 +897,12 @@ router.post('/generate', jsonParser, function (request, response) {
request.body.char_name,
request.body.user_name);
}
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.PERPLEXITY) {
apiUrl = API_PERPLEXITY;
apiKey = readSecret(SECRET_KEYS.PERPLEXITY);
headers = {};
bodyParams = {};
request.body.messages = postProcessPrompt(request.body.messages, 'claude', request.body.char_name, request.body.user_name);
} else {
console.log('This chat completion source is not supported yet.');
return response.status(400).send({ error: true });

View File

@ -36,6 +36,7 @@ const SECRET_KEYS = {
KOBOLDCPP: 'api_key_koboldcpp',
LLAMACPP: 'api_key_llamacpp',
COHERE: 'api_key_cohere',
PERPLEXITY: 'api_key_perplexity',
};
// These are the keys that are safe to expose, even if allowKeysExposure is false