Update app.py
Browse files
app.py
CHANGED
|
@@ -353,10 +353,6 @@ def summarize_web_results(query: str, search_results: List[Dict[str, str]], conv
|
|
| 353 |
except Exception as e:
|
| 354 |
return f"An error occurred during summarization: {str(e)}"
|
| 355 |
|
| 356 |
-
|
| 357 |
-
import os
|
| 358 |
-
import google.generativeai as genai
|
| 359 |
-
|
| 360 |
def get_response_from_gemini(query, context, file_type, num_calls=1, temperature=0.2):
|
| 361 |
# Configure the Gemini API
|
| 362 |
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
|
|
@@ -388,16 +384,21 @@ def get_response_from_gemini(query, context, file_type, num_calls=1, temperature
|
|
| 388 |
|
| 389 |
full_prompt = f"{system_instruction}\n\nContext:\n{context}\n\nUser query: {query}"
|
| 390 |
|
|
|
|
| 391 |
for _ in range(num_calls):
|
| 392 |
try:
|
| 393 |
# Generate content with streaming enabled
|
| 394 |
response = model.generate_content(full_prompt, stream=True)
|
| 395 |
for chunk in response:
|
| 396 |
if chunk.text:
|
| 397 |
-
|
|
|
|
| 398 |
except Exception as e:
|
| 399 |
yield f"An error occurred with the Gemini model: {str(e)}. Please try again."
|
| 400 |
|
|
|
|
|
|
|
|
|
|
| 401 |
def get_response_from_excel(query, model, context, num_calls=3, temperature=0.2):
|
| 402 |
logging.info(f"Getting response from Excel using model: {model}")
|
| 403 |
|
|
|
|
| 353 |
except Exception as e:
|
| 354 |
return f"An error occurred during summarization: {str(e)}"
|
| 355 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
def get_response_from_gemini(query, context, file_type, num_calls=1, temperature=0.2):
|
| 357 |
# Configure the Gemini API
|
| 358 |
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
|
|
|
|
| 384 |
|
| 385 |
full_prompt = f"{system_instruction}\n\nContext:\n{context}\n\nUser query: {query}"
|
| 386 |
|
| 387 |
+
full_response = ""
|
| 388 |
for _ in range(num_calls):
|
| 389 |
try:
|
| 390 |
# Generate content with streaming enabled
|
| 391 |
response = model.generate_content(full_prompt, stream=True)
|
| 392 |
for chunk in response:
|
| 393 |
if chunk.text:
|
| 394 |
+
full_response += chunk.text
|
| 395 |
+
yield full_response # Yield the accumulated response so far
|
| 396 |
except Exception as e:
|
| 397 |
yield f"An error occurred with the Gemini model: {str(e)}. Please try again."
|
| 398 |
|
| 399 |
+
if not full_response:
|
| 400 |
+
yield "No response generated from the Gemini model."
|
| 401 |
+
|
| 402 |
def get_response_from_excel(query, model, context, num_calls=3, temperature=0.2):
|
| 403 |
logging.info(f"Getting response from Excel using model: {model}")
|
| 404 |
|