Skip to content

Commit fbec5dd

Browse files
committed
fix
1 parent 7f4f38c commit fbec5dd

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

optillm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ def proxy_models():
726726
models_response = client.models.list()
727727

728728
logger.debug('Models retrieved successfully')
729-
return models_response.model_dump(), 200
729+
return models_response, 200
730730
except Exception as e:
731731
logger.error(f"Error fetching models: {str(e)}")
732732
return jsonify({"error": f"Error fetching models: {str(e)}"}), 500

optillm/inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def _load_model():
575575
logger.info(f"Using device: {device}")
576576

577577
# Load tokenizer
578-
tokenizer = AutoTokenizer.from_pretrained(model_id)
578+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
579579

580580
# Base kwargs for model loading
581581
model_kwargs = {
@@ -1545,7 +1545,7 @@ def list(self):
15451545
try:
15461546
import requests
15471547
response = requests.get(
1548-
"https://huggingface.co/api/models?sort=downloads&direction=-1&limit=100"
1548+
"https://huggingface.co/api/models?sort=downloads&direction=-1&filter=text-generation&limit=20"
15491549
)
15501550
models = response.json()
15511551
model_list = []

optillm/litellm_wrapper.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import os
2+
import time
23
import litellm
34
from litellm import completion
5+
from litellm.utils import get_valid_models
46
from typing import List, Dict, Any, Optional
57

8+
# Configure litellm to drop unsupported parameters
9+
litellm.drop_params = True
10+
611
SAFETY_SETTINGS = [
712
{"category": cat, "threshold": "BLOCK_NONE"}
813
for cat in [
@@ -36,16 +41,36 @@ def create(model: str, messages: List[Dict[str, str]], **kwargs):
3641
class Models:
3742
@staticmethod
3843
def list():
39-
# Since LiteLLM doesn't have a direct method to list models,
40-
# we'll return a predefined list of supported models.
41-
# This list can be expanded as needed.
42-
return {
43-
"data": [
44-
{"id": "gpt-4o-mini"},
45-
{"id": "gpt-4o"},
46-
{"id": "command-nightly"},
47-
# Add more models as needed
48-
]
49-
}
50-
44+
try:
45+
# Get all valid models from LiteLLM
46+
valid_models = get_valid_models()
47+
48+
# Format the response to match OpenAI's API format
49+
model_list = []
50+
for model in valid_models:
51+
model_list.append({
52+
"id": model,
53+
"object": "model",
54+
"created": int(time.time()),
55+
"owned_by": "litellm"
56+
})
57+
58+
return {
59+
"object": "list",
60+
"data": model_list
61+
}
62+
except Exception as e:
63+
# Fallback to a basic list if there's an error
64+
print(f"Error fetching LiteLLM models: {str(e)}")
65+
return {
66+
"object": "list",
67+
"data": [
68+
{"id": "gpt-4o-mini", "object": "model", "created": int(time.time()), "owned_by": "litellm"},
69+
{"id": "gpt-4o", "object": "model", "created": int(time.time()), "owned_by": "litellm"},
70+
{"id": "command-nightly", "object": "model", "created": int(time.time()), "owned_by": "litellm"},
71+
{"id": "claude-3-opus-20240229", "object": "model", "created": int(time.time()), "owned_by": "litellm"},
72+
{"id": "claude-3-sonnet-20240229", "object": "model", "created": int(time.time()), "owned_by": "litellm"},
73+
{"id": "gemini-1.5-pro-latest", "object": "model", "created": int(time.time()), "owned_by": "litellm"}
74+
]
75+
}
5176
models = Models()

0 commit comments

Comments
 (0)