This commit is contained in:
Rushabh Agarwal 2025-04-30 13:16:24 +05:30
parent eda10b1212
commit cbfef91646
6 changed files with 4337 additions and 3180 deletions

View File

@ -1,9 +1,5 @@
import { env } from 'node:process';
export function getAPIKey(cloudflareEnv: Env) {
/**
* 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;
return env.OPENAI_API_KEY || cloudflareEnv.OPENAI_API_KEY; // Update to use OpenAI API key
}

View File

@ -1,9 +1,10 @@
import { createAnthropic } from '@ai-sdk/anthropic';
// Import the OpenAI SDK
import { createOpenAI } from '@ai-sdk/openai'; // Replace with the actual OpenAI SDK import
export function getAnthropicModel(apiKey: string) {
const anthropic = createAnthropic({
export function getOpenAIModel(apiKey: string) {
const openai = createOpenAI({
apiKey,
});
return anthropic('claude-3-5-sonnet-20240620');
}
return openai('gpt-4o'); // Adjust the model identifier as needed
}

View File

@ -1,6 +1,6 @@
import { streamText as _streamText, convertToCoreMessages } from 'ai';
import { getAPIKey } from '~/lib/.server/llm/api-key';
import { getAnthropicModel } from '~/lib/.server/llm/model';
import { getOpenAIModel } from '~/lib/.server/llm/model';
import { MAX_TOKENS } from './constants';
import { getSystemPrompt } from './prompts';
@ -23,7 +23,7 @@ export type StreamingOptions = Omit<Parameters<typeof _streamText>[0], 'model'>;
export function streamText(messages: Messages, env: Env, options?: StreamingOptions) {
return _streamText({
model: getAnthropicModel(getAPIKey(env)),
model: getOpenAIModel(getAPIKey(env)),
system: getSystemPrompt(),
maxTokens: MAX_TOKENS,
headers: {

View File

@ -24,6 +24,7 @@
},
"dependencies": {
"@ai-sdk/anthropic": "^0.0.39",
"@ai-sdk/openai": "^1.3.20",
"@codemirror/autocomplete": "^6.17.0",
"@codemirror/commands": "^6.6.0",
"@codemirror/lang-cpp": "^6.0.2",
@ -87,6 +88,7 @@
"is-ci": "^3.0.1",
"node-fetch": "^3.3.2",
"prettier": "^3.3.2",
"sass-embedded": "^1.87.0",
"typescript": "^5.5.2",
"unified": "^11.0.5",
"unocss": "^0.61.3",

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
interface Env {
ANTHROPIC_API_KEY: string;
OPENAI_API_KEY: string;
}