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

Commit 1303e8e

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

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/codegate/providers/anthropic/adapter.py

Lines changed: 20 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,23 @@
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().translate_anthropic_to_openai(
24+
anthropic_message_request=request_body
25+
)
26+
return translated_body
927

1028

1129
class AnthropicInputNormalizer(LiteLLMAdapterInputNormalizer):
@@ -16,7 +34,8 @@ class AnthropicInputNormalizer(LiteLLMAdapterInputNormalizer):
1634
"""
1735

1836
def __init__(self):
19-
super().__init__(LitellmAnthropicAdapter())
37+
self.adapter = AnthropicAdapter()
38+
super().__init__(self.adapter)
2039

2140

2241
class AnthropicOutputNormalizer(LiteLLMAdapterOutputNormalizer):

0 commit comments

Comments
 (0)