mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
fix(openai): support phase parameter (#36161)
This commit is contained in:
@@ -1347,6 +1347,98 @@ def test_csv_input() -> None:
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.default_cassette("test_phase.yaml.gz")
|
||||
@pytest.mark.vcr
|
||||
@pytest.mark.parametrize("output_version", ["responses/v1", "v1"])
|
||||
def test_phase(output_version: str) -> None:
|
||||
def get_weather(location: str) -> str:
|
||||
"""Get the weather at a location."""
|
||||
return "It's sunny."
|
||||
|
||||
model = ChatOpenAI(
|
||||
model="gpt-5.4",
|
||||
use_responses_api=True,
|
||||
verbosity="high",
|
||||
reasoning={"effort": "medium", "summary": "auto"},
|
||||
output_version=output_version,
|
||||
)
|
||||
|
||||
agent = create_agent(model, tools=[get_weather])
|
||||
|
||||
input_message = {
|
||||
"role": "user",
|
||||
"content": (
|
||||
"What's the weather in the oldest major city in the US? State your answer "
|
||||
"and then generate a tool call this turn."
|
||||
),
|
||||
}
|
||||
result = agent.invoke({"messages": [input_message]})
|
||||
first_response = result["messages"][1]
|
||||
text_block = next(
|
||||
block for block in first_response.content if block["type"] == "text"
|
||||
)
|
||||
assert text_block["phase"] == "commentary"
|
||||
|
||||
final_response = result["messages"][-1]
|
||||
text_block = next(
|
||||
block for block in final_response.content if block["type"] == "text"
|
||||
)
|
||||
assert text_block["phase"] == "final_answer"
|
||||
|
||||
|
||||
@pytest.mark.default_cassette("test_phase_streaming.yaml.gz")
|
||||
@pytest.mark.vcr
|
||||
@pytest.mark.parametrize("output_version", ["responses/v1", "v1"])
|
||||
def test_phase_streaming(output_version: str) -> None:
|
||||
def get_weather(location: str) -> str:
|
||||
"""Get the weather at a location."""
|
||||
return "It's sunny."
|
||||
|
||||
model = ChatOpenAI(
|
||||
model="gpt-5.4",
|
||||
use_responses_api=True,
|
||||
verbosity="high",
|
||||
reasoning={"effort": "medium", "summary": "auto"},
|
||||
streaming=True,
|
||||
output_version=output_version,
|
||||
)
|
||||
|
||||
agent = create_agent(model, tools=[get_weather])
|
||||
|
||||
input_message = {
|
||||
"role": "user",
|
||||
"content": (
|
||||
"What's the weather in the oldest major city in the US? State your answer "
|
||||
"and then generate a tool call this turn."
|
||||
),
|
||||
}
|
||||
result = agent.invoke({"messages": [input_message]})
|
||||
first_response = result["messages"][1]
|
||||
if output_version == "responses/v1":
|
||||
assert [block["type"] for block in first_response.content] == [
|
||||
"reasoning",
|
||||
"text",
|
||||
"function_call",
|
||||
]
|
||||
else:
|
||||
assert [block["type"] for block in first_response.content] == [
|
||||
"reasoning",
|
||||
"text",
|
||||
"tool_call",
|
||||
]
|
||||
text_block = next(
|
||||
block for block in first_response.content if block["type"] == "text"
|
||||
)
|
||||
assert text_block["phase"] == "commentary"
|
||||
|
||||
final_response = result["messages"][-1]
|
||||
assert [block["type"] for block in final_response.content] == ["text"]
|
||||
text_block = next(
|
||||
block for block in final_response.content if block["type"] == "text"
|
||||
)
|
||||
assert text_block["phase"] == "final_answer"
|
||||
|
||||
|
||||
@pytest.mark.default_cassette("test_tool_search.yaml.gz")
|
||||
@pytest.mark.vcr
|
||||
@pytest.mark.parametrize("output_version", ["responses/v1", "v1"])
|
||||
|
||||
Reference in New Issue
Block a user