Skip to content

Commit 3ea022c

Browse files
authored
Merge pull request #115 from Cloud-Code-AI/114-update-how-the-config-data-is-passed
fix: updated how config data is managed
2 parents 11b4f11 + 70333a1 commit 3ea022c

File tree

4 files changed

+58
-46
lines changed

4 files changed

+58
-46
lines changed

github_app/github_helper/constants.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

github_app/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
process_pr_desc,
88
)
99
from github_app.github_helper.utils import is_github_signature_valid
10-
from kaizen.utils.config import CONFIG_DATA
10+
from kaizen.utils.config import ConfigData
1111
import logging
1212

1313
# from cloudcode.generator.ui import UITester
@@ -26,6 +26,7 @@ async def handle_webhook(request: Request, background_tasks: BackgroundTasks):
2626
body = await request.body()
2727
event = request.headers.get("X-GitHub-Event")
2828
# Check if the Signature is valid
29+
CONFIG_DATA = ConfigData()
2930
if CONFIG_DATA["github_app"]["check_signature"] and not is_github_signature_valid(
3031
request.headers, body
3132
):

kaizen/llms/provider.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import litellm
22
from kaizen.llms.prompts import BASIC_SYSTEM_PROMPT
3-
from kaizen.utils.config import CONFIG_DATA
3+
from kaizen.utils.config import ConfigData
44

55

66
class LLMProvider:
@@ -19,6 +19,8 @@ def __init__(
1919
self.model = model
2020
self.max_tokens = max_tokens
2121
self.temperature = temperature
22+
CONFIG_DATA = ConfigData()
23+
self.config = CONFIG_DATA
2224
if CONFIG_DATA.get("language_model", {}).get(
2325
"enable_observability_logging", False
2426
):

kaizen/utils/config.py

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,59 @@
33
from pathlib import Path
44

55

6-
def get_config():
7-
# Get the directory of the calling function
8-
caller_dir = Path(os.path.dirname(os.path.abspath(__file__)))
9-
config_file = f"{caller_dir}/config.json"
10-
if Path(config_file).is_file():
11-
with open(config_file, "r") as f:
12-
config_data = json.loads(f.read())
13-
else:
14-
config_data = {
15-
"language_model": {
16-
"provider": "litellm",
17-
"enable_observability_logging": False,
18-
},
19-
"github_app": {
20-
"check_signature": False,
21-
"auto_pr_review": False,
22-
"edit_pr_desc": False,
23-
},
24-
}
25-
return config_data
26-
27-
28-
def validate_config_settings(config):
29-
"Make sure relvant enviorment variables are set"
30-
if config.get("github_app", {}).get("check_signature", False):
31-
if not os.environ.get("GITHUB_APP_WEBHOOK_SECRET"):
32-
raise EnvironmentError(
33-
"The environment variable 'GITHUB_APP_WEBHOOK_SECRET' is not set."
34-
)
35-
36-
if config.get("language_model", {}).get("provider", {}) == "litellm":
37-
if config.get("language_model", {}).get("enable_observability_logging", False):
38-
if not os.environ.get("SUPABASE_URL"):
39-
raise EnvironmentError(
40-
"The environment variable 'SUPABASE_URL' is not set."
41-
)
42-
if not os.environ.get("SUPABASE_KEY"):
6+
class ConfigData:
7+
def __init__(self, config_data=None):
8+
config_file = "config.json"
9+
if Path(config_file).is_file():
10+
with open(config_file, "r") as f:
11+
self.config_data = json.loads(f.read())
12+
else:
13+
print(f"Couldnt find config at {config_file} loading default vals")
14+
self.config_data = {
15+
"language_model": {
16+
"provider": "litellm",
17+
"enable_observability_logging": False,
18+
},
19+
"github_app": {
20+
"check_signature": False,
21+
"auto_pr_review": False,
22+
"edit_pr_desc": False,
23+
},
24+
}
25+
26+
if config_data:
27+
self.update_config_data(config_data)
28+
29+
def update_config_data(self, new_config_data):
30+
self.config_data.update(new_config_data)
31+
self.validate_config_settings(self.config_data)
32+
33+
def get_config_data(self):
34+
return self.config_data
35+
36+
def get_language_model_config(self):
37+
return self.config_data["language_model"]
38+
39+
def get_github_app_config(self):
40+
return self.config_data["github_app"]
41+
42+
def validate_config_settings(self):
43+
"Make sure relvant enviorment variables are set"
44+
if self.config_data.get("github_app", {}).get("check_signature", False):
45+
if not os.environ.get("GITHUB_APP_WEBHOOK_SECRET"):
4346
raise EnvironmentError(
44-
"The environment variable 'SUPABASE_KEY' is not set."
47+
"The environment variable 'GITHUB_APP_WEBHOOK_SECRET' is not set."
4548
)
46-
return config
47-
4849

49-
CONFIG_DATA = validate_config_settings(get_config())
50+
if self.config_data.get("language_model", {}).get("provider", {}) == "litellm":
51+
if self.config_data.get("language_model", {}).get(
52+
"enable_observability_logging", False
53+
):
54+
if not os.environ.get("SUPABASE_URL"):
55+
raise EnvironmentError(
56+
"The environment variable 'SUPABASE_URL' is not set."
57+
)
58+
if not os.environ.get("SUPABASE_KEY"):
59+
raise EnvironmentError(
60+
"The environment variable 'SUPABASE_KEY' is not set."
61+
)

0 commit comments

Comments
 (0)