#!/usr/bin/env python3 """Test generation to see where it hangs""" import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import asyncio from datetime import datetime import json import httpx # Gemini API Configuration GEMINI_API_KEY = "AIzaSyCqe3vjvPlo1lt_hpQ4nqAC0-_1omva1oc" GEMINI_ENDPOINT = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent" async def test_gemini(): """Test Gemini API call""" print("Testing Gemini API...") prompt = "Say hello in 5 words" headers = { "Content-Type": "application/json" } data = { "contents": [{ "parts": [{ "text": prompt }] }], "generationConfig": { "temperature": 0.7, "topK": 40, "topP": 0.95, "maxOutputTokens": 100, }, "safetySettings": [ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"}, {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"}, {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"}, {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"} ] } print(f"Calling Gemini at: {GEMINI_ENDPOINT}") try: async with httpx.AsyncClient(timeout=30.0) as client: response = await client.post( f"{GEMINI_ENDPOINT}?key={GEMINI_API_KEY}", headers=headers, json=data ) print(f"Response status: {response.status_code}") if response.status_code == 200: result = response.json() print(f"Full response: {json.dumps(result, indent=2)}") if 'candidates' in result and len(result['candidates']) > 0: candidate = result['candidates'][0] if 'content' in candidate and 'parts' in candidate['content']: text = candidate['content']['parts'][0]['text'] print(f"Extracted text: {text}") else: print(f"No content/parts in candidate: {candidate}") else: print(f"No candidates in result") else: print(f"Error: {response.text}") except Exception as e: print(f"Exception: {e}") if __name__ == "__main__": asyncio.run(test_gemini())