import { z } from "zod"; import { JsonSchema7Type } from "zod-to-json-schema"; import { Validator } from "@langchain/core/utils/json_schema"; import { ChatOpenAI } from "@langchain/openai"; import { BasePromptTemplate } from "@langchain/core/prompts"; import { BaseLLMOutputParser } from "@langchain/core/output_parsers"; import { ChatGeneration } from "@langchain/core/outputs"; import type { BaseChatModel } from "@langchain/core/language_models/chat_models"; import type { BaseFunctionCallOptions } from "@langchain/core/language_models/base"; import { LLMChain, type LLMChainInput } from "../llm_chain.js"; import { OutputFunctionsParser } from "../../output_parsers/openai_functions.js"; /** * Type representing the input for creating a structured output chain. It * extends the LLMChainInput type and includes an additional * 'outputSchema' field representing the JSON schema for the expected * output. */ export type StructuredOutputChainInput = Omit & { outputSchema?: JsonSchema7Type; prompt: BasePromptTemplate; llm?: BaseChatModel; zodSchema?: T; }; export type FunctionCallStructuredOutputParserFields = { jsonSchema?: JsonSchema7Type; zodSchema?: T; }; /** * Class that extends the BaseLLMOutputParser class. It provides * functionality for parsing the structured output based on a JSON schema. */ export declare class FunctionCallStructuredOutputParser extends BaseLLMOutputParser> { lc_namespace: string[]; protected functionOutputParser: OutputFunctionsParser; protected jsonSchemaValidator?: Validator; protected zodSchema?: T; constructor(fieldsOrSchema: JsonSchema7Type); constructor(fieldsOrSchema: FunctionCallStructuredOutputParserFields); /** * Method to parse the result of chat generations. It first parses the * result using the functionOutputParser, then parses the result against a * zod schema if the zod schema is available which allows the result to undergo * Zod preprocessing, then it parses that result against the JSON schema. * If the result is valid, it returns the parsed result. Otherwise, it throws * an OutputParserException. * @param generations Array of ChatGeneration instances to be parsed. * @returns The parsed result if it is valid according to the JSON schema. */ parseResult(generations: ChatGeneration[]): Promise; } /** * @deprecated Use {@link https://api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead * Create a chain that returns output matching a JSON Schema. * @param input Object that includes all LLMChainInput fields except "outputParser" * as well as an additional required "outputSchema" JSON Schema object. * @returns OpenAPIChain */ export declare function createStructuredOutputChain(input: StructuredOutputChainInput): LLMChain | ChatOpenAI>; /** @deprecated Use {@link https://api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */ export declare function createStructuredOutputChainFromZod(zodSchema: T, input: Omit, "outputSchema">): LLMChain | ChatOpenAI>;