diff --git a/sample.config.toml b/sample.config.toml index 50ba95d..76f16a2 100644 --- a/sample.config.toml +++ b/sample.config.toml @@ -8,6 +8,7 @@ OPENAI = "" # OpenAI API key - sk-1234567890abcdef1234567890abcdef GROQ = "" # Groq API key - gsk_1234567890abcdef1234567890abcdef ANTHROPIC = "" # Anthropic API key - sk-ant-1234567890abcdef1234567890abcdef GEMINI = "" # Gemini API key - sk-1234567890abcdef1234567890abcdef +DEEPINFRA = "" # DeepInfra API key - 1234567890abcdef1234567890abcdef [API_ENDPOINTS] SEARXNG = "http://localhost:32768" # SearxNG API URL diff --git a/src/config.ts b/src/config.ts index 001c259..0de9153 100644 --- a/src/config.ts +++ b/src/config.ts @@ -15,6 +15,7 @@ interface Config { GROQ: string; ANTHROPIC: string; GEMINI: string; + DEEPINFRA: string; }; API_ENDPOINTS: { SEARXNG: string; @@ -46,6 +47,8 @@ export const getAnthropicApiKey = () => loadConfig().API_KEYS.ANTHROPIC; export const getGeminiApiKey = () => loadConfig().API_KEYS.GEMINI; +export const getDeepInftaApiKeys = () => loadConfig().API_KEYS.DEEPINFRA; + export const getSearxngApiEndpoint = () => process.env.SEARXNG_API_URL || loadConfig().API_ENDPOINTS.SEARXNG; diff --git a/src/lib/providers/deepinfra.ts b/src/lib/providers/deepinfra.ts new file mode 100644 index 0000000..11eebbe --- /dev/null +++ b/src/lib/providers/deepinfra.ts @@ -0,0 +1,76 @@ +import { DeepInfraEmbeddings } from "@langchain/community/embeddings/deepinfra"; +import { ChatDeepInfra } from "@langchain/community/chat_models/deepinfra"; +import { getDeepInftaApiKeys } from "../../config"; +import logger from '../../utils/logger'; + +export const loadDeepInfraChatModels = async () => { + const deepinfraApiKey = getDeepInftaApiKeys(); + + if (!deepinfraApiKey) return {}; + + try { + const chatModels = { + 'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo': { + displayName: 'LLaMA 3.1 70B Turbo', + model: new ChatDeepInfra({ + model: 'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo', + temperature: 0.7, + apiKey: deepinfraApiKey, + }), + }, + 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo': { + displayName: 'LLaMA 3.1 8B Turbo', + model: new ChatDeepInfra({ + model: 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo', + temperature: 0.7, + apiKey: deepinfraApiKey, + }), + }, + 'meta-llama/Meta-Llama-3.1-70B-Instruct': { + displayName: 'LLaMA 3.1 70B', + model: new ChatDeepInfra({ + model: 'meta-llama/Meta-Llama-3.1-70B-Instruct', + temperature: 0.7, + apiKey: deepinfraApiKey, + }), + }, + 'meta-llama/Meta-Llama-3.1-8B-Instruct': { + displayName: 'LLaMA 3.1 8B', + model: new ChatDeepInfra({ + model: 'meta-llama/Meta-Llama-3.1-8B-Instruct', + temperature: 0.7, + apiKey: deepinfraApiKey, + }), + }, + }; + + return chatModels; + } catch (err) { + logger.error(`Error loading Gemini models: ${err}`); + return {}; + } + }; + + export const loadDeepInfraEmbeddingsModels = async () => { + const deepinfraApiKey = getDeepInftaApiKeys(); + + if (!deepinfraApiKey) return {}; + + try { + const embeddingModels = { + 'BAAI/bge-m3': { + displayName: 'BAAI/bge-m3', + model: new DeepInfraEmbeddings({ + apiToken: deepinfraApiKey, + modelName: 'BAAI/bge-m3', + }), + }, + }; + + return embeddingModels; + } catch (err) { + logger.error(`Error loading Gemini embeddings model: ${err}`); + return {}; + } + }; + \ No newline at end of file diff --git a/src/lib/providers/index.ts b/src/lib/providers/index.ts index 98846e7..2f29601 100644 --- a/src/lib/providers/index.ts +++ b/src/lib/providers/index.ts @@ -4,6 +4,7 @@ import { loadOpenAIChatModels, loadOpenAIEmbeddingsModels } from './openai'; import { loadAnthropicChatModels } from './anthropic'; import { loadTransformersEmbeddingsModels } from './transformers'; import { loadGeminiChatModels, loadGeminiEmbeddingsModels } from './gemini'; +import { loadDeepInfraChatModels, loadDeepInfraEmbeddingsModels } from './deepinfra'; const chatModelProviders = { openai: loadOpenAIChatModels, @@ -11,6 +12,7 @@ const chatModelProviders = { ollama: loadOllamaChatModels, anthropic: loadAnthropicChatModels, gemini: loadGeminiChatModels, + deepinfra: loadDeepInfraChatModels, }; const embeddingModelProviders = { @@ -18,6 +20,7 @@ const embeddingModelProviders = { local: loadTransformersEmbeddingsModels, ollama: loadOllamaEmbeddingsModels, gemini: loadGeminiEmbeddingsModels, + deepinfra: loadDeepInfraEmbeddingsModels, }; export const getAvailableChatModelProviders = async () => { diff --git a/src/routes/config.ts b/src/routes/config.ts index 6ff80c6..41899c6 100644 --- a/src/routes/config.ts +++ b/src/routes/config.ts @@ -71,6 +71,7 @@ router.post('/', async (req, res) => { GROQ: config.groqApiKey, ANTHROPIC: config.anthropicApiKey, GEMINI: config.geminiApiKey, + DEEPINFRA: config.deepInfraApiKey, }, API_ENDPOINTS: { OLLAMA: config.ollamaApiUrl, diff --git a/ui/components/SettingsDialog.tsx b/ui/components/SettingsDialog.tsx index 163857b..85939e9 100644 --- a/ui/components/SettingsDialog.tsx +++ b/ui/components/SettingsDialog.tsx @@ -64,6 +64,7 @@ interface SettingsType { groqApiKey: string; anthropicApiKey: string; geminiApiKey: string; + deepinfraApiKey: string; ollamaApiUrl: string; } @@ -493,6 +494,22 @@ const SettingsDialog = ({ } /> +
+

+ DeepInfra API Key +

+ + setConfig({ + ...config, + deepinfraApiKey: e.target.value, + }) + } + /> +
)} {isLoading && (