Update model.py
Browse files
model.py
CHANGED
|
@@ -16,9 +16,11 @@ class LiteLLMModel:
|
|
| 16 |
def __init__(self, model_id: str):
|
| 17 |
self.model_id = model_id
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
def generate(self, messages: List[Dict], tools: Optional[List] = None) -> Dict:
|
| 24 |
if not litellm:
|
|
@@ -39,12 +41,13 @@ class LiteLLMModel:
|
|
| 39 |
for tool in tools
|
| 40 |
]
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 44 |
if not api_key:
|
| 45 |
-
raise RuntimeError("
|
| 46 |
|
| 47 |
-
print(f"DEBUG: Using model
|
| 48 |
|
| 49 |
response = litellm.completion(
|
| 50 |
model=self.model_id,
|
|
@@ -54,6 +57,7 @@ class LiteLLMModel:
|
|
| 54 |
temperature=0.1
|
| 55 |
)
|
| 56 |
else:
|
|
|
|
| 57 |
response = litellm.completion(
|
| 58 |
model=self.model_id,
|
| 59 |
messages=messages,
|
|
|
|
| 16 |
def __init__(self, model_id: str):
|
| 17 |
self.model_id = model_id
|
| 18 |
|
| 19 |
+
# Check for Groq API key
|
| 20 |
+
if "groq" in model_id.lower():
|
| 21 |
+
if not os.getenv("GROQ_API_KEY"):
|
| 22 |
+
print("⚠️ GROQ_API_KEY not set in environment")
|
| 23 |
+
raise RuntimeError("GROQ_API_KEY not set. Please add it to your Space secrets.")
|
| 24 |
|
| 25 |
def generate(self, messages: List[Dict], tools: Optional[List] = None) -> Dict:
|
| 26 |
if not litellm:
|
|
|
|
| 41 |
for tool in tools
|
| 42 |
]
|
| 43 |
|
| 44 |
+
# Groq configuration
|
| 45 |
+
if "groq" in self.model_id.lower():
|
| 46 |
+
api_key = os.getenv("GROQ_API_KEY")
|
| 47 |
if not api_key:
|
| 48 |
+
raise RuntimeError("GROQ_API_KEY not set in environment")
|
| 49 |
|
| 50 |
+
print(f"DEBUG: Using Groq model: {self.model_id}")
|
| 51 |
|
| 52 |
response = litellm.completion(
|
| 53 |
model=self.model_id,
|
|
|
|
| 57 |
temperature=0.1
|
| 58 |
)
|
| 59 |
else:
|
| 60 |
+
# Generic model support
|
| 61 |
response = litellm.completion(
|
| 62 |
model=self.model_id,
|
| 63 |
messages=messages,
|