mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
test(azure_ai): record the Azure inference request with respx instead of appending to a list
This commit is contained in:
parent
81ca2f309d
commit
c63d2c4397
1 changed files with 16 additions and 24 deletions
|
|
@ -12,7 +12,6 @@ from pydantic import ValidationError
|
|||
import litellm
|
||||
from litellm import anthropic_beta_headers_manager
|
||||
from litellm.llms.azure_ai.anthropic.count_tokens.token_counter import AzureAIAnthropicTokenCounter
|
||||
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler
|
||||
from litellm.types.utils import CountContextManagement, TokenCountResponse
|
||||
|
||||
API_BASE: Final = "https://my-resource.services.ai.azure.com"
|
||||
|
|
@ -275,26 +274,22 @@ async def test_count_sends_the_tool_change_beta_when_the_history_adds_a_tool(mon
|
|||
|
||||
|
||||
async def _betas_azure_inference_sends(context_management: Mapping[str, object]) -> frozenset[str]:
|
||||
received: Final[list[httpx.Request]] = []
|
||||
|
||||
def foundry_answers(request: httpx.Request) -> httpx.Response:
|
||||
received.append(request)
|
||||
return httpx.Response(
|
||||
200,
|
||||
json={
|
||||
"id": "msg_1",
|
||||
"type": "message",
|
||||
"role": "assistant",
|
||||
"model": "claude-sonnet-5-5",
|
||||
"content": [{"type": "text", "text": "ok"}],
|
||||
"stop_reason": "end_turn",
|
||||
"stop_sequence": None,
|
||||
"usage": {"input_tokens": 12, "output_tokens": 2},
|
||||
},
|
||||
with respx.mock:
|
||||
route: Final = respx.post(f"{API_BASE}/anthropic/v1/messages").mock(
|
||||
return_value=httpx.Response(
|
||||
200,
|
||||
json={
|
||||
"id": "msg_1",
|
||||
"type": "message",
|
||||
"role": "assistant",
|
||||
"model": "claude-sonnet-5-5",
|
||||
"content": [{"type": "text", "text": "ok"}],
|
||||
"stop_reason": "end_turn",
|
||||
"stop_sequence": None,
|
||||
"usage": {"input_tokens": 12, "output_tokens": 2},
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
upstream: Final = AsyncHTTPHandler(transport=httpx.MockTransport(foundry_answers))
|
||||
try:
|
||||
await litellm.anthropic.messages.acreate(
|
||||
max_tokens=64,
|
||||
messages=[{"role": "user", "content": "Summarize the thread."}],
|
||||
|
|
@ -302,11 +297,8 @@ async def _betas_azure_inference_sends(context_management: Mapping[str, object])
|
|||
api_key="azure-key",
|
||||
api_base=API_BASE,
|
||||
context_management=context_management,
|
||||
client=upstream,
|
||||
)
|
||||
finally:
|
||||
await upstream.close()
|
||||
return frozenset(filter(None, received[0].headers.get("anthropic-beta", "").split(",")))
|
||||
return frozenset(filter(None, route.calls.last.request.headers.get("anthropic-beta", "").split(",")))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue