MCPcopy
hub / github.com/openai/openai-python / test_parse_strict_tools

Function test_parse_strict_tools

tests/lib/chat/test_completions.py:748–818  ·  view source on GitHub ↗
(client: OpenAI, respx_mock: MockRouter, monkeypatch: pytest.MonkeyPatch)

Source from the content-addressed store, hash-verified

746
747@pytest.mark.respx(base_url=base_url)
748def test_parse_strict_tools(client: OpenAI, respx_mock: MockRouter, monkeypatch: pytest.MonkeyPatch) -> None:
749 completion = make_snapshot_request(
750 lambda c: c.chat.completions.parse(
751 model="gpt-4o-2024-08-06",
752 messages=[
753 {
754 "role": "user",
755 "content": "What's the weather like in SF?",
756 },
757 ],
758 tools=[
759 {
760 "type": "function",
761 "function": {
762 "name": "get_weather",
763 "parameters": {
764 "type": "object",
765 "properties": {
766 "city": {"type": "string"},
767 "state": {"type": "string"},
768 },
769 "required": [
770 "city",
771 "state",
772 ],
773 "additionalProperties": False,
774 },
775 "strict": True,
776 },
777 }
778 ],
779 ),
780 content_snapshot=snapshot(
781 '{"id": "chatcmpl-ABfvzdvCI6RaIkiEFNjqGXCSYnlzf", "object": "chat.completion", "created": 1727346167, "model": "gpt-4o-2024-08-06", "choices": [{"index": 0, "message": {"role": "assistant", "content": null, "tool_calls": [{"id": "call_CUdUoJpsWWVdxXntucvnol1M", "type": "function", "function": {"name": "get_weather", "arguments": "{\\"city\\":\\"San Francisco\\",\\"state\\":\\"CA\\"}"}}], "refusal": null}, "logprobs": null, "finish_reason": "tool_calls"}], "usage": {"prompt_tokens": 48, "completion_tokens": 19, "total_tokens": 67, "completion_tokens_details": {"reasoning_tokens": 0}}, "system_fingerprint": "fp_5050236cbd"}'
782 ),
783 path="/chat/completions",
784 mock_client=client,
785 respx_mock=respx_mock,
786 )
787
788 assert print_obj(completion.choices, monkeypatch) == snapshot(
789 """\
790[
791 ParsedChoice(
792 finish_reason='tool_calls',
793 index=0,
794 logprobs=None,
795 message=ParsedChatCompletionMessage(
796 annotations=None,
797 audio=None,
798 content=None,
799 function_call=None,
800 parsed=None,
801 refusal=None,
802 role='assistant',
803 tool_calls=[
804 ParsedFunctionToolCall(
805 function=ParsedFunction(

Callers

nothing calls this directly

Calls 3

make_snapshot_requestFunction · 0.85
print_objFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected