Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ litellm/proxy/google-cloud-sdk/*
tests/llm_translation/log.txt
venv/
tests/local_testing/log.txt

.codegpt
55 changes: 21 additions & 34 deletions litellm/llms/custom_httpx/aiohttp_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

class BaseLLMAIOHTTPHandler:

def __init__(self):
self.client_session: Optional[aiohttp.ClientSession] = None

async def _make_common_async_call(
self,
async_httpx_client: AsyncHTTPHandler,
Expand All @@ -52,21 +55,23 @@ async def _make_common_async_call(
)
)

async with aiohttp.ClientSession(timeout=timeout_obj) as session:
for i in range(max(max_retry_on_unprocessable_entity_error, 1)):
try:
response = await session.post(
url=api_base,
headers=headers,
json=data,
)
if not response.ok:
response.raise_for_status()
except aiohttp.ClientResponseError as e:
raise self._handle_error(e=e, provider_config=provider_config)
except Exception as e:
raise self._handle_error(e=e, provider_config=provider_config)
break
if self.client_session is None:
self.client_session = aiohttp.ClientSession()

for i in range(max(max_retry_on_unprocessable_entity_error, 1)):
try:
response = await self.client_session.post(
url=api_base,
headers=headers,
json=data,
)
if not response.ok:
response.raise_for_status()
except aiohttp.ClientResponseError as e:
raise self._handle_error(e=e, provider_config=provider_config)
except Exception as e:
raise self._handle_error(e=e, provider_config=provider_config)
break

if response is None:
raise provider_config.get_error_class(
Expand Down Expand Up @@ -168,25 +173,7 @@ async def async_completion(
)
_json_response = await _response.json()

# cast to httpx.Response
# Todo - use this until we migrate fully to aiohttp
response = httpx.Response(
status_code=_response.status,
headers=_response.headers,
json=_json_response,
)
return provider_config.transform_response(
model=model,
raw_response=response,
model_response=model_response,
logging_obj=logging_obj,
api_key=api_key,
request_data=data,
messages=messages,
optional_params=optional_params,
litellm_params=litellm_params,
encoding=encoding,
)
return _json_response

def completion(
self,
Expand Down
4 changes: 2 additions & 2 deletions litellm/proxy/proxy_config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
model_list:
- model_name: "fake-openai-endpoint"
litellm_params:
model: openai/any
api_base: https://exampleopenaiendpoint-production.up.railway.app
model: aiohttp_openai/any
api_base: https://example-openai-endpoint.onrender.com/chat/completions
api_key: "ishaan"

general_settings:
Expand Down