Spaces:
Running
Running
girishwangikar
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -18,19 +18,22 @@ class GroqLLM:
|
|
18 |
self.client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
19 |
self.model_name = model_name
|
20 |
|
21 |
-
def __call__(self, prompt: str) -> str:
|
22 |
"""Make the class callable as required by smolagents"""
|
23 |
-
# Ensure the prompt is a string
|
24 |
-
if not isinstance(prompt, str):
|
25 |
-
return "Error: Prompt must be a string"
|
26 |
-
|
27 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
# Create a properly formatted message
|
29 |
completion = self.client.chat.completions.create(
|
30 |
model=self.model_name,
|
31 |
messages=[{
|
32 |
"role": "user",
|
33 |
-
"content":
|
34 |
}],
|
35 |
temperature=0.7,
|
36 |
max_tokens=1024,
|
|
|
18 |
self.client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
19 |
self.model_name = model_name
|
20 |
|
21 |
+
def __call__(self, prompt: Union[str, dict, List[Dict]]) -> str:
|
22 |
"""Make the class callable as required by smolagents"""
|
|
|
|
|
|
|
|
|
23 |
try:
|
24 |
+
# Handle different prompt formats
|
25 |
+
if isinstance(prompt, (dict, list)):
|
26 |
+
# If prompt is a dictionary or list, convert it to a string representation
|
27 |
+
prompt_str = str(prompt)
|
28 |
+
else:
|
29 |
+
prompt_str = str(prompt)
|
30 |
+
|
31 |
# Create a properly formatted message
|
32 |
completion = self.client.chat.completions.create(
|
33 |
model=self.model_name,
|
34 |
messages=[{
|
35 |
"role": "user",
|
36 |
+
"content": prompt_str
|
37 |
}],
|
38 |
temperature=0.7,
|
39 |
max_tokens=1024,
|