import os
import google.generativeai as genai
import requests
import json
genai.configure(api_key=“GEMINI_API_KEY”)
vectara_url = “https://api.vectara.io/v2/corpora/mmmm/query”
vectara_headers = {
‘Accept’: ‘application/json’,
‘x-api-key’: ‘VECTARA_API_KEY’,
‘Content-Type’: ‘application/json’
}
generation_config = {
“temperature”: 0.05,
“top_p”: 0.95,
“top_k”: 64,
“max_output_tokens”: 8192,
“response_mime_type”: “text/plain”,
}
model = genai.GenerativeModel(
model_name=“gemini-1.5-flash”,
generation_config=generation_config,
)
chat_session = model.start_chat(history=)
query_text = “What is the gap between what people think is going on and what is actually going on?”
vectara_payload = {
“query”: query_text
}
try:
vectara_response = requests.post(vectara_url, headers=vectara_headers, json=vectara_payload)
vectara_response.raise_for_status()
vectara_data = vectara_response.json()
extracted_texts = []
if 'results' in vectara_data:
for result in vectara_data['results']:
snippet = result.get('snippet')
if snippet:
extracted_texts.append(snippet)
combined_text = " ".join(extracted_texts).strip()
if combined_text:
print(f"Combined Text for Gemini: {combined_text}")
gemini_response = chat_session.send_message(combined_text)
gemini_response_text = gemini_response.text
print(f"Gemini Response: {gemini_response_text}")
else:
print("No valid text extracted from Vectara. Cannot send to Gemini.")
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")