jorel
Version:
A unified wrapper for working with LLMs from multiple providers, including streams, images, documents & automatic tool use.
53 lines (52 loc) • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolChoiceToMistral = exports.jsonResponseToMistral = void 0;
const zod_1 = require("zod");
const shared_1 = require("../../shared");
const jsonResponseToMistral = (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",
jsonSchema: {
name: "json_schema",
description: schemaDescription,
schemaDefinition: format instanceof zod_1.ZodObject ? (0, shared_1.zodSchemaToJsonSchema)(format, "openAi") : format,
strict: true,
},
};
}
throw new Error("Invalid format");
};
exports.jsonResponseToMistral = jsonResponseToMistral;
const toolChoiceToMistral = (toolChoice) => {
if (!toolChoice) {
return undefined;
}
if (toolChoice === "auto") {
return "auto";
}
else if (toolChoice === "required") {
return "any"; // Mistral uses "any" instead of "required"
}
else if (toolChoice === "none") {
return "none";
}
else {
// For specific function names, return ToolChoice object
return {
type: "function",
function: { name: toolChoice },
};
}
};
exports.toolChoiceToMistral = toolChoiceToMistral;