fix(main.py): pass extra headers through for async calls

This commit is contained in:
Krrish Dholakia 2024-05-27 19:11:40 -07:00
parent 24eb79da91
commit 6b50e656b8
3 changed files with 18 additions and 7 deletions

View file

@ -294,6 +294,7 @@ async def acompletion(
"api_version": api_version,
"api_key": api_key,
"model_list": model_list,
"extra_headers": extra_headers,
"acompletion": True, # assuming this is a required parameter
}
if custom_llm_provider is None:

View file

@ -24,8 +24,8 @@ general_settings:
database_connection_timeout: 60
health_check_interval: 300
ui_access_mode: all
litellm_settings:
json_logs: true
# litellm_settings:
# json_logs: true
model_list:
- litellm_params:
api_base: http://0.0.0.0:8080
@ -43,5 +43,14 @@ model_list:
api_version: '2023-05-15'
model: azure/chatgpt-v-2
model_name: gpt-3.5-turbo
- litellm_params:
model: anthropic.claude-3-sonnet-20240229-v1:0
model_name: bedrock-anthropic-claude-3
- litellm_params:
api_base: https://openai-gpt-4-test-v-1.openai.azure.com/
api_key: os.environ/AZURE_API_KEY
api_version: '2023-05-15'
model: azure/chatgpt-v-2
model_name: gpt-3.5-turbo
router_settings:
enable_pre_call_checks: true

View file

@ -13,7 +13,7 @@ import pytest
import litellm
from litellm import embedding, completion, completion_cost, Timeout, ModelResponse
from litellm import RateLimitError
from litellm.llms.custom_httpx.http_handler import HTTPHandler
from litellm.llms.custom_httpx.http_handler import HTTPHandler, AsyncHTTPHandler
from unittest.mock import patch, AsyncMock, Mock
# litellm.num_retries = 3
@ -519,20 +519,21 @@ def test_bedrock_ptu():
mock_client_post.assert_called_once()
def test_bedrock_extra_headers():
@pytest.mark.asyncio
async def test_bedrock_extra_headers():
"""
Check if a url with 'modelId' passed in, is created correctly
Reference: https://github.com/BerriAI/litellm/issues/3805
"""
client = HTTPHandler()
client = AsyncHTTPHandler()
with patch.object(client, "post", new=Mock()) as mock_client_post:
with patch.object(client, "post", new=AsyncMock()) as mock_client_post:
litellm.set_verbose = True
from openai.types.chat import ChatCompletion
try:
response = litellm.completion(
response = await litellm.acompletion(
model="anthropic.claude-3-sonnet-20240229-v1:0",
messages=[{"role": "user", "content": "What's AWS?"}],
client=client,