143ba32b11
Route /force through a named Ollama tool choice and scope the Ollama request tools to that selected name so local models cannot pick a different tool.\n\nFixes #1236
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import type { Api, Model, ToolChoice } from "@oh-my-pi/pi-ai";
|
|
|
|
/**
|
|
* Build a provider-aware tool choice that targets one specific tool when supported.
|
|
* Providers that only expose required/any forcing may still honor named choices by
|
|
* narrowing their request tool list before transport.
|
|
*/
|
|
export function buildNamedToolChoice(toolName: string, model?: Model<Api>): ToolChoice | undefined {
|
|
if (!model) return undefined;
|
|
|
|
if (model.api === "anthropic-messages" || model.api === "bedrock-converse-stream") {
|
|
return { type: "tool", name: toolName };
|
|
}
|
|
|
|
if (
|
|
model.api === "openai-codex-responses" ||
|
|
model.api === "openai-responses" ||
|
|
model.api === "openai-completions" ||
|
|
model.api === "azure-openai-responses"
|
|
) {
|
|
return { type: "function", name: toolName };
|
|
}
|
|
|
|
if (model.api === "ollama-chat") {
|
|
return { type: "function", name: toolName };
|
|
}
|
|
|
|
if (model.api === "google-generative-ai" || model.api === "google-gemini-cli" || model.api === "google-vertex") {
|
|
return "required";
|
|
}
|
|
|
|
return undefined;
|
|
}
|