feat: dynamic model discovery from vercel ai gateway (#1353)
This commit is contained in:
parent
2b0b42d144
commit
b1da86062e
74 changed files with 7426 additions and 2277 deletions
|
|
@ -21,7 +21,7 @@ import type { VisibilityType } from "@/components/visibility-selector";
|
|||
import { entitlementsByUserType } from "@/lib/ai/entitlements";
|
||||
import type { ChatModel } from "@/lib/ai/models";
|
||||
import { type RequestHints, systemPrompt } from "@/lib/ai/prompts";
|
||||
import { myProvider } from "@/lib/ai/providers";
|
||||
import { getLanguageModel } from "@/lib/ai/providers";
|
||||
import { createDocument } from "@/lib/ai/tools/create-document";
|
||||
import { getWeather } from "@/lib/ai/tools/get-weather";
|
||||
import { requestSuggestions } from "@/lib/ai/tools/request-suggestions";
|
||||
|
|
@ -179,21 +179,33 @@ export async function POST(request: Request) {
|
|||
|
||||
const stream = createUIMessageStream({
|
||||
execute: ({ writer: dataStream }) => {
|
||||
const isReasoningModel =
|
||||
selectedChatModel.includes("reasoning") ||
|
||||
selectedChatModel.includes("thinking");
|
||||
|
||||
const result = streamText({
|
||||
model: myProvider.languageModel(selectedChatModel),
|
||||
model: getLanguageModel(selectedChatModel),
|
||||
system: systemPrompt({ selectedChatModel, requestHints }),
|
||||
messages: convertToModelMessages(uiMessages),
|
||||
stopWhen: stepCountIs(5),
|
||||
experimental_activeTools:
|
||||
selectedChatModel === "chat-model-reasoning"
|
||||
? []
|
||||
: [
|
||||
"getWeather",
|
||||
"createDocument",
|
||||
"updateDocument",
|
||||
"requestSuggestions",
|
||||
],
|
||||
experimental_transform: smoothStream({ chunking: "word" }),
|
||||
experimental_activeTools: isReasoningModel
|
||||
? []
|
||||
: [
|
||||
"getWeather",
|
||||
"createDocument",
|
||||
"updateDocument",
|
||||
"requestSuggestions",
|
||||
],
|
||||
experimental_transform: isReasoningModel
|
||||
? undefined
|
||||
: smoothStream({ chunking: "word" }),
|
||||
providerOptions: isReasoningModel
|
||||
? {
|
||||
anthropic: {
|
||||
thinking: { type: "enabled", budgetTokens: 10_000 },
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
tools: {
|
||||
getWeather,
|
||||
createDocument: createDocument({ session, dataStream }),
|
||||
|
|
@ -210,8 +222,7 @@ export async function POST(request: Request) {
|
|||
onFinish: async ({ usage }) => {
|
||||
try {
|
||||
const providers = await getTokenlensCatalog();
|
||||
const modelId =
|
||||
myProvider.languageModel(selectedChatModel).modelId;
|
||||
const modelId = getLanguageModel(selectedChatModel).modelId;
|
||||
if (!modelId) {
|
||||
finalMergedUsage = usage;
|
||||
dataStream.write({
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export const postRequestBodySchema = z.object({
|
|||
role: z.enum(["user"]),
|
||||
parts: z.array(partSchema),
|
||||
}),
|
||||
selectedChatModel: z.enum(["chat-model", "chat-model-reasoning"]),
|
||||
selectedChatModel: z.string(),
|
||||
selectedVisibilityType: z.enum(["public", "private"]),
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue