mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 22:03:52 +00:00
langchain_openai: Add "strict" parameter to OpenAIFunctionsAgent (#25862)
- **Description:** OpenAI recently introduced a "strict" parameter for [structured outputs in their API](https://openai.com/index/introducing-structured-outputs-in-the-api/). An optional `strict` parameter has been added to `create_openai_functions_agent()` and `create_openai_tools_agent()` so developers can use this feature in those agents. --------- Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
parent
fabd3295fa
commit
e7c856c298
@ -1,4 +1,4 @@
|
||||
from typing import Sequence
|
||||
from typing import Optional, Sequence
|
||||
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.prompts.chat import ChatPromptTemplate
|
||||
@ -13,7 +13,10 @@ from langchain.agents.output_parsers.openai_tools import OpenAIToolsAgentOutputP
|
||||
|
||||
|
||||
def create_openai_tools_agent(
|
||||
llm: BaseLanguageModel, tools: Sequence[BaseTool], prompt: ChatPromptTemplate
|
||||
llm: BaseLanguageModel,
|
||||
tools: Sequence[BaseTool],
|
||||
prompt: ChatPromptTemplate,
|
||||
strict: Optional[bool] = None,
|
||||
) -> Runnable:
|
||||
"""Create an agent that uses OpenAI tools.
|
||||
|
||||
@ -87,7 +90,9 @@ def create_openai_tools_agent(
|
||||
if missing_vars:
|
||||
raise ValueError(f"Prompt missing required variables: {missing_vars}")
|
||||
|
||||
llm_with_tools = llm.bind(tools=[convert_to_openai_tool(tool) for tool in tools])
|
||||
llm_with_tools = llm.bind(
|
||||
tools=[convert_to_openai_tool(tool, strict=strict) for tool in tools]
|
||||
)
|
||||
|
||||
agent = (
|
||||
RunnablePassthrough.assign(
|
||||
|
Loading…
Reference in New Issue
Block a user