tikendraw commited on
Commit
bd8615d
·
1 Parent(s): 567a707

moved to core.config.confg

Browse files
Files changed (1) hide show
  1. app/app_config.py +3 -70
app/app_config.py CHANGED
@@ -1,8 +1,9 @@
1
  import json
2
  import os
3
- from dataclasses import dataclass
4
  from pathlib import Path
5
  from dotenv import load_dotenv
 
6
 
7
  CUR_DIR = Path(os.path.abspath(__file__)).parent.parent
8
  CACHE_DIR = CUR_DIR/'cache'
@@ -13,75 +14,7 @@ CONFIG_FILE_PATH = CUR_DIR / 'input_config.json'
13
  print(f"{CUR_DIR=}")
14
  print(f"{ENV_FILE_PATH=}")
15
  print(f"{CONFIG_FILE_PATH=}")
16
-
17
-
18
- @dataclass
19
- class InputConfig:
20
- model_name: str = 'openai/gpt-3.5-turbo'
21
- model_api_key: str = 'sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
22
- max_tokens: int = 1024
23
- max_steps: int = 10
24
- temperature: float = 0.2
25
- timeout: float = 30.0
26
- sleeptime: float = 0.0
27
- force_max_steps: bool = True
28
-
29
- @classmethod
30
- def load(cls, env_file=ENV_FILE_PATH, config_file=CONFIG_FILE_PATH):
31
- # Load env variables
32
- load_dotenv(env_file)
33
- env_dict = {
34
- 'model_name': os.getenv('MODEL_NAME', 'not set'),
35
- 'model_api_key': os.getenv('MODEL_API_KEY', 'not set')
36
- }
37
-
38
- # Load config JSON
39
- with open(config_file, 'r') as f:
40
- config_dict = json.load(f)
41
-
42
- # Combine both
43
- return cls(
44
- model_name=env_dict.get('model_name', cls.model_name),
45
- model_api_key=env_dict.get('model_api_key', cls.model_api_key),
46
- max_tokens=config_dict.get('max_tokens', cls.max_tokens),
47
- max_steps=config_dict.get('max_steps', cls.max_steps),
48
- temperature=config_dict.get('temperature', cls.temperature),
49
- timeout=config_dict.get('timeout', cls.timeout),
50
- sleeptime=config_dict.get('sleeptime', cls.sleeptime),
51
- force_max_steps=config_dict.get('force_max_steps', cls.force_max_steps)
52
- )
53
-
54
- def save(self, env_file=ENV_FILE_PATH, config_file=CONFIG_FILE_PATH):
55
- # Read existing env content if it exists
56
- env_vars = {}
57
- if os.path.exists(env_file):
58
- with open(env_file, 'r') as f:
59
- for line in f:
60
- if line.strip(): # Ignore empty lines
61
- key, value = line.strip().split('=', 1)
62
- env_vars[key] = value
63
-
64
- # Update the necessary keys
65
- env_vars['MODEL_API_KEY'] = self.model_api_key
66
- env_vars['MODEL_NAME'] = self.model_name
67
-
68
- # Write back to the .env file
69
- with open(env_file, 'w') as f:
70
- for key, value in env_vars.items():
71
- f.write(f'{key}={value}\n')
72
-
73
- # Save other parameters to input_config.json
74
- config_dict = {
75
- 'max_tokens': self.max_tokens,
76
- 'max_steps': self.max_steps,
77
- 'temperature': self.temperature,
78
- 'timeout': self.timeout,
79
- 'sleeptime': self.sleeptime,
80
- 'force_max_steps': self.force_max_steps
81
- }
82
- with open(config_file, 'w') as f:
83
- json.dump(config_dict, f, indent=4)
84
 
85
  if not CONFIG_FILE_PATH.exists() or not ENV_FILE_PATH.exists():
86
- InputConfig().save()
87
 
 
1
  import json
2
  import os
3
+ from pydantic import BaseModel
4
  from pathlib import Path
5
  from dotenv import load_dotenv
6
+ from core.config.config import InputConfig
7
 
8
  CUR_DIR = Path(os.path.abspath(__file__)).parent.parent
9
  CACHE_DIR = CUR_DIR/'cache'
 
14
  print(f"{CUR_DIR=}")
15
  print(f"{ENV_FILE_PATH=}")
16
  print(f"{CONFIG_FILE_PATH=}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  if not CONFIG_FILE_PATH.exists() or not ENV_FILE_PATH.exists():
19
+ InputConfig().save(ENV_FILE_PATH, CONFIG_FILE_PATH)
20