Update app.py
Browse files
app.py
CHANGED
|
@@ -129,6 +129,22 @@ class PollinationsModel:
|
|
| 129 |
except Exception as e:
|
| 130 |
logger.exception(f"PollinationsModel generate failed: {e}")
|
| 131 |
return f"Error generating response: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
logger.info(f"Initializing Pollinations LLM connection: {MODEL_ID}")
|
| 134 |
try:
|
|
|
|
| 129 |
except Exception as e:
|
| 130 |
logger.exception(f"PollinationsModel generate failed: {e}")
|
| 131 |
return f"Error generating response: {str(e)}"
|
| 132 |
+
|
| 133 |
+
def __call__(self, prompt=None, messages=None, **kwargs):
|
| 134 |
+
"""Make the model callable as required by smolagents CodeAgent."""
|
| 135 |
+
# Determine content to send based on what's provided
|
| 136 |
+
if messages:
|
| 137 |
+
# If we have chat messages, extract content from the last one
|
| 138 |
+
content = messages[-1].get("content", "") if messages else ""
|
| 139 |
+
else:
|
| 140 |
+
content = prompt or ""
|
| 141 |
+
|
| 142 |
+
# Generate the response
|
| 143 |
+
response_text = self.generate(content, **kwargs)
|
| 144 |
+
|
| 145 |
+
# Return in a format similar to OpenAI API responses
|
| 146 |
+
return {"choices": [{"message": {"content": response_text}}]}
|
| 147 |
+
|
| 148 |
|
| 149 |
logger.info(f"Initializing Pollinations LLM connection: {MODEL_ID}")
|
| 150 |
try:
|