mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 15:19:33 +00:00
openai[patch]: add test case for code interpreter (#31383)
This commit is contained in:
parent
c8a656c05b
commit
ab8b4003be
@ -386,9 +386,11 @@ def test_code_interpreter() -> None:
|
|||||||
llm_with_tools = llm.bind_tools(
|
llm_with_tools = llm.bind_tools(
|
||||||
[{"type": "code_interpreter", "container": {"type": "auto"}}]
|
[{"type": "code_interpreter", "container": {"type": "auto"}}]
|
||||||
)
|
)
|
||||||
response = llm_with_tools.invoke(
|
input_message = {
|
||||||
"Write and run code to answer the question: what is 3^3?"
|
"role": "user",
|
||||||
)
|
"content": "Write and run code to answer the question: what is 3^3?",
|
||||||
|
}
|
||||||
|
response = llm_with_tools.invoke([input_message])
|
||||||
_check_response(response)
|
_check_response(response)
|
||||||
tool_outputs = response.additional_kwargs["tool_outputs"]
|
tool_outputs = response.additional_kwargs["tool_outputs"]
|
||||||
assert tool_outputs
|
assert tool_outputs
|
||||||
@ -404,9 +406,7 @@ def test_code_interpreter() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
full: Optional[BaseMessageChunk] = None
|
full: Optional[BaseMessageChunk] = None
|
||||||
for chunk in llm_with_tools.stream(
|
for chunk in llm_with_tools.stream([input_message]):
|
||||||
"Write and run code to answer the question: what is 3^3?"
|
|
||||||
):
|
|
||||||
assert isinstance(chunk, AIMessageChunk)
|
assert isinstance(chunk, AIMessageChunk)
|
||||||
full = chunk if full is None else full + chunk
|
full = chunk if full is None else full + chunk
|
||||||
assert isinstance(full, AIMessageChunk)
|
assert isinstance(full, AIMessageChunk)
|
||||||
@ -414,6 +414,10 @@ def test_code_interpreter() -> None:
|
|||||||
assert tool_outputs
|
assert tool_outputs
|
||||||
assert any(output["type"] == "code_interpreter_call" for output in tool_outputs)
|
assert any(output["type"] == "code_interpreter_call" for output in tool_outputs)
|
||||||
|
|
||||||
|
# Test we can pass back in
|
||||||
|
next_message = {"role": "user", "content": "Please add more comments to the code."}
|
||||||
|
_ = llm_with_tools.invoke([input_message, full, next_message])
|
||||||
|
|
||||||
|
|
||||||
def test_mcp_builtin() -> None:
|
def test_mcp_builtin() -> None:
|
||||||
pytest.skip() # TODO: set up VCR
|
pytest.skip() # TODO: set up VCR
|
||||||
|
Loading…
Reference in New Issue
Block a user