fix(openai): add in output_text (#32450)

This property was deleted in `openai==1.99.2`.
This commit is contained in:
ccurme 2025-08-07 16:23:56 -03:00 committed by GitHub
parent 754528d23f
commit 68c70da33e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 31 deletions

View File

@ -3716,6 +3716,20 @@ def _construct_responses_api_input(messages: Sequence[BaseMessage]) -> list:
return input_
def _get_output_text(response: Response) -> str:
"""OpenAI SDK deleted response.output_text in 1.99.2"""
if hasattr(response, "output_text"):
return response.output_text
texts: list[str] = []
for output in response.output:
if output.type == "message":
for content in output.content:
if content.type == "output_text":
texts.append(content.text)
return "".join(texts)
def _construct_lc_result_from_responses_api(
response: Response,
schema: Optional[type[_BM]] = None,
@ -3830,17 +3844,18 @@ def _construct_lc_result_from_responses_api(
# text_format=Foo,
# stream=True, # <-- errors
# )
output_text = _get_output_text(response)
if (
schema is not None
and "parsed" not in additional_kwargs
and response.output_text # tool calls can generate empty output text
and output_text # tool calls can generate empty output text
and response.text
and (text_config := response.text.model_dump())
and (format_ := text_config.get("format", {}))
and (format_.get("type") == "json_schema")
):
try:
parsed_dict = json.loads(response.output_text)
parsed_dict = json.loads(output_text)
if schema and _is_pydantic_class(schema):
parsed = schema(**parsed_dict)
else:

View File

@ -480,7 +480,7 @@ wheels = [
[[package]]
name = "langchain-core"
version = "0.3.72"
version = "0.3.73"
source = { editable = "../../core" }
dependencies = [
{ name = "jsonpatch" },
@ -995,7 +995,7 @@ wheels = [
[[package]]
name = "openai"
version = "1.98.0"
version = "1.99.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "anyio" },
@ -1007,9 +1007,9 @@ dependencies = [
{ name = "tqdm" },
{ name = "typing-extensions" },
]
sdist = { url = "https://files.pythonhosted.org/packages/d8/9d/52eadb15c92802711d6b6cf00df3a6d0d18b588f4c5ba5ff210c6419fc03/openai-1.98.0.tar.gz", hash = "sha256:3ee0fcc50ae95267fd22bd1ad095ba5402098f3df2162592e68109999f685427", size = 496695, upload-time = "2025-07-30T12:48:03.701Z" }
sdist = { url = "https://files.pythonhosted.org/packages/de/2c/8cd1684364551237a5e6db24ce25c25ff54efcf1805b39110ec713dc2972/openai-1.99.2.tar.gz", hash = "sha256:118075b48109aa237636607b1346cf03b37cb9d74b0414cb11095850a0a22c96", size = 504752, upload-time = "2025-08-07T17:16:14.668Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/a8/fe/f64631075b3d63a613c0d8ab761d5941631a470f6fa87eaaee1aa2b4ec0c/openai-1.98.0-py3-none-any.whl", hash = "sha256:b99b794ef92196829120e2df37647722104772d2a74d08305df9ced5f26eae34", size = 767713, upload-time = "2025-07-30T12:48:01.264Z" },
{ url = "https://files.pythonhosted.org/packages/b7/06/f3338c1b8685dc1634fa5174dc5ba2d3eecc7887c9fc539bb5da6f75ebb3/openai-1.99.2-py3-none-any.whl", hash = "sha256:110d85b8ed400e1d7b02f8db8e245bd757bcde347cb6923155f42cd66a10aa0b", size = 785594, upload-time = "2025-08-07T17:16:13.083Z" },
]
[[package]]