Skip to content

Commit

Permalink
chat: smoother container (fixes #7598) (#7599)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Mutugiii and dogi authored Oct 10, 2024
1 parent b79469b commit 0ec7bca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 41 deletions.
56 changes: 18 additions & 38 deletions chatapi/src/config/ai-providers.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { GoogleGenerativeAI } from '@google/generative-ai';
import OpenAI from 'openai';

Expand All @@ -15,69 +16,48 @@ async function getConfig(): Promise<ModelsDocument | undefined> {
const doc = allDocs.rows[0].doc as unknown as ModelsDocument;
return doc;
} else {
throw new Error('No documents found in configurationDB');
console.error('No documents found in configurationDB');
}
} catch (error: any) {
throw new Error(`Error fetching models config: ${error.message}`);
console.error(`Error fetching models config: ${error}`);
}
}

const initializeProviders = async () => {
const initialize = async () => {
try {
const doc = await getConfig();
if (!doc || !doc.keys) {
throw new Error('API Keys configuration not found');
if (!doc) {
console.error('Configuration not found');
}

keys = {
'openai': new OpenAI({
'apiKey': doc.keys.openai || '',
'apiKey': doc?.keys.openai || '',
}),
'perplexity': new OpenAI({
'apiKey': doc.keys.perplexity || '',
'apiKey': doc?.keys.perplexity || '',
'baseURL': 'https://api.perplexity.ai',
}),
'gemini': new GoogleGenerativeAI(doc.keys.gemini || '')
'gemini': new GoogleGenerativeAI(doc?.keys.gemini || '')
};
} catch (error: any) {
throw new Error(`Error initializing providers: ${error.message}`);
}
};

const getModels = async () => {
try {
const doc = await getConfig();
if (!doc || !doc.models) {
throw new Error('Models configuration not found');
}
models = {
'openai': { 'ai': keys.openai, 'defaultModel': doc.models.openai || 'gpt-3.5-turbo' },
'perplexity': { 'ai': keys.perplexity, 'defaultModel': doc.models.perplexity || 'llama-3-sonar-small-32k-online' },
'gemini': { 'ai': keys.gemini, 'defaultModel': doc.models.gemini || 'gemini-pro' },
'openai': { 'ai': keys.openai, 'defaultModel': doc?.models.openai || 'gpt-3.5-turbo' },
'perplexity': { 'ai': keys.perplexity, 'defaultModel': doc?.models.perplexity || 'llama-3-sonar-small-32k-online' },
'gemini': { 'ai': keys.gemini, 'defaultModel': doc?.models.gemini || 'gemini-pro' },
};
} catch (error: any) {
throw new Error(`Error getting provider models: ${error.message}`);
}
};

const getAssistant = async () => {
try {
const doc = await getConfig();
if (!doc || !doc.assistant) {
throw new Error('Assistant configuration not found');
}
assistant = {
'name': doc.assistant.name,
'instructions': doc.assistant.instructions,
'name': doc?.assistant?.name || '',
'instructions': doc?.assistant?.instructions || '',
};
} catch (error: any) {
throw new Error(`Error getting assistant configs: ${error.message}`);
} catch (error) {
console.error(`Error initializing configs: ${error}`);
}
};

(async () => {
await initializeProviders();
await getModels();
await getAssistant();
await initialize();
})();

export { keys, models, assistant };
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "planet",
"license": "AGPL-3.0",
"version": "0.14.88",
"version": "0.14.89",
"myplanet": {
"latest": "v0.20.8",
"min": "v0.19.8"
"latest": "v0.20.13",
"min": "v0.19.13"
},
"scripts": {
"ng": "ng",
Expand Down

0 comments on commit 0ec7bca

Please sign in to comment.