aiohttp_openai/ fixes - allow using aiohttp_openai/gpt-4o (#7598)

* fixes for get_complete_url

* update aiohttp tests

* fix event loop for aiohtto

* ci/cd run again

* test_aiohttp_openai
This commit is contained in:
Ishaan Jaff 2025-01-06 21:39:11 -08:00 committed by GitHub
parent 744beac754
commit 2ca0977921
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 106 additions and 61 deletions

View file

@ -9,7 +9,7 @@ New config to ensure we introduce this without causing breaking changes for user
from typing import TYPE_CHECKING, Any, List, Optional
import httpx
from aiohttp import ClientResponse
from litellm.llms.openai_like.chat.transformation import OpenAILikeChatConfig
from litellm.types.llms.openai import AllMessageValues
@ -24,6 +24,22 @@ else:
class AiohttpOpenAIChatConfig(OpenAILikeChatConfig):
def get_complete_url(
self,
api_base: str,
model: str,
optional_params: dict,
stream: Optional[bool] = None,
) -> str:
"""
Ensure - /v1/chat/completions is at the end of the url
"""
if not api_base.endswith("/chat/completions"):
api_base += "/chat/completions"
return api_base
def validate_environment(
self,
headers: dict,
@ -33,12 +49,12 @@ class AiohttpOpenAIChatConfig(OpenAILikeChatConfig):
api_key: Optional[str] = None,
api_base: Optional[str] = None,
) -> dict:
return {}
return {"Authorization": f"Bearer {api_key}"}
def transform_response(
async def transform_response( # type: ignore
self,
model: str,
raw_response: httpx.Response,
raw_response: ClientResponse,
model_response: ModelResponse,
logging_obj: LiteLLMLoggingObj,
request_data: dict,
@ -49,4 +65,5 @@ class AiohttpOpenAIChatConfig(OpenAILikeChatConfig):
api_key: Optional[str] = None,
json_mode: Optional[bool] = None,
) -> ModelResponse:
return ModelResponse(**raw_response.json())
_json_response = await raw_response.json()
return ModelResponse(**_json_response)