mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
* build: merge branch * test: fix openai naming * fix(main.py): fix openai renaming * style: ignore function length for config factory * fix(sagemaker/): fix routing logic * fix: fix imports * fix: fix override
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""
|
|
Support for OpenAI's `/v1/chat/completions` endpoint.
|
|
|
|
Calls done in OpenAI/openai.py as OpenRouter is openai-compatible.
|
|
|
|
Docs: https://openrouter.ai/docs/parameters
|
|
"""
|
|
|
|
from typing import Optional
|
|
|
|
from litellm import get_model_info, verbose_logger
|
|
|
|
from ...openai.chat.gpt_transformation import OpenAIGPTConfig
|
|
|
|
|
|
class OpenrouterConfig(OpenAIGPTConfig):
|
|
|
|
def map_openai_params(
|
|
self,
|
|
non_default_params: dict,
|
|
optional_params: dict,
|
|
model: str,
|
|
drop_params: bool,
|
|
) -> dict:
|
|
mapped_openai_params = super().map_openai_params(
|
|
non_default_params, optional_params, model, drop_params
|
|
)
|
|
|
|
# OpenRouter-only parameters
|
|
extra_body = {}
|
|
transforms = non_default_params.pop("transforms", None)
|
|
models = non_default_params.pop("models", None)
|
|
route = non_default_params.pop("route", None)
|
|
if transforms is not None:
|
|
extra_body["transforms"] = transforms
|
|
if models is not None:
|
|
extra_body["models"] = models
|
|
if route is not None:
|
|
extra_body["route"] = route
|
|
mapped_openai_params["extra_body"] = (
|
|
extra_body # openai client supports `extra_body` param
|
|
)
|
|
return mapped_openai_params
|