Add Groq as chat completion source

This commit is contained in:
Cohee
2024-05-05 18:53:12 +03:00
parent 31f1b34911
commit 181b5aff97
11 changed files with 165 additions and 6 deletions

View File

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

View File

@@ -15,6 +15,7 @@ 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';
const API_GROQ = 'https://api.groq.com/openai/v1';
/**
* Applies a post-processing step to the generated messages.
@@ -879,6 +880,11 @@ router.post('/generate', jsonParser, function (request, response) {
headers = {};
bodyParams = {};
request.body.messages = postProcessPrompt(request.body.messages, 'claude', request.body.char_name, request.body.user_name);
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.GROQ) {
apiUrl = API_GROQ;
apiKey = readSecret(request.user.directories, SECRET_KEYS.GROQ);
headers = {};
bodyParams = {};
} else {
console.log('This chat completion source is not supported yet.');
return response.status(400).send({ error: true });

View File

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