chatbot-template/docs/02-update-models.md

56 lines
2.2 KiB
Markdown
Raw Normal View History

2025-02-05 14:58:38 +03:00
# Update Models
2025-03-14 19:00:22 -07:00
The chatbot template ships with [xAI](https://sdk.vercel.ai/providers/ai-sdk-providers/xai) as the default model provider. Since the template is powered by the [AI SDK](https://sdk.vercel.ai), which supports [multiple providers](https://sdk.vercel.ai/providers/ai-sdk-providers) out of the box, you can easily switch to another provider of your choice.
2025-02-05 14:58:38 +03:00
To update the models, you will need to update the custom provider called `myProvider` at `/lib/ai/models.ts` shown below.
```ts
import { customProvider } from "ai";
2025-03-14 19:00:22 -07:00
import { xai } from "@ai-sdk/xai";
2025-03-20 14:10:45 -07:00
import { groq } from "@ai-sdk/groq";
import { fal } from "@ai-sdk/fal";
2025-02-05 14:58:38 +03:00
export const myProvider = customProvider({
languageModels: {
2025-03-17 16:58:22 -07:00
"chat-model": xai("grok-2-1212"),
2025-02-05 14:58:38 +03:00
"chat-model-reasoning": wrapLanguageModel({
2025-03-20 14:10:45 -07:00
model: groq("deepseek-r1-distill-llama-70b"),
2025-02-05 14:58:38 +03:00
middleware: extractReasoningMiddleware({ tagName: "think" }),
}),
2025-03-14 19:00:22 -07:00
"title-model": xai("grok-2-1212"),
"artifact-model": xai("grok-2-1212"),
2025-02-05 14:58:38 +03:00
},
imageModels: {
2025-03-20 14:10:45 -07:00
"small-model": fal.image("fal-ai/fast-sdxl"),
2025-02-05 14:58:38 +03:00
},
});
```
2025-03-14 19:00:22 -07:00
You can replace the models with any other provider of your choice. You will need to install the provider library and switch the models accordingly.
2025-02-05 14:58:38 +03:00
2025-03-17 16:58:22 -07:00
For example, if you want to use Anthropic's `claude-3-5-sonnet` model for `chat-model`, you can replace the `xai` model with the `anthropic` model as shown below.
2025-02-05 14:58:38 +03:00
```ts
import { customProvider } from "ai";
2025-03-20 14:10:45 -07:00
import { fal } from "@ai-sdk/fal";
import { groq } from "@ai-sdk/groq";
2025-02-05 14:58:38 +03:00
import { anthropic } from "@ai-sdk/anthropic";
export const myProvider = customProvider({
languageModels: {
2025-03-17 16:58:22 -07:00
"chat-model": anthropic("claude-3-5-sonnet"), // Replace xai with anthropic
2025-02-05 14:58:38 +03:00
"chat-model-reasoning": wrapLanguageModel({
2025-03-20 14:10:45 -07:00
model: groq("deepseek-r1-distill-llama-70b"),
2025-02-05 14:58:38 +03:00
middleware: extractReasoningMiddleware({ tagName: "think" }),
}),
2025-03-20 14:10:45 -07:00
"title-model": anthropic("claude-3-5-haiku"),
"artifact-model": anthropic("claude-3-5-haiku"),
2025-02-05 14:58:38 +03:00
},
imageModels: {
2025-03-20 14:10:45 -07:00
"small-model": fal.image("fal-ai/fast-sdxl"),
2025-02-05 14:58:38 +03:00
},
});
```
You can find the provider library and model names in the [provider](https://sdk.vercel.ai/providers/ai-sdk-providers)'s documentation. Once you have updated the models, you should be able to use the new models in your chatbot.