mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-09 04:50:37 +00:00
fix streaming annotations
This commit is contained in:
parent
e928672306
commit
6004ba7a0d
@ -3889,6 +3889,16 @@ def _convert_responses_chunk_to_generation_chunk(
|
||||
annotation = chunk.annotation
|
||||
else:
|
||||
annotation = chunk.annotation.model_dump(exclude_none=True, mode="json")
|
||||
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":
|
||||
|
Binary file not shown.
@ -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]
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user