Update app.py
Browse files
app.py
CHANGED
|
@@ -120,30 +120,31 @@ class PollinationsModel:
|
|
| 120 |
}
|
| 121 |
response = requests.post(self.api_url, json=payload, timeout=120)
|
| 122 |
response.raise_for_status()
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
return result["content"]
|
| 126 |
-
else:
|
| 127 |
-
logger.error(f"Unexpected response structure: {result}")
|
| 128 |
-
return "Error: Unexpected API response format"
|
| 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,
|
| 134 |
"""Make the model callable as required by smolagents CodeAgent."""
|
| 135 |
-
|
| 136 |
-
if messages:
|
| 137 |
-
#
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
| 141 |
|
| 142 |
-
|
| 143 |
-
response_text = self.generate(content, **kwargs)
|
| 144 |
|
| 145 |
-
#
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
|
| 149 |
logger.info(f"Initializing Pollinations LLM connection: {MODEL_ID}")
|
|
|
|
| 120 |
}
|
| 121 |
response = requests.post(self.api_url, json=payload, timeout=120)
|
| 122 |
response.raise_for_status()
|
| 123 |
+
# Die API gibt direkt Text zurück, kein JSON
|
| 124 |
+
return response.text
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
except Exception as e:
|
| 126 |
logger.exception(f"PollinationsModel generate failed: {e}")
|
| 127 |
return f"Error generating response: {str(e)}"
|
| 128 |
|
| 129 |
+
def __call__(self, messages=None, **kwargs):
|
| 130 |
"""Make the model callable as required by smolagents CodeAgent."""
|
| 131 |
+
prompt = ""
|
| 132 |
+
if messages and isinstance(messages, list) and len(messages) > 0:
|
| 133 |
+
# Get content from the last message
|
| 134 |
+
if hasattr(messages[-1], 'content'):
|
| 135 |
+
prompt = messages[-1].content
|
| 136 |
+
elif isinstance(messages[-1], dict) and 'content' in messages[-1]:
|
| 137 |
+
prompt = messages[-1]['content']
|
| 138 |
|
| 139 |
+
response_text = self.generate(prompt)
|
|
|
|
| 140 |
|
| 141 |
+
# Create a response object with the content attribute
|
| 142 |
+
class ChatMessage:
|
| 143 |
+
def __init__(self, content):
|
| 144 |
+
self.content = content
|
| 145 |
+
|
| 146 |
+
return ChatMessage(response_text)
|
| 147 |
+
|
| 148 |
|
| 149 |
|
| 150 |
logger.info(f"Initializing Pollinations LLM connection: {MODEL_ID}")
|