Sidreds06 commited on
Commit
81c40fc
·
1 Parent(s): 0b508b2
backend/cache_utils.py CHANGED
@@ -1,7 +1,8 @@
1
  import time
2
  from typing import Dict, Any, Optional
3
 
4
- from backend.config import setup_google_credentials
 
5
  setup_google_credentials()
6
 
7
  # Simple in-memory cache
 
1
  import time
2
  from typing import Dict, Any, Optional
3
 
4
+
5
+ from backend.credentials import setup_google_credentials
6
  setup_google_credentials()
7
 
8
  # Simple in-memory cache
backend/config.py CHANGED
@@ -5,8 +5,8 @@ from tools.goal_tools import add_goal_tool, list_goal_categories
5
 
6
  load_dotenv()
7
 
8
- from server import setup_google_credentials
9
 
 
10
  setup_google_credentials()
11
 
12
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
 
5
 
6
  load_dotenv()
7
 
 
8
 
9
+ from backend.credentials import setup_google_credentials
10
  setup_google_credentials()
11
 
12
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
backend/credentials.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import tempfile
3
+ import os
4
+
5
+ def setup_google_credentials():
6
+ creds_json = os.getenv("GOOGLE_APPLICATION_CREDENTIALS_JSON")
7
+ if creds_json:
8
+ # Create temporary JSON file from environment variable
9
+ tmp_path = tempfile.NamedTemporaryFile(delete=False, suffix=".json").name
10
+ with open(tmp_path, "w") as f:
11
+ f.write(creds_json)
12
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = tmp_path
13
+ print("[CREDENTIALS] Using Google Cloud credentials from environment")
14
+ else:
15
+ print("[CREDENTIALS] Using local service account file")
backend/goal_extraction.py CHANGED
@@ -1,7 +1,8 @@
1
  import re
2
  from backend.config import gpt4o
3
 
4
- from backend.config import setup_google_credentials
 
5
  setup_google_credentials()
6
 
7
  async def extract_goal_details(user_message: str, conversation_history: list = None) -> dict:
 
1
  import re
2
  from backend.config import gpt4o
3
 
4
+
5
+ from backend.credentials import setup_google_credentials
6
  setup_google_credentials()
7
 
8
  async def extract_goal_details(user_message: str, conversation_history: list = None) -> dict:
backend/mood_extraction.py CHANGED
@@ -5,7 +5,8 @@ from backend.config import gpt4o
5
 
6
  db = firestore.Client()
7
 
8
- from backend.config import setup_google_credentials
 
9
  setup_google_credentials()
10
 
11
  COMMON_EMOTIONS = [
 
5
 
6
  db = firestore.Client()
7
 
8
+
9
+ from backend.credentials import setup_google_credentials
10
  setup_google_credentials()
11
 
12
  COMMON_EMOTIONS = [
backend/rag_utils.py CHANGED
@@ -4,7 +4,8 @@ from backend.mood_extraction import get_recent_mood_entries
4
  import time
5
  from backend.cache_utils import get_cached_user_data, cache_user_data
6
 
7
- from backend.config import setup_google_credentials
 
8
  setup_google_credentials()
9
 
10
  # Load from .env file
 
4
  import time
5
  from backend.cache_utils import get_cached_user_data, cache_user_data
6
 
7
+
8
+ from backend.credentials import setup_google_credentials
9
  setup_google_credentials()
10
 
11
  # Load from .env file
server.py CHANGED
@@ -20,7 +20,7 @@ from backend.cache_utils import get_cached_user_data, cache_user_data, cleanup_e
20
  import json
21
  import os
22
 
23
- from backend.config import setup_google_credentials
24
  setup_google_credentials()
25
 
26
 
 
20
  import json
21
  import os
22
 
23
+ from backend.credentials import setup_google_credentials
24
  setup_google_credentials()
25
 
26
 
tools/goal_tools.py CHANGED
@@ -3,7 +3,8 @@ from langchain_core.tools import tool
3
  from datetime import datetime, timedelta
4
  import pytz
5
 
6
- from backend.config import setup_google_credentials
 
7
  setup_google_credentials()
8
 
9
  APP_TO_DB_CATEGORY = {
 
3
  from datetime import datetime, timedelta
4
  import pytz
5
 
6
+
7
+ from backend.credentials import setup_google_credentials
8
  setup_google_credentials()
9
 
10
  APP_TO_DB_CATEGORY = {