mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-12 14:23:58 +00:00
openai: fix lint and tests
This commit is contained in:
parent
eb8d32aff2
commit
7c0d1cb324
@ -3807,11 +3807,12 @@ def _construct_lc_result_from_responses_api(
|
|||||||
)
|
)
|
||||||
if image_generation_call.output_format:
|
if image_generation_call.output_format:
|
||||||
mime_type = f"image/{image_generation_call.output_format}"
|
mime_type = f"image/{image_generation_call.output_format}"
|
||||||
for block in message.content:
|
for content_block in message.content:
|
||||||
# OK to mutate output message
|
# OK to mutate output message
|
||||||
if (
|
if (
|
||||||
block.get("type") == "image"
|
isinstance(content_block, dict)
|
||||||
and "base64" in block
|
and content_block.get("type") == "image"
|
||||||
|
and "base64" in content_block
|
||||||
and "mime_type" not in block
|
and "mime_type" not in block
|
||||||
):
|
):
|
||||||
block["mime_type"] = mime_type
|
block["mime_type"] = mime_type
|
||||||
@ -4055,10 +4056,13 @@ def _convert_responses_chunk_to_generation_chunk(
|
|||||||
)
|
)
|
||||||
elif output_version == "v1":
|
elif output_version == "v1":
|
||||||
message = cast(AIMessageChunk, _convert_to_v1_from_responses(message))
|
message = cast(AIMessageChunk, _convert_to_v1_from_responses(message))
|
||||||
for block in message.content:
|
for content_block in message.content:
|
||||||
if block.get("index", -1) > current_index:
|
if (
|
||||||
|
isinstance(content_block, dict)
|
||||||
|
and content_block.get("index", -1) > current_index
|
||||||
|
):
|
||||||
# blocks were added for v1
|
# blocks were added for v1
|
||||||
current_index = block["index"]
|
current_index = content_block["index"]
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
return (
|
return (
|
||||||
|
@ -496,7 +496,7 @@ def test_code_interpreter(output_version: Literal["v0", "responses/v1", "v1"]) -
|
|||||||
code_interpreter_result = next(
|
code_interpreter_result = next(
|
||||||
item
|
item
|
||||||
for item in response.content
|
for item in response.content
|
||||||
if item["type"] == "code_interpreter_result"
|
if isinstance(item, dict) and item["type"] == "code_interpreter_result"
|
||||||
)
|
)
|
||||||
assert tool_outputs
|
assert tool_outputs
|
||||||
assert code_interpreter_result
|
assert code_interpreter_result
|
||||||
@ -528,12 +528,14 @@ def test_code_interpreter(output_version: Literal["v0", "responses/v1", "v1"]) -
|
|||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
code_interpreter_call = next(
|
code_interpreter_call = next(
|
||||||
item for item in response.content if item["type"] == "code_interpreter_call"
|
item
|
||||||
|
for item in response.content
|
||||||
|
if isinstance(item, dict) and item["type"] == "code_interpreter_call"
|
||||||
)
|
)
|
||||||
code_interpreter_result = next(
|
code_interpreter_result = next(
|
||||||
item
|
item
|
||||||
for item in response.content
|
for item in response.content
|
||||||
if item["type"] == "code_interpreter_result"
|
if isinstance(item, dict) and item["type"] == "code_interpreter_result"
|
||||||
)
|
)
|
||||||
assert code_interpreter_call
|
assert code_interpreter_call
|
||||||
assert code_interpreter_result
|
assert code_interpreter_result
|
||||||
@ -701,7 +703,9 @@ def test_image_generation_streaming(output_version: str) -> None:
|
|||||||
# v1
|
# v1
|
||||||
standard_keys = {"type", "base64", "id", "status", "index"}
|
standard_keys = {"type", "base64", "id", "status", "index"}
|
||||||
tool_output = next(
|
tool_output = next(
|
||||||
block for block in complete_ai_message.content if block["type"] == "image"
|
block
|
||||||
|
for block in complete_ai_message.content
|
||||||
|
if isinstance(block, dict) and block["type"] == "image"
|
||||||
)
|
)
|
||||||
assert set(standard_keys).issubset(tool_output.keys())
|
assert set(standard_keys).issubset(tool_output.keys())
|
||||||
|
|
||||||
@ -758,7 +762,9 @@ def test_image_generation_multi_turn(output_version: str) -> None:
|
|||||||
else:
|
else:
|
||||||
standard_keys = {"type", "base64", "id", "status"}
|
standard_keys = {"type", "base64", "id", "status"}
|
||||||
tool_output = next(
|
tool_output = next(
|
||||||
block for block in ai_message.content if block["type"] == "image"
|
block
|
||||||
|
for block in ai_message.content
|
||||||
|
if isinstance(block, dict) and block["type"] == "image"
|
||||||
)
|
)
|
||||||
assert set(standard_keys).issubset(tool_output.keys())
|
assert set(standard_keys).issubset(tool_output.keys())
|
||||||
|
|
||||||
@ -810,6 +816,8 @@ def test_image_generation_multi_turn(output_version: str) -> None:
|
|||||||
else:
|
else:
|
||||||
standard_keys = {"type", "base64", "id", "status"}
|
standard_keys = {"type", "base64", "id", "status"}
|
||||||
tool_output = next(
|
tool_output = next(
|
||||||
block for block in ai_message2.content if block["type"] == "image"
|
block
|
||||||
|
for block in ai_message2.content
|
||||||
|
if isinstance(block, dict) and block["type"] == "image"
|
||||||
)
|
)
|
||||||
assert set(standard_keys).issubset(tool_output.keys())
|
assert set(standard_keys).issubset(tool_output.keys())
|
||||||
|
@ -2534,8 +2534,7 @@ def test_convert_to_v1_from_chat_completions(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"source_type": "base64",
|
"base64": "...",
|
||||||
"data": "...",
|
|
||||||
"id": "img_123",
|
"id": "img_123",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -2739,8 +2738,7 @@ def test_convert_from_v1_to_responses(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"source_type": "base64",
|
"base64": "...",
|
||||||
"data": "...",
|
|
||||||
"id": "img_123",
|
"id": "img_123",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user