diff --git a/libs/partners/openai/langchain_openai/chat_models/base.py b/libs/partners/openai/langchain_openai/chat_models/base.py index 0b1f3ef9604..7cb80a7f134 100644 --- a/libs/partners/openai/langchain_openai/chat_models/base.py +++ b/libs/partners/openai/langchain_openai/chat_models/base.py @@ -3889,7 +3889,17 @@ def _convert_responses_chunk_to_generation_chunk( annotation = chunk.annotation else: annotation = chunk.annotation.model_dump(exclude_none=True, mode="json") - content.append({"annotations": [annotation], "index": current_index}) + if output_version == "v1": + content.append( + { + "type": "text", + "text": "", + "annotations": [annotation], + "index": current_index + } + ) + else: + content.append({"annotations": [annotation], "index": current_index}) elif chunk.type == "response.output_text.done": if output_version == "v1": content.append( diff --git a/libs/partners/openai/tests/cassettes/test_web_search.yaml.gz b/libs/partners/openai/tests/cassettes/test_web_search.yaml.gz index e99f1c2e13a..c1231c99f98 100644 Binary files a/libs/partners/openai/tests/cassettes/test_web_search.yaml.gz and b/libs/partners/openai/tests/cassettes/test_web_search.yaml.gz differ diff --git a/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py b/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py index fac526c382b..3568b3dd136 100644 --- a/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py +++ b/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py @@ -55,7 +55,7 @@ def _check_response(response: Optional[BaseMessage]) -> None: @pytest.mark.default_cassette("test_web_search.yaml.gz") @pytest.mark.vcr @pytest.mark.parametrize("output_version", ["responses/v1", "v1"]) -def test_web_search(output_version: Literal["v0", "responses/v1", "v1"]) -> None: +def test_web_search(output_version: Literal["responses/v1", "v1"]) -> None: llm = ChatOpenAI(model=MODEL_NAME, output_version=output_version) first_response = llm.invoke( "What was a positive news story from today?", @@ -112,7 +112,10 @@ def test_web_search(output_version: Literal["v0", "responses/v1", "v1"]) -> None for msg in [first_response, full, response]: assert isinstance(msg, AIMessage) block_types = [block["type"] for block in msg.content] # type: ignore[index] - assert block_types == ["web_search_call", "text"] + if output_version == "responses/v1": + assert block_types == ["web_search_call", "text"] + else: + assert block_types == ["non_standard", "text"] @pytest.mark.flaky(retries=3, delay=1)