wip
This commit is contained in:
parent
61ba844234
commit
bacf705ee5
2 changed files with 37 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ import { unique } from "remeda"
|
||||||
import type { JSONSchema } from "zod/v4/core"
|
import type { JSONSchema } from "zod/v4/core"
|
||||||
import type { Provider } from "./provider"
|
import type { Provider } from "./provider"
|
||||||
import type { ModelsDev } from "./models"
|
import type { ModelsDev } from "./models"
|
||||||
|
import type { MessageV2 } from "@/session/message-v2"
|
||||||
|
|
||||||
type Modality = NonNullable<ModelsDev.Model["modalities"]>["input"][number]
|
type Modality = NonNullable<ModelsDev.Model["modalities"]>["input"][number]
|
||||||
|
|
||||||
|
|
@ -210,6 +211,38 @@ export namespace ProviderTransform {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function thinking(model: Provider.Model, thinking: MessageV2.Thinking) {
|
||||||
|
if (!model.capabilities.reasoning) return undefined
|
||||||
|
|
||||||
|
switch (model.api.npm) {
|
||||||
|
case "@openrouter/ai-sdk-provider":
|
||||||
|
return {
|
||||||
|
reasoning: { effort: thinking.effort },
|
||||||
|
}
|
||||||
|
case "@ai-sdk/openai-compatible":
|
||||||
|
const result: Record<string, any> = {
|
||||||
|
reasoningEffort: thinking.effort,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model.providerID === "baseten") {
|
||||||
|
result["chat_template_args"] = { enable_thinking: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
case "@ai-sdk/openai":
|
||||||
|
return {
|
||||||
|
reasoningEffort: thinking.effort,
|
||||||
|
reasoningSummary: "auto",
|
||||||
|
include: ["reasoning.encrypted_content"],
|
||||||
|
}
|
||||||
|
|
||||||
|
case "@ai-sdk/anthropic":
|
||||||
|
// TODO: map to thinking budgets
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function options(
|
export function options(
|
||||||
model: Provider.Model,
|
model: Provider.Model,
|
||||||
sessionID: string,
|
sessionID: string,
|
||||||
|
|
|
||||||
|
|
@ -286,6 +286,9 @@ export namespace MessageV2 {
|
||||||
sessionID: z.string(),
|
sessionID: z.string(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const Thinking = z.object({ effort: z.enum(["low", "medium", "high"]) })
|
||||||
|
export type Thinking = z.infer<typeof Thinking>
|
||||||
|
|
||||||
export const User = Base.extend({
|
export const User = Base.extend({
|
||||||
role: z.literal("user"),
|
role: z.literal("user"),
|
||||||
time: z.object({
|
time: z.object({
|
||||||
|
|
@ -305,6 +308,7 @@ export namespace MessageV2 {
|
||||||
}),
|
}),
|
||||||
system: z.string().optional(),
|
system: z.string().optional(),
|
||||||
tools: z.record(z.string(), z.boolean()).optional(),
|
tools: z.record(z.string(), z.boolean()).optional(),
|
||||||
|
thinking: Thinking.optional(),
|
||||||
}).meta({
|
}).meta({
|
||||||
ref: "UserMessage",
|
ref: "UserMessage",
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue