UNPKG

jorel

Version:

A unified wrapper for working with LLMs from multiple providers, including streams, images, documents & automatic tool use.

65 lines (64 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reasoningToOpenRouter = exports.toolChoiceToOpenRouter = exports.jsonResponseToOpenRouter = void 0; const zod_1 = require("zod"); const shared_1 = require("../../shared"); /** * Convert JorEl JSON response config to OpenRouter format */ const jsonResponseToOpenRouter = (format, schemaDescription) => { if (!format) { return undefined; } if (format === true) { return { type: "json_object" }; } // JSON schema provided return { type: "json_schema", jsonSchema: { name: "response", description: schemaDescription || "Response schema", schema: format instanceof zod_1.ZodObject ? (0, shared_1.zodSchemaToJsonSchema)(format, "openAi") : format, }, }; }; exports.jsonResponseToOpenRouter = jsonResponseToOpenRouter; /** * Convert JorEl tool choice to OpenRouter format */ const toolChoiceToOpenRouter = (toolChoice) => { if (!toolChoice) { return undefined; } if (toolChoice === "none") { return "none"; } if (toolChoice === "auto") { return "auto"; } if (toolChoice === "required") { return "required"; } // Specific tool name return { type: "function", function: { name: toolChoice, }, }; }; exports.toolChoiceToOpenRouter = toolChoiceToOpenRouter; /** * Convert reasoning effort and verbosity to OpenRouter format */ const reasoningToOpenRouter = (reasoningEffort, reasoningSummaryVerbosity) => { if (!reasoningEffort && !reasoningSummaryVerbosity) { return undefined; } return { effort: reasoningEffort, summary: reasoningSummaryVerbosity || "auto", }; }; exports.reasoningToOpenRouter = reasoningToOpenRouter;