工具
langchain_core.utils ¶
LangChain 的实用函数。
这些函数不依赖于任何其他 LangChain 模块。
langchain_core.utils.function_calling ¶
用于创建 OpenAI 函数风格的函数规范的方法。
| 函数 | 描述 |
|---|---|
convert_to_json_schema |
将模式表示转换为 JSON 模式。 |
convert_to_openai_tool |
将类工具对象转换为 OpenAI 工具模式。 |
convert_to_json_schema ¶
convert_to_openai_tool ¶
convert_to_openai_tool(
tool: dict[str, Any] | type[BaseModel] | Callable | BaseTool,
*,
strict: bool | None = None,
) -> dict[str, Any]
将类工具对象转换为 OpenAI 工具模式。
| 参数 | 描述 |
|---|---|
tool
|
可以是字典、 |
strict
|
如果为
类型: |
| 返回 | 描述 |
|---|---|
dict[str, Any]
|
传入工具的字典版本,与 |
dict[str, Any]
|
OpenAI 工具调用 API 兼容。 |
在 0.3.16 版本中行为发生变化
description 和 parameters 键现在是可选的。只有 name 是必需的,并保证是输出的一部分。
在 0.3.44 版本中行为发生变化
返回 OpenAI Responses API 风格的工具时保持不变。这包括任何 "type" 在 "file_search"、"function"、"computer_use_preview"、"web_search_preview" 中的字典。
在 0.3.63 版本中行为发生变化
增加了对 OpenAI 图像生成内置工具的支持。