diff --git a/litellm/llms/openrouter.py b/litellm/llms/openrouter.py index c1ae146c982..fa21ab61eec 100644 --- a/litellm/llms/openrouter.py +++ b/litellm/llms/openrouter.py @@ -1,4 +1,5 @@ -from typing import List +from typing import List, Dict +import types class OpenrouterConfig(): """ @@ -6,6 +7,24 @@ class OpenrouterConfig(): """ # OpenRouter-only parameters - transforms: List[str] = [] - models: List[str] = [] - route: str = '' + extra_body: Dict[str, List[str]] = { + 'transforms': [] # default transforms to [] + } + + + def __init__(self, + transforms: List[str] = [], + models: List[str] = [], + route: str = '', + ) -> None: + locals_ = locals() + for key, value in locals_.items(): + if key != 'self' and value is not None: + setattr(self.__class__, key, value) + + @classmethod + def get_config(cls): + return {k: v for k, v in cls.__dict__.items() + if not k.startswith('__') + and not isinstance(v, (types.FunctionType, types.BuiltinFunctionType, classmethod, staticmethod)) + and v is not None} \ No newline at end of file diff --git a/litellm/main.py b/litellm/main.py index b7e9ccce222..bb8d8ba8b17 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -52,6 +52,7 @@ from .llms import ( cohere, petals, oobabooga, + openrouter, palm, vertex_ai, maritalk) @@ -1026,14 +1027,17 @@ def completion( } ) + ## Load Config + config = openrouter.OpenrouterConfig.get_config() + for k, v in config.items(): + if k not in optional_params: # completion(top_k=3) > anthropic_config(top_k=3) <- allows for dynamic variables to be passed in + optional_params[k] = v + data = { "model": model, "messages": messages, **optional_params } - ## LOGGING - logging.pre_call(input=messages, api_key=openai.api_key, additional_args={"complete_input_dict": data, "headers": headers}) - ## COMPLETION CALL ## COMPLETION CALL response = openai_chat_completions.completion(