pmeyhoefer commited on
Commit
35a1002
·
verified ·
1 Parent(s): f8f7684

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
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
- result = response.json()
124
- if "content" in result:
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, 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}")
 
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}")