diff --git a/lib.py b/lib.py index f20da31..0b1fc07 100644 --- a/lib.py +++ b/lib.py @@ -4,6 +4,8 @@ This module provides functionality to generate content using Google's Gemini mod with Vertex AI RAG (Retrieval-Augmented Generation) support. """ +from llm_config import generate_content_config +import logging import asyncio import json import os @@ -13,7 +15,8 @@ from google.genai import types from google.oauth2 import service_account from dotenv import load_dotenv -from llm_config import generate_content_config +logger = logging.getLogger(__name__) + # Load environment variables from .env file load_dotenv() @@ -31,9 +34,14 @@ def get_credentials(): """ # Try to load credentials from JSON content directly credentials_json = os.getenv("GOOGLE_CREDENTIALS_JSON") + + logger.info(f"creds JSON: {credentials_json}") + if credentials_json: try: credentials_info = json.loads(credentials_json) + logger.info(f"creds JSON parsed: {credentials_info}") + return service_account.Credentials.from_service_account_info( credentials_info ) @@ -42,6 +50,9 @@ def get_credentials(): # Fall back to file-based credentials (standard behavior) credentials_path = os.getenv("GOOGLE_APPLICATION_CREDENTIALS") + + logger.info(f"creds path: {credentials_path}") + if credentials_path and os.path.exists(credentials_path): return service_account.Credentials.from_service_account_file( credentials_path @@ -79,6 +90,9 @@ async def generate(prompt: str): """Run the synchronous streaming in a separate thread.""" try: credentials = get_credentials() + + logger.info(f"credentials: {credentials}") + client = genai.Client(vertexai=True, credentials=credentials) contents = [