|
7 | 7 | import httpx |
8 | 8 | import pydantic |
9 | 9 | import pytest |
10 | | -from anthropic._models import FinalRequestOptions |
11 | 10 | from anthropic.types import ( |
12 | 11 | Completion, |
13 | 12 | Message, |
|
24 | 23 | from inline_snapshot import snapshot |
25 | 24 |
|
26 | 25 | import logfire |
27 | | -from logfire._internal.integrations.llm_providers.anthropic import get_endpoint_config |
28 | 26 | from logfire.testing import TestExporter |
29 | 27 |
|
30 | 28 | ANY_ADAPTER = pydantic.TypeAdapter(Any) # type: ignore |
@@ -491,35 +489,24 @@ def test_unknown_method(instrumented_client: anthropic.Anthropic, exporter: Test |
491 | 489 | assert exporter.exported_spans_as_dict() == snapshot( |
492 | 490 | [ |
493 | 491 | { |
494 | | - 'name': 'Unable to instrument {suffix} API call: {error}', |
| 492 | + 'name': 'Anthropic API call to {url!r}', |
495 | 493 | 'context': {'is_remote': False, 'span_id': 1, 'trace_id': 1}, |
496 | 494 | 'parent': None, |
497 | 495 | 'start_time': 1000000000, |
498 | | - 'end_time': 1000000000, |
| 496 | + 'end_time': 2000000000, |
499 | 497 | 'attributes': { |
500 | | - 'logfire.span_type': 'log', |
| 498 | + 'logfire.span_type': 'span', |
501 | 499 | 'logfire.tags': ('LLM',), |
502 | | - 'logfire.level_num': 13, |
503 | | - 'logfire.msg_template': 'Unable to instrument {suffix} API call: {error}', |
504 | | - 'logfire.msg': 'Unable to instrument Anthropic API call: Unknown Anthropic API endpoint: `/v1/complete`', |
| 500 | + 'request_data': '{"max_tokens_to_sample":1000,"model":"claude-2.1","prompt":"prompt"}', |
| 501 | + 'url': '/v1/complete', |
| 502 | + 'async': False, |
| 503 | + 'logfire.msg_template': 'Anthropic API call to {url!r}', |
| 504 | + 'logfire.msg': "Anthropic API call to '/v1/complete'", |
505 | 505 | 'code.filepath': 'test_anthropic.py', |
506 | 506 | 'code.function': 'test_unknown_method', |
507 | 507 | 'code.lineno': 123, |
508 | | - 'error': 'Unknown Anthropic API endpoint: `/v1/complete`', |
509 | | - 'kwargs': IsStr(), |
510 | 508 | 'logfire.json_schema': IsStr(), |
511 | | - 'suffix': 'Anthropic', |
512 | 509 | }, |
513 | 510 | } |
514 | 511 | ] |
515 | 512 | ) |
516 | | - |
517 | | - |
518 | | -def test_get_endpoint_config_json_not_dict(): |
519 | | - with pytest.raises(ValueError, match='Expected `options.json_data` to be a dictionary'): |
520 | | - get_endpoint_config(FinalRequestOptions(method='POST', url='...')) |
521 | | - |
522 | | - |
523 | | -def test_get_endpoint_config_unknown_url(): |
524 | | - with pytest.raises(ValueError, match='Unknown Anthropic API endpoint: `/foobar/`'): |
525 | | - get_endpoint_config(FinalRequestOptions(method='POST', url='/foobar/', json_data={'model': 'foobar'})) |
0 commit comments