Files

1 line
7.8 KiB
JSON

{"repo": "bombap/taoprompt.com", "files": {"lib/models.ts": {"431de5c7f6b5641399e1290bffc63ae46cd862d4": {"t": 1785745566.065946, "n": 3663, "h": "74b3fb2769250843", "c": "import { createAnthropic } from \"@ai-sdk/anthropic\"\nimport { createGoogleGenerativeAI } from \"@ai-sdk/google\"\nimport { createMistral } from \"@ai-sdk/mistral\"\nimport { createOpenAI } from \"@ai-sdk/openai\"\nimport modelsData from \"./models.json\"\n\nexport type LLMModel = {\n id: string\n name: string\n provider: string\n providerId: string\n multiModal?: boolean\n}\n\nexport type LLMModelConfig = {\n model?: string\n apiKey?: string\n baseURL?: string\n temperature?: number\n topP?: number\n topK?: number\n frequencyPenalty?: number\n presencePenalty?: number\n maxTokens?: number\n}\n\n// Filter out Vertex models to prevent the error\nexport const models: LLMModel[] = modelsData.models.filter((model) => model.providerId !== \"vertex\")\n\nexport function getModelById(modelId: string): LLMModel | undefined {\n return models.find((model) => model.id === modelId)\n}\n\nexport function getDefaultModel(): LLMModel {\n // Default to Claude 3.5 Haiku or the first available model\n return models.find((model) => model.id === \"claude-3-5-haiku-latest\") || models[0]\n}\n\nexport function getModelClient(modelId: string, config: LLMModelConfig = {}) {\n const model = getModelById(modelId)\n\n if (!model) {\n throw new Error(`Model ${modelId} not found`)\n }\n\n const { providerId } = model\n const { apiKey, baseURL } = config\n\n try {\n const providerConfigs: Record<string, () => any> = {\n anthropic: () => createAnthropic({ apiKey, baseURL })(modelId),\n openai: () => createOpenAI({ apiKey, baseURL })(modelId),\n google: () => createGoogleGenerativeAI({ apiKey, baseURL })(modelId),\n mistral: () => createMistral({ apiKey, baseURL })(modelId),\n groq: () =>\n createOpenAI({\n apiKey: apiKey || process.env.GROQ_API_KEY,\n baseURL: baseURL || \"https://api.groq.com/openai/v1\",\n })(modelId),\n togetherai: () =>\n createOpenAI({\n apiKey: apiKey || process.env.TOGETHER_API_KEY,\n baseURL: baseURL || \"https://api.together.xyz/v1\",\n })(modelId),\n fireworks: () =>\n createOpenAI({\n apiKey: apiKey || process.env.FIREWORKS_API_KEY,\n baseURL: baseURL || \"https://api.fireworks.ai/inference/v1\",\n })(modelId),\n xai: () =>\n createOpenAI({\n apiKey: apiKey || process.env.XAI_API_KEY,\n baseURL: baseURL || \"https://api.x.ai/v1\",\n })(modelId),\n deepseek: () =>\n createOpenAI({\n apiKey: apiKey || process.env.DEEPSEEK_API_KEY,\n baseURL: baseURL || \"https://api.deepseek.com/v1\",\n })(modelId),\n }\n\n const createClient = providerConfigs[providerId]\n\n if (!createClient) {\n throw new Error(`Unsupported provider: ${providerId}`)\n }\n\n return createClient()\n } catch (error) {\n console.error(`Error creating model client for ${modelId}:`, error)\n // Fallback to OpenAI if available\n if (providerId !== \"openai\") {\n const fallbackModel = models.find((m) => m.providerId === \"openai\")\n if (fallbackModel) {\n console.warn(`Falling back to ${fallbackModel.id}`)\n return getModelClient(fallbackModel.id, config)\n }\n }\n throw error\n }\n}\n\nexport function getDefaultMode(modelId: string) {\n const model = getModelById(modelId)\n\n if (!model) {\n return \"auto\"\n }\n\n // monkey patch fireworks\n if (model.providerId === \"fireworks\") {\n return \"json\"\n }\n\n return \"auto\"\n}\n\nexport interface ModelSettings {\n temperature: number\n maxTokens: number\n topP: number\n frequencyPenalty: number\n}\n\nexport const defaultModelSettings: ModelSettings = {\n temperature: 0.7,\n maxTokens: 2048,\n topP: 0.95,\n frequencyPenalty: 0,\n}\n\n"}, "494cf1afb944eb55a48c1f342ad4f55684d7ca1c": {"t": 1785754279.9461548, "n": 3663, "h": "74b3fb2769250843", "c": "import { createAnthropic } from \"@ai-sdk/anthropic\"\nimport { createGoogleGenerativeAI } from \"@ai-sdk/google\"\nimport { createMistral } from \"@ai-sdk/mistral\"\nimport { createOpenAI } from \"@ai-sdk/openai\"\nimport modelsData from \"./models.json\"\n\nexport type LLMModel = {\n id: string\n name: string\n provider: string\n providerId: string\n multiModal?: boolean\n}\n\nexport type LLMModelConfig = {\n model?: string\n apiKey?: string\n baseURL?: string\n temperature?: number\n topP?: number\n topK?: number\n frequencyPenalty?: number\n presencePenalty?: number\n maxTokens?: number\n}\n\n// Filter out Vertex models to prevent the error\nexport const models: LLMModel[] = modelsData.models.filter((model) => model.providerId !== \"vertex\")\n\nexport function getModelById(modelId: string): LLMModel | undefined {\n return models.find((model) => model.id === modelId)\n}\n\nexport function getDefaultModel(): LLMModel {\n // Default to Claude 3.5 Haiku or the first available model\n return models.find((model) => model.id === \"claude-3-5-haiku-latest\") || models[0]\n}\n\nexport function getModelClient(modelId: string, config: LLMModelConfig = {}) {\n const model = getModelById(modelId)\n\n if (!model) {\n throw new Error(`Model ${modelId} not found`)\n }\n\n const { providerId } = model\n const { apiKey, baseURL } = config\n\n try {\n const providerConfigs: Record<string, () => any> = {\n anthropic: () => createAnthropic({ apiKey, baseURL })(modelId),\n openai: () => createOpenAI({ apiKey, baseURL })(modelId),\n google: () => createGoogleGenerativeAI({ apiKey, baseURL })(modelId),\n mistral: () => createMistral({ apiKey, baseURL })(modelId),\n groq: () =>\n createOpenAI({\n apiKey: apiKey || process.env.GROQ_API_KEY,\n baseURL: baseURL || \"https://api.groq.com/openai/v1\",\n })(modelId),\n togetherai: () =>\n createOpenAI({\n apiKey: apiKey || process.env.TOGETHER_API_KEY,\n baseURL: baseURL || \"https://api.together.xyz/v1\",\n })(modelId),\n fireworks: () =>\n createOpenAI({\n apiKey: apiKey || process.env.FIREWORKS_API_KEY,\n baseURL: baseURL || \"https://api.fireworks.ai/inference/v1\",\n })(modelId),\n xai: () =>\n createOpenAI({\n apiKey: apiKey || process.env.XAI_API_KEY,\n baseURL: baseURL || \"https://api.x.ai/v1\",\n })(modelId),\n deepseek: () =>\n createOpenAI({\n apiKey: apiKey || process.env.DEEPSEEK_API_KEY,\n baseURL: baseURL || \"https://api.deepseek.com/v1\",\n })(modelId),\n }\n\n const createClient = providerConfigs[providerId]\n\n if (!createClient) {\n throw new Error(`Unsupported provider: ${providerId}`)\n }\n\n return createClient()\n } catch (error) {\n console.error(`Error creating model client for ${modelId}:`, error)\n // Fallback to OpenAI if available\n if (providerId !== \"openai\") {\n const fallbackModel = models.find((m) => m.providerId === \"openai\")\n if (fallbackModel) {\n console.warn(`Falling back to ${fallbackModel.id}`)\n return getModelClient(fallbackModel.id, config)\n }\n }\n throw error\n }\n}\n\nexport function getDefaultMode(modelId: string) {\n const model = getModelById(modelId)\n\n if (!model) {\n return \"auto\"\n }\n\n // monkey patch fireworks\n if (model.providerId === \"fireworks\") {\n return \"json\"\n }\n\n return \"auto\"\n}\n\nexport interface ModelSettings {\n temperature: number\n maxTokens: number\n topP: number\n frequencyPenalty: number\n}\n\nexport const defaultModelSettings: ModelSettings = {\n temperature: 0.7,\n maxTokens: 2048,\n topP: 0.95,\n frequencyPenalty: 0,\n}\n\n"}}}}