UNPKG

@naktibalda/jorel

Version:

The easiest way to use LLMs, including streams, images, documents, tools and various agent scenarios.

49 lines (48 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toolChoiceToOpenAi = exports.jsonResponseToOpenAi = void 0; const zod_1 = require("zod"); const shared_1 = require("../../shared"); const jsonResponseToOpenAi = (format, schemaDescription) => { if (!format) { return { type: "text", }; } else if (typeof format === "boolean") { return { type: "json_object", }; } else if (typeof format === "object") { return { type: "json_schema", json_schema: { name: "json_schema", description: schemaDescription, schema: format instanceof zod_1.ZodObject ? (0, shared_1.zodSchemaToJsonSchema)(format, 'openAi') : format, strict: true, }, }; } throw new Error("Invalid format"); }; exports.jsonResponseToOpenAi = jsonResponseToOpenAi; const toolChoiceToOpenAi = (toolChoice) => { if (!toolChoice) { return undefined; } if (toolChoice === "auto") { return "auto"; } else if (toolChoice === "required") { return "required"; } else if (toolChoice === "none") { return "none"; } else { return { type: "function", function: { name: toolChoice } }; } }; exports.toolChoiceToOpenAi = toolChoiceToOpenAi;