Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit b397a2b

Browse files
committed
fix: override translate method to return ChatCompletionRequest
Closes: #187
1 parent d666bb6 commit b397a2b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/codegate/providers/anthropic/adapter.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
from litellm.adapters.anthropic_adapter import (
23
AnthropicAdapter as LitellmAnthropicAdapter,
34
)
@@ -6,6 +7,22 @@
67
LiteLLMAdapterInputNormalizer,
78
LiteLLMAdapterOutputNormalizer,
89
)
10+
import litellm
11+
from litellm import ChatCompletionRequest
12+
from litellm.types.llms.anthropic import (
13+
AnthropicMessagesRequest,
14+
)
15+
16+
17+
class AnthropicAdapter(LitellmAnthropicAdapter):
18+
def __init__(self) -> None:
19+
super().__init__()
20+
21+
def translate_completion_input_params(self, kwargs) -> Optional[ChatCompletionRequest]:
22+
request_body = AnthropicMessagesRequest(**kwargs) # type: ignore
23+
translated_body = litellm.AnthropicExperimentalPassThroughConfig()\
24+
.translate_anthropic_to_openai(anthropic_message_request=request_body)
25+
return translated_body
926

1027

1128
class AnthropicInputNormalizer(LiteLLMAdapterInputNormalizer):
@@ -16,7 +33,8 @@ class AnthropicInputNormalizer(LiteLLMAdapterInputNormalizer):
1633
"""
1734

1835
def __init__(self):
19-
super().__init__(LitellmAnthropicAdapter())
36+
self.adapter = AnthropicAdapter()
37+
super().__init__(self.adapter)
2038

2139

2240
class AnthropicOutputNormalizer(LiteLLMAdapterOutputNormalizer):

0 commit comments

Comments
 (0)