mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-23 03:22:38 +00:00
openai: revert some cassette changes
This commit is contained in:
parent
ce369125f3
commit
7ab615409c
@ -70,14 +70,7 @@ import json
|
|||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from typing import Any, Union, cast
|
from typing import Any, Union, cast
|
||||||
|
|
||||||
from langchain_core.messages import (
|
from langchain_core.messages import AIMessage, AIMessageChunk, is_data_content_block
|
||||||
AIMessage,
|
|
||||||
AIMessageChunk,
|
|
||||||
DocumentCitation,
|
|
||||||
NonStandardAnnotation,
|
|
||||||
UrlCitation,
|
|
||||||
is_data_content_block,
|
|
||||||
)
|
|
||||||
|
|
||||||
_FUNCTION_CALL_IDS_MAP_KEY = "__openai_function_call_ids__"
|
_FUNCTION_CALL_IDS_MAP_KEY = "__openai_function_call_ids__"
|
||||||
|
|
||||||
@ -318,30 +311,30 @@ def _convert_from_v1_to_chat_completions(message: AIMessage) -> AIMessage:
|
|||||||
|
|
||||||
|
|
||||||
# v1 / Responses
|
# v1 / Responses
|
||||||
def _convert_annotation_to_v1(
|
def _convert_annotation_to_v1(annotation: dict[str, Any]) -> dict[str, Any]:
|
||||||
annotation: dict[str, Any],
|
|
||||||
) -> Union[UrlCitation, DocumentCitation, NonStandardAnnotation]:
|
|
||||||
annotation_type = annotation.get("type")
|
annotation_type = annotation.get("type")
|
||||||
|
|
||||||
if annotation_type == "url_citation":
|
if annotation_type == "url_citation":
|
||||||
url_citation: UrlCitation = {"type": "url_citation", "url": annotation["url"]}
|
url_citation = {}
|
||||||
for field in ("title", "start_index", "end_index"):
|
for field in ("end_index", "start_index", "title"):
|
||||||
if field in annotation:
|
if field in annotation:
|
||||||
url_citation[field] = annotation[field]
|
url_citation[field] = annotation[field]
|
||||||
|
url_citation["type"] = "url_citation"
|
||||||
|
url_citation["url"] = annotation["url"]
|
||||||
return url_citation
|
return url_citation
|
||||||
|
|
||||||
elif annotation_type == "file_citation":
|
elif annotation_type == "file_citation":
|
||||||
document_citation: DocumentCitation = {"type": "document_citation"}
|
document_citation = {"type": "document_citation"}
|
||||||
if "filename" in annotation:
|
if "filename" in annotation:
|
||||||
document_citation["title"] = annotation["filename"]
|
document_citation["title"] = annotation["filename"]
|
||||||
for field in ("file_id", "index"): # OpenAI-specific
|
for field in ("file_id", "index"): # OpenAI-specific
|
||||||
if field in annotation:
|
if field in annotation:
|
||||||
document_citation[field] = annotation[field] # type: ignore[literal-required]
|
document_citation[field] = annotation[field]
|
||||||
return document_citation
|
return document_citation
|
||||||
|
|
||||||
# TODO: standardise container_file_citation?
|
# TODO: standardise container_file_citation?
|
||||||
else:
|
else:
|
||||||
non_standard_annotation: NonStandardAnnotation = {
|
non_standard_annotation = {
|
||||||
"type": "non_standard_annotation",
|
"type": "non_standard_annotation",
|
||||||
"value": annotation,
|
"value": annotation,
|
||||||
}
|
}
|
||||||
@ -472,7 +465,9 @@ def _implode_reasoning_blocks(blocks: list[dict[str, Any]]) -> Iterable[dict[str
|
|||||||
continue
|
continue
|
||||||
elif "reasoning" not in block and "summary" not in block:
|
elif "reasoning" not in block and "summary" not in block:
|
||||||
# {"type": "reasoning", "id": "rs_..."}
|
# {"type": "reasoning", "id": "rs_..."}
|
||||||
yield {**block, "summary": []}
|
oai_format = {**block, "summary": []}
|
||||||
|
oai_format["type"] = oai_format.pop("type", "reasoning")
|
||||||
|
yield oai_format
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -497,6 +492,7 @@ def _implode_reasoning_blocks(blocks: list[dict[str, Any]]) -> Iterable[dict[str
|
|||||||
|
|
||||||
merged = dict(common)
|
merged = dict(common)
|
||||||
merged["summary"] = summary
|
merged["summary"] = summary
|
||||||
|
merged["type"] = merged.pop("type", "reasoning")
|
||||||
yield merged
|
yield merged
|
||||||
|
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user