Redfire-1234 commited on
Commit
3bcd5c9
·
verified ·
1 Parent(s): 1d1fd13

Update app/config.py

Browse files
Files changed (1) hide show
  1. app/config.py +46 -14
app/config.py CHANGED
@@ -2,8 +2,6 @@ from pydantic_settings import BaseSettings
2
  from functools import lru_cache
3
  import base64
4
  import json
5
- import tempfile
6
- import os
7
 
8
  class Settings(BaseSettings):
9
  groq_api_key: str
@@ -17,22 +15,56 @@ class Settings(BaseSettings):
17
  class Config:
18
  env_file = ".env"
19
 
20
- def get_google_credentials_path(self) -> str:
21
  """
22
- Decode base64 credentials and write to a temporary file.
23
- Returns the path to the credentials file.
24
  """
25
- # Decode base64 string
26
- credentials_json = base64.b64decode(self.google_credentials_base64).decode('utf-8')
27
-
28
- # Create a temporary file
29
- temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json')
30
- temp_file.write(credentials_json)
31
- temp_file.close()
32
-
33
- return temp_file.name
34
 
35
  @lru_cache()
36
  def get_settings():
37
  return Settings()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
 
2
  from functools import lru_cache
3
  import base64
4
  import json
 
 
5
 
6
  class Settings(BaseSettings):
7
  groq_api_key: str
 
15
  class Config:
16
  env_file = ".env"
17
 
18
+ def get_google_credentials_dict(self) -> dict:
19
  """
20
+ Decode base64 credentials and return as dictionary.
 
21
  """
22
+ try:
23
+ # Decode base64 string
24
+ credentials_json = base64.b64decode(self.google_credentials_base64).decode('utf-8')
25
+ # Parse JSON
26
+ return json.loads(credentials_json)
27
+ except Exception as e:
28
+ raise ValueError(f"Failed to decode Google credentials: {str(e)}")
 
 
29
 
30
  @lru_cache()
31
  def get_settings():
32
  return Settings()
33
+ # from pydantic_settings import BaseSettings
34
+ # from functools import lru_cache
35
+ # import base64
36
+ # import json
37
+ # import tempfile
38
+ # import os
39
+
40
+ # class Settings(BaseSettings):
41
+ # groq_api_key: str
42
+ # google_credentials_base64: str
43
+ # google_drive_folder_id: str
44
+ # vector_store_path: str = "data/vector_store"
45
+ # chunk_size: int = 800
46
+ # chunk_overlap: int = 150
47
+ # top_k_results: int = 3
48
+
49
+ # class Config:
50
+ # env_file = ".env"
51
+
52
+ # def get_google_credentials_path(self) -> str:
53
+ # """
54
+ # Decode base64 credentials and write to a temporary file.
55
+ # Returns the path to the credentials file.
56
+ # """
57
+ # # Decode base64 string
58
+ # credentials_json = base64.b64decode(self.google_credentials_base64).decode('utf-8')
59
+
60
+ # # Create a temporary file
61
+ # temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json')
62
+ # temp_file.write(credentials_json)
63
+ # temp_file.close()
64
+
65
+ # return temp_file.name
66
+
67
+ # @lru_cache()
68
+ # def get_settings():
69
+ # return Settings()
70