Documentation
    Preparing search index...

    Function toLangChainTools

    • Convert typia controllers to LangChain tools.

      Converts TypeScript class methods via typia.llm.controller<Class>() or OpenAPI operations via HttpLlm.controller() to LangChain tools.

      Every tool call is validated by typia. If LLM provides invalid arguments, returns validation error formatted by LlmJson.stringify so that LLM can correct them automatically.

      Parameters

      • props: { controllers: (IHttpLlmController | ILlmController<any>)[]; prefix?: boolean }

        Conversion properties

        • controllers: (IHttpLlmController | ILlmController<any>)[]

          List of controllers to convert to LangChain tools.

          • ILlmController: from typia.llm.controller<Class>(), converts all methods of the class to tools
          • IHttpLlmController: from HttpLlm.controller(), converts all operations from OpenAPI document to tools
        • Optionalprefix?: boolean

          Whether to add controller name as prefix to tool names.

          If true, tool names become {controllerName}_{methodName}. If false, tool names are just {methodName}.

          false
          

      Returns DynamicStructuredTool<ToolInputSchemaBase, any, any, any, string>[]

      Array of LangChain DynamicStructuredTool

        import { initChatModel } from "langchain/chat_models/universal";
      import typia from "typia";
      import { toLangChainTools } from "@typia/langchain";

      class Calculator {
      add(input: { a: number; b: number }): { value: number } {
      return { value: input.a + input.b };
      }
      }

      const tools = toLangChainTools({
      controllers: [
      typia.llm.controller<Calculator>("calculator", new Calculator()),
      ],
      });

      const llm = await initChatModel();
      const modelWithTools = llm.bindTools(tools);
      const result = await modelWithTools.invoke("What is 10 + 5?");