Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -160,41 +160,41 @@ class BasicAgent:
|
|
160 |
|
161 |
|
162 |
|
163 |
-
def _formulate_direct_answer(self, relevant_info, question):
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
|
199 |
|
200 |
|
|
|
160 |
|
161 |
|
162 |
|
163 |
+
def _formulate_direct_answer(self, relevant_info, question):
|
164 |
+
if self.model and self.model.startswith('gemini'):
|
165 |
+
try:
|
166 |
+
# Configure the model
|
167 |
+
generation_config = {
|
168 |
+
"temperature": 0.7,
|
169 |
+
"top_p": 0.95,
|
170 |
+
"top_k": 40,
|
171 |
+
"max_output_tokens": 1024,
|
172 |
+
}
|
173 |
+
|
174 |
+
safety_settings = {
|
175 |
+
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
|
176 |
+
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
|
177 |
+
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
|
178 |
+
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
|
179 |
+
}
|
180 |
+
|
181 |
+
# Initialize the model
|
182 |
+
model = genai.GenerativeModel(
|
183 |
+
model_name="gemini-pro", # Adjust as needed based on your model string
|
184 |
+
generation_config=generation_config,
|
185 |
+
safety_settings=safety_settings
|
186 |
+
)
|
187 |
+
|
188 |
+
# Prepare prompt and generate response
|
189 |
+
prompt = f"Question: {question}\n\nRelevant information: {relevant_info}\n\nProvide a concise answer based only on the given information."
|
190 |
+
response = model.generate_content(prompt)
|
191 |
+
return response.text
|
192 |
+
|
193 |
+
except Exception as e:
|
194 |
+
print(f"Error using Gemini model: {e}")
|
195 |
+
return f"Based on the search: {relevant_info}"
|
196 |
+
|
197 |
+
return relevant_info
|
198 |
|
199 |
|
200 |
|