Update api.py
Browse files
api.py
CHANGED
|
@@ -25,7 +25,6 @@ except ImportError as e:
|
|
| 25 |
|
| 26 |
|
| 27 |
import google.generativeai as genai
|
| 28 |
-
from google.generativeai.types import GenerationConfig, Content, Part # Corrected import path
|
| 29 |
|
| 30 |
# Configure logging for the API
|
| 31 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
@@ -97,13 +96,9 @@ async def lifespan(app: FastAPI):
|
|
| 97 |
if not api_key:
|
| 98 |
raise ValueError("GEMINI_API_KEY not found in environment or settings.")
|
| 99 |
genai.configure(api_key=api_key)
|
| 100 |
-
# Optionally, you could create a specific model instance here if needed frequently
|
| 101 |
-
# gemini_client = genai.GenerativeModel(...)
|
| 102 |
logger.info("Gemini client configured successfully.")
|
| 103 |
except Exception as e:
|
| 104 |
logger.error(f"Failed to configure Gemini client: {e}", exc_info=True)
|
| 105 |
-
# Decide if the app should fail to start or just log the error
|
| 106 |
-
# gemini_client will remain None, endpoints using it will fail
|
| 107 |
else:
|
| 108 |
logger.warning("Gemini library not imported. Endpoints requiring Gemini will not work.")
|
| 109 |
|
|
@@ -276,21 +271,10 @@ async def evaluation(request: SpecificityEvaluationRequest):
|
|
| 276 |
try:
|
| 277 |
logger.info("Calling Gemini API to generate problematic...")
|
| 278 |
# Use the specified model and configuration
|
| 279 |
-
model_name = "gemini-
|
| 280 |
model = genai.GenerativeModel(model_name)
|
| 281 |
|
| 282 |
-
|
| 283 |
-
contents = [Content(role="user", parts=[Part.from_text(text=prompt)])]
|
| 284 |
-
|
| 285 |
-
# Define generation config
|
| 286 |
-
generate_config = GenerationConfig(response_mime_type="text/plain") # Updated parameter name
|
| 287 |
-
|
| 288 |
-
# Make the API call
|
| 289 |
-
response = await model.generate_content_async(
|
| 290 |
-
contents=contents,
|
| 291 |
-
generation_config=generate_config # Pass config object
|
| 292 |
-
)
|
| 293 |
-
|
| 294 |
# Extract the result
|
| 295 |
problematic_result = response.text.strip()
|
| 296 |
logger.info("Successfully generated problematic from Gemini.")
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
import google.generativeai as genai
|
|
|
|
| 28 |
|
| 29 |
# Configure logging for the API
|
| 30 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
|
|
| 96 |
if not api_key:
|
| 97 |
raise ValueError("GEMINI_API_KEY not found in environment or settings.")
|
| 98 |
genai.configure(api_key=api_key)
|
|
|
|
|
|
|
| 99 |
logger.info("Gemini client configured successfully.")
|
| 100 |
except Exception as e:
|
| 101 |
logger.error(f"Failed to configure Gemini client: {e}", exc_info=True)
|
|
|
|
|
|
|
| 102 |
else:
|
| 103 |
logger.warning("Gemini library not imported. Endpoints requiring Gemini will not work.")
|
| 104 |
|
|
|
|
| 271 |
try:
|
| 272 |
logger.info("Calling Gemini API to generate problematic...")
|
| 273 |
# Use the specified model and configuration
|
| 274 |
+
model_name = "gemini-2.5-flash-preview-04-17"
|
| 275 |
model = genai.GenerativeModel(model_name)
|
| 276 |
|
| 277 |
+
response = model.generate_content(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
# Extract the result
|
| 279 |
problematic_result = response.text.strip()
|
| 280 |
logger.info("Successfully generated problematic from Gemini.")
|