litellm/litellm/llms/base.py
Mateo Wang fbf539e136
refactor(types): replace Unknown with proven types in 390 files (#53715)
* refactor(types): replace Unknown with proven types in 410 files

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* revert files that added new validation seams

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* revert three overrides that became incompatible

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(types): drop sweep docstrings that restate the helper they sit on

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(types): restore legacy_spend_counters.py to main

The file is code-owned and moves to its own PR

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(types): restore three base transformation files to main after #53774 annotated their overrides

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(types): drop annotations that clash with signatures typed on main

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(otel): lower the Prisma call-site scan floor after main folded team lookups into a helper

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* chore(ui): regenerate dashboard API types after main merge

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(deepseek): pass typed litellm_params to the DeepSeek messages transform

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-24 03:33:11 +00:00

99 lines
3.1 KiB
Python

## This is a template base class to be used for adding new LLM providers via API calls
from collections.abc import Mapping, Sequence
from types import TracebackType
from typing import TYPE_CHECKING, Union
import httpx
import litellm
if TYPE_CHECKING:
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper
from litellm.types.utils import ModelResponse, TextCompletionResponse
class BaseLLM:
_client_session: httpx.Client | None = None
def process_response(
self,
model: str,
response: httpx.Response,
model_response: "ModelResponse",
stream: bool,
logging_obj: "LiteLLMLoggingObj",
optional_params: Mapping[str, object],
api_key: str,
data: Mapping[str, object] | str,
messages: Sequence[object],
print_verbose: object,
encoding: object,
) -> Union["ModelResponse", "CustomStreamWrapper"]:
"""
Helper function to process the response across sync + async completion calls
"""
return model_response
def process_text_completion_response(
self,
model: str,
response: httpx.Response,
model_response: "TextCompletionResponse",
stream: bool,
logging_obj: "LiteLLMLoggingObj",
optional_params: Mapping[str, object],
api_key: str,
data: Mapping[str, object] | str,
messages: Sequence[object],
print_verbose: object,
encoding: object,
) -> Union["TextCompletionResponse", "CustomStreamWrapper"]:
"""
Helper function to process the response across sync + async completion calls
"""
return model_response
def create_client_session(self):
if litellm.client_session:
_client_session = litellm.client_session
else:
_client_session = httpx.Client()
return _client_session
def create_aclient_session(self):
if litellm.aclient_session:
_aclient_session = litellm.aclient_session
else:
_aclient_session = httpx.AsyncClient()
return _aclient_session
def __exit__(self):
if hasattr(self, "_client_session") and self._client_session is not None:
self._client_session.close()
async def __aexit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
):
if hasattr(self, "_aclient_session"):
await self._aclient_session.aclose()
def validate_environment(
self, *args, **kwargs
) -> object | None: # set up the environment required to run the model
return None
def completion(
self, *args, **kwargs
) -> object | None: # logic for parsing in - calling - parsing out model completion calls
return None
def embedding(
self, *args, **kwargs
) -> object | None: # logic for parsing in - calling - parsing out model embedding calls
return None