UNPKG

@langchain/openai

Version:
1 lines 6.71 kB
{"version":3,"file":"tools.d.cts","names":["OpenAI","OpenAIClient","ToolDefinition","BindToolsInput","DynamicTool","StructuredToolInterface","ToolCall","_convertToOpenAITool","ChatCompletionTool","OpenAIFunction","Chat","ChatCompletionCreateParams","Function","FunctionDef","ObjectProp","Omit","Prop","AnyOfProp","formatFunctionDefinitions","formatToOpenAIAssistantTool","OpenAIToolChoice","ChatCompletionToolChoiceOption","ResponsesToolChoice","Responses","ResponseCreateParams","NonNullable","ChatOpenAIToolType","ResponsesTool","formatToOpenAIToolChoice","isBuiltInTool","LangchainToolWithProviderDefinition","hasProviderToolDefinition","isBuiltInToolChoice","CustomToolCall","LangchainCustomTool","CustomTool","isCustomTool","isOpenAICustomTool","ChatCompletionCustomTool","parseCustomToolCall","Record","ComputerToolCall","parseComputerCall","isComputerToolCall","isCustomToolCall","convertCompletionsCustomTool","convertResponsesCustomTool"],"sources":["../../src/utils/tools.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport { ToolDefinition } from \"@langchain/core/language_models/base\";\nimport { BindToolsInput } from \"@langchain/core/language_models/chat_models\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport { ToolCall } from \"@langchain/core/messages/tool\";\n/**\n * Formats a tool in either OpenAI format, or LangChain structured tool format\n * into an OpenAI tool format. If the tool is already in OpenAI format, return without\n * any changes. If it is in LangChain structured tool format, convert it to OpenAI tool format\n * using OpenAI's `zodFunction` util, falling back to `convertToOpenAIFunction` if the parameters\n * returned from the `zodFunction` util are not defined.\n *\n * @param {BindToolsInput} tool The tool to convert to an OpenAI tool.\n * @param {Object} [fields] Additional fields to add to the OpenAI tool.\n * @returns {ToolDefinition} The inputted tool in OpenAI tool format.\n */\nexport declare function _convertToOpenAITool(tool: BindToolsInput, fields?: {\n /**\n * If `true`, model output is guaranteed to exactly match the JSON Schema\n * provided in the function definition.\n */\n strict?: boolean;\n}): OpenAIClient.ChatCompletionTool;\ntype OpenAIFunction = OpenAIClient.Chat.ChatCompletionCreateParams.Function;\nexport interface FunctionDef extends Omit<OpenAIFunction, \"parameters\"> {\n name: string;\n description?: string;\n parameters: ObjectProp;\n}\ninterface ObjectProp {\n type: \"object\";\n properties?: {\n [key: string]: Prop;\n };\n required?: string[];\n}\ninterface AnyOfProp {\n anyOf: Prop[];\n}\ntype Prop = {\n description?: string;\n} & (AnyOfProp | ObjectProp | {\n type: \"string\";\n enum?: string[];\n} | {\n type: \"number\" | \"integer\";\n minimum?: number;\n maximum?: number;\n enum?: number[];\n} | {\n type: \"boolean\";\n} | {\n type: \"null\";\n} | {\n type: \"array\";\n items?: Prop;\n});\nexport declare function formatFunctionDefinitions(functions: FunctionDef[]): string;\nexport declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): ToolDefinition;\nexport type OpenAIToolChoice = OpenAIClient.ChatCompletionToolChoiceOption | \"any\" | string;\nexport type ResponsesToolChoice = NonNullable<OpenAIClient.Responses.ResponseCreateParams[\"tool_choice\"]>;\nexport type ChatOpenAIToolType = BindToolsInput | OpenAIClient.Chat.ChatCompletionTool | ResponsesTool;\nexport type ResponsesTool = NonNullable<OpenAIClient.Responses.ResponseCreateParams[\"tools\"]>[number];\nexport declare function formatToOpenAIToolChoice(toolChoice?: OpenAIToolChoice): OpenAIClient.ChatCompletionToolChoiceOption | undefined;\nexport declare function isBuiltInTool(tool: ChatOpenAIToolType): tool is ResponsesTool;\n/**\n * Type for LangChain tools that have a provider-specific tool definition\n * stored in extras.providerToolDefinition.\n */\ntype LangchainToolWithProviderDefinition = StructuredToolInterface & {\n extras: {\n providerToolDefinition: ResponsesTool;\n };\n};\n/**\n * Checks if a tool has a provider-specific tool definition in extras.providerToolDefinition.\n * This is used for tools like localShell, shell, computerUse, and applyPatch\n * that need to be sent as built-in tool types to the OpenAI API.\n */\nexport declare function hasProviderToolDefinition(tool: unknown): tool is LangchainToolWithProviderDefinition;\nexport declare function isBuiltInToolChoice(tool_choice: OpenAIToolChoice | ResponsesToolChoice | undefined): tool_choice is ResponsesToolChoice;\nexport type CustomToolCall = ToolCall & {\n call_id: string;\n isCustomTool: true;\n};\ntype LangchainCustomTool = DynamicTool<string> & {\n metadata: {\n customTool: OpenAIClient.Responses.CustomTool;\n };\n};\nexport declare function isCustomTool(tool: unknown): tool is LangchainCustomTool;\nexport declare function isOpenAICustomTool(tool: ChatOpenAIToolType): tool is OpenAIClient.Chat.ChatCompletionCustomTool;\nexport declare function parseCustomToolCall(rawToolCall: Record<string, any>): CustomToolCall | undefined;\nexport type ComputerToolCall = ToolCall & {\n call_id: string;\n /**\n * marker to indicate that the tool call is a computer tool call\n */\n isComputerTool: true;\n};\n/**\n * Parses a computer_call output item from the OpenAI Responses API\n * into a ToolCall format that can be processed by the ToolNode.\n *\n * @param rawToolCall - The raw computer_call output item from the API\n * @returns A ComputerToolCall object if valid, undefined otherwise\n */\nexport declare function parseComputerCall(rawToolCall: Record<string, any>): ComputerToolCall | undefined;\n/**\n * Checks if a tool call is a computer tool call.\n * @param toolCall - The tool call to check.\n * @returns True if the tool call is a computer tool call, false otherwise.\n */\nexport declare function isComputerToolCall(toolCall: unknown): toolCall is ComputerToolCall;\nexport declare function isCustomToolCall(toolCall: unknown): toolCall is CustomToolCall;\nexport declare function convertCompletionsCustomTool(tool: OpenAIClient.Chat.ChatCompletionCustomTool): OpenAIClient.Responses.CustomTool;\nexport declare function convertResponsesCustomTool(tool: OpenAIClient.Responses.CustomTool): OpenAIClient.Chat.ChatCompletionCustomTool;\nexport {};\n//# sourceMappingURL=tools.d.ts.map"],"mappings":";;;;;;KA2DYoB,gBAAAA,GAAmBnB,QAAAA,CAAaoB;KAChCC,mBAAAA,GAAsBG,YAAYxB,QAAAA,CAAasB,SAAAA,CAAUC;KACzDE,kBAAAA,GAAqBvB,iBAAiBF,QAAAA,CAAaS,IAAAA,CAAKF,qBAAqBmB;KAC7EA,aAAAA,GAAgBF,YAAYxB,QAAAA,CAAasB,SAAAA,CAAUC"}