diff --git a/.env.example b/.env.example index 22bdcc18..4a781e0a 100644 --- a/.env.example +++ b/.env.example @@ -18,7 +18,12 @@ ANTHROPIC_API_KEY= # Get your OpenRouter API Key in your account settings - # https://openrouter.ai/settings/keys # You only need this environment variable set if you want to use OpenRouter models -OPEN_ROUTER_API_KEY= +OPEN_ROUTER_API_KEY=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 + +# Get your Google Generative AI API Key by following these instructions - +# https://console.cloud.google.com/apis/credentials +# You only need this environment variable set if you want to use Google Generative AI models +GOOGLE_GENERATIVE_AI_API_KEY= # Include this environment variable if you want more logging for debugging locally -VITE_LOG_LEVEL=debug \ No newline at end of file +VITE_LOG_LEVEL=debug diff --git a/app/lib/.server/llm/api-key.ts b/app/lib/.server/llm/api-key.ts index 1f656cfa..b1a47f42 100644 --- a/app/lib/.server/llm/api-key.ts +++ b/app/lib/.server/llm/api-key.ts @@ -7,11 +7,14 @@ export function getAPIKey(cloudflareEnv: Env, provider: string) { * The `cloudflareEnv` is only used when deployed or when previewing locally. * In development the environment variables are available through `env`. */ + switch (provider) { case 'Anthropic': return env.ANTHROPIC_API_KEY || cloudflareEnv.ANTHROPIC_API_KEY; case 'OpenAI': return env.OPENAI_API_KEY || cloudflareEnv.OPENAI_API_KEY; + case 'Google': + return env.GOOGLE_GENERATIVE_AI_API_KEY || cloudflareEnv.GOOGLE_GENERATIVE_AI_API_KEY; case 'Groq': return env.GROQ_API_KEY || cloudflareEnv.GROQ_API_KEY; case 'OpenRouter': diff --git a/app/lib/.server/llm/model.ts b/app/lib/.server/llm/model.ts index 9b56a6dd..68983756 100644 --- a/app/lib/.server/llm/model.ts +++ b/app/lib/.server/llm/model.ts @@ -3,6 +3,7 @@ import { getAPIKey } from '~/lib/.server/llm/api-key'; import { createAnthropic } from '@ai-sdk/anthropic'; import { createOpenAI } from '@ai-sdk/openai'; +import { createGoogleGenerativeAI } from '@ai-sdk/google'; import { ollama } from 'ollama-ai-provider'; import { createOpenRouter } from "@openrouter/ai-sdk-provider"; @@ -22,6 +23,14 @@ export function getOpenAIModel(apiKey: string, model: string) { return openai(model); } +export function getGoogleModel(apiKey: string, model: string) { + const google = createGoogleGenerativeAI( + apiKey, + ); + + return google(model); +} + export function getGroqModel(apiKey: string, model: string) { const openai = createOpenAI({ baseURL: 'https://api.groq.com/openai/v1', @@ -45,7 +54,8 @@ export function getOpenRouterModel(apiKey: string, model: string) { export function getModel(provider: string, model: string, env: Env) { const apiKey = getAPIKey(env, provider); - + + switch (provider) { case 'Anthropic': return getAnthropicModel(apiKey, model); @@ -55,6 +65,8 @@ export function getModel(provider: string, model: string, env: Env) { return getGroqModel(apiKey, model); case 'OpenRouter': return getOpenRouterModel(apiKey, model); + case 'Google': + return getGoogleModel(apiKey, model) default: return getOllamaModel(model); } diff --git a/app/utils/constants.ts b/app/utils/constants.ts index 4ff6a46f..8f49885d 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -6,7 +6,13 @@ export const DEFAULT_MODEL = "claude-3-5-sonnet-20240620"; export const DEFAULT_PROVIDER = "Anthropic"; export const MODEL_LIST = [ { name: 'claude-3-5-sonnet-20240620', label: 'Claude 3.5 Sonnet', provider: 'Anthropic' }, + { name: 'gemini-1.5-flash-latest', label: 'Gemini 1.5 Flash', provider: 'Google' }, + { name: 'gemini-1.5-pro-latest', label: 'Gemini 1.5 Pro', provider: 'Google'}, { name: 'gpt-4o', label: 'GPT-4o', provider: 'OpenAI' }, + { name: 'gpt-4o-mini', label: 'GPT-4o Mini', provider: 'OpenAI' }, + { name: 'gpt-4-turbo', label: 'GPT-4 Turbo', provider: 'OpenAI' }, + { name: 'gpt-4', label: 'GPT-4', provider: 'OpenAI' }, + { name: 'gpt-3.5-turbo', label: 'GPT-3.5 Turbo', provider: 'OpenAI' }, { name: 'qwen2.5-coder:7b', label: 'Qwen 2.5 Coder 7b', provider: 'Ollama' }, { name: 'qwen2.5-coder:1.5b', label: 'Qwen 2.5 Coder 1.5b', provider: 'Ollama' }, { name: 'deepseek-coder-v2:236b', label: 'DeepSeek-Coder-V2 236b', provider: 'Ollama' }, @@ -31,8 +37,4 @@ export const MODEL_LIST = [ { name: 'claude-3-opus-20240229', label: 'Claude 3 Opus', provider: 'Anthropic' }, { name: 'claude-3-sonnet-20240229', label: 'Claude 3 Sonnet', provider: 'Anthropic' }, { name: 'claude-3-haiku-20240307', label: 'Claude 3 Haiku', provider: 'Anthropic' }, - { name: 'gpt-4o-mini', label: 'GPT-4o Mini', provider: 'OpenAI' }, - { name: 'gpt-4-turbo', label: 'GPT-4 Turbo', provider: 'OpenAI' }, - { name: 'gpt-4', label: 'GPT-4', provider: 'OpenAI' }, - { name: 'gpt-3.5-turbo', label: 'GPT-3.5 Turbo', provider: 'OpenAI' }, -]; \ No newline at end of file +];