@naktibalda/jorel
Version:
The easiest way to use LLMs, including streams, images, documents, tools and various agent scenarios.
37 lines (36 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolsToOllama = exports.jsonResponseToOllama = void 0;
const zod_1 = require("zod");
const shared_1 = require("../../shared");
const jsonResponseToOllama = (format) => {
if (!format) {
return undefined;
}
else if (typeof format === "boolean") {
return "json";
}
else if (typeof format === "object") {
return format instanceof zod_1.ZodObject ? (0, shared_1.zodSchemaToJsonSchema)(format) : format;
}
throw new Error("Invalid format");
};
exports.jsonResponseToOllama = jsonResponseToOllama;
const toolsToOllama = (tools) => {
if (!tools?.asLlmFunctions?.length) {
return undefined;
}
return tools.asLlmFunctions.map((f) => ({
type: "function",
function: {
name: f.function.name,
description: f.function.description ?? "",
parameters: {
type: f.function.parameters?.type ?? "object",
properties: f.function.parameters?.properties ?? {},
required: f.function.parameters?.required ?? [],
},
},
}));
};
exports.toolsToOllama = toolsToOllama;