Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /BerriAI_litellm /tests /benchmarks /test_a2a_benchmarks.py
| """ | |
| Performance benchmarks for the A2A (agent-to-agent) message-translation hot path. | |
| Both directions are covered: the client direction (litellm.completion talking to | |
| an upstream A2A agent) converts OpenAI messages into a prompt and extracts text | |
| from the A2A response, and the proxy server-ingress direction converts an inbound | |
| A2A message into OpenAI messages before bridging to a completion. All are pure-CPU | |
| per-request transforms. | |
| """ | |
| import pytest | |
| from litellm.a2a_protocol.litellm_completion_bridge.transformation import ( | |
| A2ACompletionBridgeTransformation, | |
| ) | |
| from litellm.llms.a2a.common_utils import ( | |
| convert_messages_to_prompt, | |
| extract_text_from_a2a_response, | |
| ) | |
| MESSAGES = [ | |
| {"role": "system", "content": "You are a helpful research assistant."}, | |
| {"role": "user", "content": "What is the capital of France?"}, | |
| {"role": "assistant", "content": "The capital of France is Paris."}, | |
| {"role": "user", "content": "And what is its population?"}, | |
| ] | |
| MESSAGE_RESPONSE = { | |
| "result": { | |
| "kind": "message", | |
| "parts": [ | |
| {"kind": "text", "text": "The population of Paris is about 2.1 million."}, | |
| {"kind": "text", "text": "The metro area has over 12 million people."}, | |
| ], | |
| } | |
| } | |
| TASK_RESPONSE = { | |
| "result": { | |
| "kind": "task", | |
| "artifacts": [{"parts": [{"kind": "text", "text": "Paris has a population of about 2.1 million."}]}], | |
| } | |
| } | |
| A2A_INBOUND_MESSAGE = { | |
| "role": "user", | |
| "parts": [ | |
| {"kind": "text", "text": "Summarize the latest quarterly report."}, | |
| {"kind": "text", "text": "Focus on revenue and margins."}, | |
| ], | |
| "messageId": "msg-1", | |
| } | |
| def test_convert_messages_to_a2a_prompt(): | |
| """Benchmark converting OpenAI messages into an A2A prompt string.""" | |
| convert_messages_to_prompt(messages=MESSAGES) | |
| def test_extract_text_from_a2a_message_response(): | |
| """Benchmark extracting text from a direct-message A2A response.""" | |
| extract_text_from_a2a_response(response_dict=MESSAGE_RESPONSE) | |
| def test_extract_text_from_a2a_task_response(): | |
| """Benchmark extracting text from a task-with-artifacts A2A response.""" | |
| extract_text_from_a2a_response(response_dict=TASK_RESPONSE) | |
| def test_a2a_inbound_message_to_openai_messages(): | |
| """Benchmark the proxy converting an inbound A2A message into OpenAI messages.""" | |
| A2ACompletionBridgeTransformation.a2a_message_to_openai_messages(A2A_INBOUND_MESSAGE) | |
Xet Storage Details
- Size:
- 2.55 kB
- Xet hash:
- fe704f5bf28860c341854951329a39af6f911cb3dbfbc9e4f911df7559fb331c
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.