UNPKG

langcode

Version:

A Plugin-Based Framework for Managing and Using LangChain

39 lines (38 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const types_1 = require("../../types"); const output_parsers_1 = require("langchain/output_parsers"); const zod_1 = require("zod"); class StructuredOutputParserPlugin { constructor() { this.name = "structuredOutputParser"; this.description = "Parses structured JSON-like LLM outputs using a Zod schema."; this.type = types_1.PluginType.Parser; this.RunConfigExample = { text: "" }; this.InitConfigExample = { schema: zod_1.z.object({ name: zod_1.z.string(), age: zod_1.z.number(), }), }; } expose() { return { name: this.name, description: this.description, type: this.type, InitConfigExample: this.InitConfigExample, RunConfigExample: this.RunConfigExample, parser: this.parser }; } async init(config) { this.parser = output_parsers_1.StructuredOutputParser.fromZodSchema(config.schema); } async run(args) { return await this.parser.parse(args.text); } } exports.default = StructuredOutputParserPlugin;