MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / test_content_mode

Method test_content_mode

tests/test_open_telemetry.py:4906–4964  ·  view source on GitHub ↗
(self, spans: Spans, respx_mock: MockRouter)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

make_clientFunction · 0.70
attributesFunction · 0.70
postMethod · 0.45
optionMethod · 0.45
createMethod · 0.45
oneMethod · 0.45

Tested by

no test coverage detected