forked from stackblitz/bolt.new
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability to use practically any LLM you can dream of within …
…Bolt.new
- Loading branch information
Showing
14 changed files
with
641 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Rename this file to .env.local once you have filled in the below environment variables! | ||
|
||
# Get your GROQ API Key here - | ||
# https://console.groq.com/keys | ||
# You only need this environment variable set if you want to use Groq models | ||
GROQ_API_KEY= | ||
|
||
# Get your Open AI API Key by following these instructions - | ||
# https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key | ||
# You only need this environment variable set if you want to use GPT models | ||
OPENAI_API_KEY= | ||
|
||
# Get your Anthropic API Key in your account settings - | ||
# https://console.anthropic.com/settings/keys | ||
# You only need this environment variable set if you want to use Claude models | ||
ANTHROPIC_API_KEY= | ||
|
||
# Include this environment variable if you want more logging for debugging locally | ||
VITE_LOG_LEVEL=debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,8 @@ dist-ssr | |
|
||
/.cache | ||
/build | ||
.env* | ||
.env.local | ||
.env | ||
*.vars | ||
.wrangler | ||
_worker.bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
// @ts-nocheck | ||
// Preventing TS checks with files presented in the video for a better presentation. | ||
import { env } from 'node:process'; | ||
|
||
export function getAPIKey(cloudflareEnv: Env) { | ||
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`. | ||
*/ | ||
return env.ANTHROPIC_API_KEY || cloudflareEnv.ANTHROPIC_API_KEY; | ||
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 'Groq': | ||
return env.GROQ_API_KEY || cloudflareEnv.GROQ_API_KEY; | ||
default: | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,50 @@ | ||
// @ts-nocheck | ||
// Preventing TS checks with files presented in the video for a better presentation. | ||
import { getAPIKey } from '~/lib/.server/llm/api-key'; | ||
import { createAnthropic } from '@ai-sdk/anthropic'; | ||
import { createOpenAI } from '@ai-sdk/openai'; | ||
import { ollama } from 'ollama-ai-provider'; | ||
|
||
export function getAnthropicModel(apiKey: string) { | ||
export function getAnthropicModel(apiKey: string, model: string) { | ||
const anthropic = createAnthropic({ | ||
apiKey, | ||
}); | ||
|
||
return anthropic('claude-3-5-sonnet-20240620'); | ||
return anthropic(model); | ||
} | ||
|
||
export function getOpenAIModel(apiKey: string, model: string) { | ||
const openai = createOpenAI({ | ||
apiKey, | ||
}); | ||
|
||
return openai(model); | ||
} | ||
|
||
export function getGroqModel(apiKey: string, model: string) { | ||
const openai = createOpenAI({ | ||
baseURL: 'https://api.groq.com/openai/v1', | ||
apiKey, | ||
}); | ||
|
||
return openai(model); | ||
} | ||
|
||
export function getOllamaModel(model: string) { | ||
return ollama(model); | ||
} | ||
|
||
export function getModel(provider: string, model: string, env: Env) { | ||
const apiKey = getAPIKey(env, provider); | ||
|
||
switch (provider) { | ||
case 'Anthropic': | ||
return getAnthropicModel(apiKey, model); | ||
case 'OpenAI': | ||
return getOpenAIModel(apiKey, model); | ||
case 'Groq': | ||
return getGroqModel(apiKey, model); | ||
default: | ||
return getOllamaModel(model); | ||
} | ||
} |
Oops, something went wrong.