mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
feat(anthropic_adapter.py): support for translating anthropic params to openai format
This commit is contained in:
parent
059a161c28
commit
01a335b4c3
10 changed files with 542 additions and 4213 deletions
|
@ -48,6 +48,7 @@ from litellm import ( # type: ignore
|
|||
get_litellm_params,
|
||||
get_optional_params,
|
||||
)
|
||||
from litellm.integrations.custom_logger import CustomLogger
|
||||
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
|
||||
from litellm.utils import (
|
||||
CustomStreamWrapper,
|
||||
|
@ -3943,6 +3944,33 @@ def text_completion(
|
|||
return text_completion_response
|
||||
|
||||
|
||||
###### Adapter Completion ################
|
||||
|
||||
|
||||
def adapter_completion(*, adapter_id: str, **kwargs) -> Any:
|
||||
translation_obj: Optional[CustomLogger] = None
|
||||
for item in litellm.adapters:
|
||||
if item["id"] == adapter_id:
|
||||
translation_obj = item["adapter"]
|
||||
|
||||
if translation_obj is None:
|
||||
raise ValueError(
|
||||
"No matching adapter given. Received 'adapter_id'={}, litellm.adapters={}".format(
|
||||
adapter_id, litellm.adapters
|
||||
)
|
||||
)
|
||||
|
||||
new_kwargs = translation_obj.translate_completion_input_params(kwargs=kwargs)
|
||||
|
||||
response: ModelResponse = completion(**new_kwargs) # type: ignore
|
||||
|
||||
translated_response = translation_obj.translate_completion_output_params(
|
||||
response=response
|
||||
)
|
||||
|
||||
return translated_response
|
||||
|
||||
|
||||
##### Moderation #######################
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue