(self, spans: Spans, respx_mock: MockRouter)
| 4903 | class TestContent: |
| 4904 | @pytest.mark.respx(base_url=base_url) |
| 4905 | def test_content_mode(self, spans: Spans, respx_mock: MockRouter) -> None: |
| 4906 | response = { |
| 4907 | **MESSAGE, |
| 4908 | "content": [ |
| 4909 | {"type": "text", "text": "Let me check"}, |
| 4910 | {"type": "tool_use", "id": "toolu_1", "name": "get_weather", "input": {"city": "SF"}}, |
| 4911 | ], |
| 4912 | } |
| 4913 | respx_mock.post("/v1/messages").mock(return_value=httpx2.Response(200, json=response)) |
| 4914 | client = make_client(spans, open_telemetry=spans.option(traces={"content_mode": "content"})) |
| 4915 | |
| 4916 | client.messages.create( |
| 4917 | max_tokens=1024, |
| 4918 | model="claude-test", |
| 4919 | system="Be brief", |
| 4920 | messages=[ |
| 4921 | {"role": "user", "content": "Weather?"}, |
| 4922 | { |
| 4923 | "role": "assistant", |
| 4924 | "content": [{"type": "tool_use", "id": "toolu_0", "name": "get_weather", "input": {"city": "LA"}}], |
| 4925 | }, |
| 4926 | { |
| 4927 | "role": "user", |
| 4928 | "content": [ |
| 4929 | {"type": "tool_result", "tool_use_id": "toolu_0", "content": "sunny"}, |
| 4930 | {"type": "image", "source": {"type": "url", "url": "https://example.com/cat.png"}}, |
| 4931 | {"type": "document", "source": {"type": "text", "media_type": "text/plain", "data": "Cats"}}, |
| 4932 | ], |
| 4933 | }, |
| 4934 | ], |
| 4935 | ) |
| 4936 | |
| 4937 | span = spans.one("anthropic.messages.create") |
| 4938 | assert json.loads(attributes(span)["gen_ai.system_instructions"]) == [{"type": "text", "content": "Be brief"}] |
| 4939 | assert json.loads(attributes(span)["gen_ai.input.messages"]) == [ |
| 4940 | {"role": "user", "parts": [{"type": "text", "content": "Weather?"}]}, |
| 4941 | { |
| 4942 | "role": "assistant", |
| 4943 | "parts": [{"type": "tool_call", "id": "toolu_0", "name": "get_weather", "arguments": {"city": "LA"}}], |
| 4944 | }, |
| 4945 | { |
| 4946 | "role": "user", |
| 4947 | "parts": [ |
| 4948 | {"type": "tool_call_response", "id": "toolu_0", "response": [{"type": "text", "text": "sunny"}]}, |
| 4949 | # Any other block is its type after `anthropic_`. |
| 4950 | {"type": "anthropic_image"}, |
| 4951 | {"type": "anthropic_document"}, |
| 4952 | ], |
| 4953 | }, |
| 4954 | ] |
| 4955 | assert json.loads(attributes(span)["gen_ai.output.messages"]) == [ |
| 4956 | { |
| 4957 | "role": "assistant", |
| 4958 | "parts": [ |
| 4959 | {"type": "text", "content": "Let me check"}, |
| 4960 | {"type": "tool_call", "id": "toolu_1", "name": "get_weather", "arguments": {"city": "SF"}}, |
| 4961 | ], |
| 4962 | } |
nothing calls this directly
no test coverage detected