2024-10-13 18:53:43 +00:00
|
|
|
// @ts-nocheck
|
|
|
|
// Preventing TS checks with files presented in the video for a better presentation.
|
|
|
|
import { getAPIKey } from '~/lib/.server/llm/api-key';
|
2024-07-10 16:44:39 +00:00
|
|
|
import { createAnthropic } from '@ai-sdk/anthropic';
|
2024-10-13 18:53:43 +00:00
|
|
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
|
|
import { ollama } from 'ollama-ai-provider';
|
2024-07-10 16:44:39 +00:00
|
|
|
|
2024-10-13 18:53:43 +00:00
|
|
|
export function getAnthropicModel(apiKey: string, model: string) {
|
2024-07-10 16:44:39 +00:00
|
|
|
const anthropic = createAnthropic({
|
|
|
|
apiKey,
|
|
|
|
});
|
|
|
|
|
2024-10-13 18:53:43 +00:00
|
|
|
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);
|
|
|
|
}
|
2024-07-10 16:44:39 +00:00
|
|
|
}
|