UNPKG

@copilotkit/runtime

Version:

<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />

63 lines (61 loc) 1.98 kB
require("reflect-metadata"); //#region src/service-adapters/langchain/langserve.ts var RemoteChain = class { constructor(options) { this.name = options.name; this.description = options.description; this.chainUrl = options.chainUrl; this.parameters = options.parameters; this.parameterType = options.parameterType || "multi"; } async toAction() { if (!this.parameters) await this.inferLangServeParameters(); return { name: this.name, description: this.description, parameters: this.parameters, handler: async (args) => { const { RemoteRunnable } = require("langchain/runnables/remote"); const runnable = new RemoteRunnable({ url: this.chainUrl }); let input; if (this.parameterType === "single") input = args[Object.keys(args)[0]]; else input = args; return await runnable.invoke(input); } }; } async inferLangServeParameters() { const supportedTypes = [ "string", "number", "boolean" ]; let schemaUrl = this.chainUrl.replace(/\/+$/, "") + "/input_schema"; let schema = await fetch(schemaUrl).then((res) => res.json()).catch(() => { throw new Error("Failed to fetch langserve schema at " + schemaUrl); }); if (supportedTypes.includes(schema.type)) { this.parameterType = "single"; this.parameters = [{ name: "input", type: schema.type, description: "The input to the chain" }]; } else if (schema.type === "object") { this.parameterType = "multi"; this.parameters = Object.keys(schema.properties).map((key) => { let property = schema.properties[key]; if (!supportedTypes.includes(property.type)) throw new Error("Unsupported schema type"); return { name: key, type: property.type, description: property.description || "", required: schema.required?.includes(key) || false }; }); } else throw new Error("Unsupported schema type"); } }; //#endregion exports.RemoteChain = RemoteChain; //# sourceMappingURL=langserve.cjs.map