Skip to content

Commit 664d734

Browse files
committed
feat(python): use router to call litellm
1 parent f443bf4 commit 664d734

File tree

1 file changed

+23
-4
lines changed
  • implementations/python/python/ockam/models

1 file changed

+23
-4
lines changed

implementations/python/python/ockam/models/model.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from typing import List, Optional
22

33
import litellm
4+
from litellm import Router
5+
46
import os
57
import boto3
68
import threading
@@ -40,6 +42,14 @@
4042
"gemma3:27b": "ollama_chat/gemma3:27b",
4143
"nomic-embed-text": "ollama/nomic-embed-text",
4244
},
45+
"ollama_chat": {
46+
"deepseek-r1": "ollama_chat/deepseek-r1",
47+
"llama3.2": "ollama_chat/llama3.2",
48+
"llama3.3": "ollama_chat/llama3.3",
49+
"gemma3": "ollama_chat/gemma3",
50+
"gemma3:27b": "ollama_chat/gemma3:27b",
51+
"nomic-embed-text": "ollama/nomic-embed-text",
52+
},
4353
"bedrock": {
4454
"claude-3-5-haiku-v1": "bedrock/anthropic.claude-3-5-haiku-20241022-v1:0",
4555
"claude-3-5-sonnet-v1": "bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0",
@@ -80,6 +90,16 @@
8090
init_lock = threading.Lock()
8191

8292

93+
# slightly modify the parameters to accommodate services
94+
litellm.modify_params = True
95+
96+
model_list = []
97+
for model_name in ALL_PROVIDER_ALLOWED_FULL_NAMES:
98+
model_list.append({"model_name": model_name, "litellm_params": {"model": model_name}})
99+
100+
router = Router(model_list=model_list, default_max_parallel_requests=400)
101+
102+
83103
def construct_bedrock_arn(model_identifier: str) -> Optional[str]:
84104
global region, account_id, init_lock
85105
with init_lock:
@@ -192,17 +212,16 @@ async def complete_chat(self, messages: List[dict] | List[ConversationMessage],
192212
if "tool_calls" in message:
193213
del message["tool_calls"]
194214

195-
# slightly modify the parameters to accommodate services
196-
litellm.modify_params = True
197-
198215
# parameters provided in kwargs will override the default parameters
199216
kwargs = {**self.kwargs, **kwargs}
200217

201218
# sometimes an empty tools list is interpreted as "please hallucinate tools",
202219
if "tools" in kwargs and len(kwargs["tools"]) == 0:
203220
del kwargs["tools"]
204221

205-
return await litellm.acompletion(self.name, messages=messages, stream=stream, **kwargs)
222+
global router
223+
224+
return await router.acompletion(self.name, messages=messages, stream=stream, **kwargs)
206225

207226
async def embeddings(self, text: List[str], **kwargs) -> List[List[float]]:
208227
# parameters provided in kwargs will override the default parameters

0 commit comments

Comments
 (0)