mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
feat - add fireworks ai config for param mapping
This commit is contained in:
parent
f9407aaefc
commit
493a737787
2 changed files with 131 additions and 0 deletions
107
litellm/llms/fireworks_ai.py
Normal file
107
litellm/llms/fireworks_ai.py
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
import types
|
||||||
|
from typing import Literal, Optional, Union
|
||||||
|
|
||||||
|
import litellm
|
||||||
|
|
||||||
|
|
||||||
|
class FireworksAIConfig:
|
||||||
|
"""
|
||||||
|
Reference: https://docs.fireworks.ai/api-reference/post-chatcompletions
|
||||||
|
|
||||||
|
The class `FireworksAIConfig` provides configuration for the Fireworks's Chat Completions API interface. Below are the parameters:
|
||||||
|
"""
|
||||||
|
|
||||||
|
tools: Optional[list] = None
|
||||||
|
tool_choice: Optional[Union[str, dict]] = None
|
||||||
|
max_tokens: Optional[int] = None
|
||||||
|
temperature: Optional[int] = None
|
||||||
|
top_p: Optional[int] = None
|
||||||
|
top_k: Optional[int] = None
|
||||||
|
frequency_penalty: Optional[int] = None
|
||||||
|
presence_penalty: Optional[int] = None
|
||||||
|
n: Optional[int] = None
|
||||||
|
stop: Optional[Union[str, list]] = None
|
||||||
|
response_format: Optional[dict] = None
|
||||||
|
user: Optional[str] = None
|
||||||
|
|
||||||
|
# Non OpenAI parameters - Fireworks AI only params
|
||||||
|
prompt_truncate_length: Optional[int] = None
|
||||||
|
context_length_exceeded_behavior: Optional[Literal["error", "truncate"]] = None
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
tools: Optional[list] = None,
|
||||||
|
tool_choice: Optional[Union[str, dict]] = None,
|
||||||
|
max_tokens: Optional[int] = None,
|
||||||
|
temperature: Optional[int] = None,
|
||||||
|
top_p: Optional[int] = None,
|
||||||
|
top_k: Optional[int] = None,
|
||||||
|
frequency_penalty: Optional[int] = None,
|
||||||
|
presence_penalty: Optional[int] = None,
|
||||||
|
n: Optional[int] = None,
|
||||||
|
stop: Optional[Union[str, list]] = None,
|
||||||
|
response_format: Optional[dict] = None,
|
||||||
|
user: Optional[str] = None,
|
||||||
|
prompt_truncate_length: Optional[int] = None,
|
||||||
|
context_length_exceeded_behavior: Optional[Literal["error", "truncate"]] = None,
|
||||||
|
) -> None:
|
||||||
|
locals_ = locals().copy()
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_supported_openai_params(self):
|
||||||
|
return [
|
||||||
|
"stream",
|
||||||
|
"tools",
|
||||||
|
"tool_choice",
|
||||||
|
"max_tokens",
|
||||||
|
"temperature",
|
||||||
|
"top_p",
|
||||||
|
"top_k",
|
||||||
|
"frequency_penalty",
|
||||||
|
"presence_penalty",
|
||||||
|
"n",
|
||||||
|
"stop",
|
||||||
|
"response_format",
|
||||||
|
"user",
|
||||||
|
"prompt_truncate_length",
|
||||||
|
"context_length_exceeded_behavior",
|
||||||
|
]
|
||||||
|
|
||||||
|
def map_openai_params(
|
||||||
|
self,
|
||||||
|
non_default_params: dict,
|
||||||
|
optional_params: dict,
|
||||||
|
model: str,
|
||||||
|
drop_params: bool,
|
||||||
|
) -> dict:
|
||||||
|
supported_openai_params = self.get_supported_openai_params()
|
||||||
|
for param, value in non_default_params.items():
|
||||||
|
if param == "tool_choice":
|
||||||
|
if value == "required":
|
||||||
|
# relevant issue: https://github.com/BerriAI/litellm/issues/4416
|
||||||
|
optional_params["tools"] = "any"
|
||||||
|
|
||||||
|
if param in supported_openai_params:
|
||||||
|
if value is not None:
|
||||||
|
optional_params[param] = value
|
||||||
|
return optional_params
|
|
@ -2073,6 +2073,30 @@
|
||||||
"supports_function_calling": true,
|
"supports_function_calling": true,
|
||||||
"supports_vision": true
|
"supports_vision": true
|
||||||
},
|
},
|
||||||
|
"openrouter/anthropic/claude-3-haiku-20240307": {
|
||||||
|
"max_tokens": 4096,
|
||||||
|
"max_input_tokens": 200000,
|
||||||
|
"max_output_tokens": 4096,
|
||||||
|
"input_cost_per_token": 0.00000025,
|
||||||
|
"output_cost_per_token": 0.00000125,
|
||||||
|
"litellm_provider": "openrouter",
|
||||||
|
"mode": "chat",
|
||||||
|
"supports_function_calling": true,
|
||||||
|
"supports_vision": true,
|
||||||
|
"tool_use_system_prompt_tokens": 264
|
||||||
|
},
|
||||||
|
"openrouter/anthropic/claude-3.5-sonnet": {
|
||||||
|
"max_tokens": 4096,
|
||||||
|
"max_input_tokens": 200000,
|
||||||
|
"max_output_tokens": 4096,
|
||||||
|
"input_cost_per_token": 0.000003,
|
||||||
|
"output_cost_per_token": 0.000015,
|
||||||
|
"litellm_provider": "openrouter",
|
||||||
|
"mode": "chat",
|
||||||
|
"supports_function_calling": true,
|
||||||
|
"supports_vision": true,
|
||||||
|
"tool_use_system_prompt_tokens": 159
|
||||||
|
},
|
||||||
"openrouter/anthropic/claude-3-sonnet": {
|
"openrouter/anthropic/claude-3-sonnet": {
|
||||||
"max_tokens": 200000,
|
"max_tokens": 200000,
|
||||||
"input_cost_per_token": 0.000003,
|
"input_cost_per_token": 0.000003,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue