Skip to content

Commit dd05586

Browse files
authored
Merge pull request #49 from sunmh207/feature/20250321-config
Feature/20250321 config
2 parents fd27e50 + 94ea290 commit dd05586

23 files changed

+28
-43
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
venv/
33
test/
44
.idea/
5-
docker
65

76
log/*
87
!log/.gitkeep
98
data/*
109
!data/.gitkeep
1110

12-
.env
11+
conf/.env
1312
.pyc
1413
__pycache__/
1514
.cursorignore

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ COPY requirements.txt .
1313
# 安装依赖
1414
RUN pip install --no-cache-dir -r requirements.txt
1515

16+
RUN mkdir -p log data conf
1617
COPY biz ./biz
1718
COPY core ./core
1819
COPY api.py ./api.py
1920
COPY ui.py ./ui.py
20-
COPY prompt_templates.yml ./prompt_templates.yml
21-
RUN mkdir -p log data
21+
COPY conf/prompt_templates.yml ./conf/prompt_templates.yml
22+
2223

2324
# 暴露 Flask 和 Streamlit 的端口
2425
EXPOSE 5001 5002
@@ -27,7 +28,7 @@ EXPOSE 5001 5002
2728
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
2829

2930
FROM base AS dev
30-
COPY supervisord.dev.conf /etc/supervisor/conf.d/supervisord.conf
31+
COPY ./conf/supervisord.dev.conf /etc/supervisor/conf.d/supervisord.conf
3132

3233
FROM base AS prod
33-
COPY supervisord.prod.conf /etc/supervisor/conf.d/supervisord.conf
34+
COPY ./conf/supervisord.prod.conf /etc/supervisor/conf.d/supervisord.conf

api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from biz.utils.reporter import Reporter
2222
from urllib.parse import urlparse
2323

24-
load_dotenv()
24+
load_dotenv("conf/.env")
2525
api_app = Flask(__name__)
2626

2727
PUSH_REVIEW_ENABLED = os.environ.get('PUSH_REVIEW_ENABLED', '0') == '1'
File renamed without changes.
File renamed without changes.

core/llm/client/base.py renamed to biz/llm/client/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import abstractmethod
22
from typing import List, Dict, Optional
33

4-
from core.llm.types import NotGiven, NOT_GIVEN, CompletionMessage
4+
from biz.llm.types import NotGiven, NOT_GIVEN
55

66

77
class BaseClient:

core/llm/client/deepseek.py renamed to biz/llm/client/deepseek.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import os
22
from typing import Dict, List, Optional
33

4-
from dotenv import load_dotenv
54
from openai import OpenAI
6-
from biz.utils.log import logger
75

8-
from core.llm.client.base import BaseClient
9-
from core.llm.types import NotGiven, NOT_GIVEN
6+
from biz.llm.client.base import BaseClient
7+
from biz.llm.types import NotGiven, NOT_GIVEN
8+
from biz.utils.log import logger
109

1110

1211
class DeepSeekClient(BaseClient):
1312
def __init__(self, api_key: str = None):
14-
if not os.getenv("DEEPSEEK_API_KEY"):
15-
load_dotenv()
1613
self.api_key = api_key or os.getenv("DEEPSEEK_API_KEY")
1714
self.base_url = os.getenv("DEEPSEEK_API_BASE_URL", "https://api.deepseek.com")
1815
if not self.api_key:

core/llm/client/ollama_client.py renamed to biz/llm/client/ollama_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from ollama import ChatResponse
66
from ollama import Client
77

8-
from core.llm.client.base import BaseClient
9-
from core.llm.types import NotGiven, NOT_GIVEN
8+
from biz.llm.client.base import BaseClient
9+
from biz.llm.types import NotGiven, NOT_GIVEN
1010

1111

1212
class OllamaClient(BaseClient):

core/llm/client/openai.py renamed to biz/llm/client/openai.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import os
22
from typing import Dict, List, Optional
33

4-
from dotenv import load_dotenv
54
from openai import OpenAI
65

7-
from core.llm.client.base import BaseClient
8-
from core.llm.types import NotGiven, NOT_GIVEN
6+
from biz.llm.client.base import BaseClient
7+
from biz.llm.types import NotGiven, NOT_GIVEN
98

109

1110
class OpenAIClient(BaseClient):
1211
def __init__(self, api_key: str = None):
13-
if not os.getenv("OPENAI_API_KEY"):
14-
load_dotenv()
1512
self.api_key = api_key or os.getenv("OPENAI_API_KEY")
1613
self.base_url = os.getenv("OPENAI_API_BASE_URL", "https://api.openai.com")
1714
if not self.api_key:

core/llm/client/zhipuai.py renamed to biz/llm/client/zhipuai.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import os
22
from typing import Dict, List, Optional
33

4-
from dotenv import load_dotenv
54
from zhipuai import ZhipuAI
65

7-
from core.llm.client.base import BaseClient
8-
from core.llm.types import NotGiven, NOT_GIVEN
6+
from biz.llm.client.base import BaseClient
7+
from biz.llm.types import NotGiven, NOT_GIVEN
98

109

1110
class ZhipuAIClient(BaseClient):
1211
def __init__(self, api_key: str = None):
13-
if not os.getenv("ZHIPUAI_API_KEY"):
14-
load_dotenv()
1512
self.api_key = api_key or os.getenv("ZHIPUAI_API_KEY")
1613
if not self.api_key:
1714
raise ValueError("API key is required. Please provide it or set it in the environment variables.")

core/llm/factory.py renamed to biz/llm/factory.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import os
22

3-
from dotenv import load_dotenv
4-
5-
from core.llm.client.base import BaseClient
6-
from core.llm.client.deepseek import DeepSeekClient
7-
from core.llm.client.ollama_client import OllamaClient
8-
from core.llm.client.openai import OpenAIClient
9-
from core.llm.client.zhipuai import ZhipuAIClient
3+
from biz.llm.client.base import BaseClient
4+
from biz.llm.client.deepseek import DeepSeekClient
5+
from biz.llm.client.ollama_client import OllamaClient
6+
from biz.llm.client.openai import OpenAIClient
7+
from biz.llm.client.zhipuai import ZhipuAIClient
108

119

1210
class Factory:
1311
@staticmethod
1412
def getClient(provider: str = None) -> BaseClient:
15-
load_dotenv()
1613
provider = provider or os.getenv("LLM_PROVIDER", "openai")
1714
chat_model_providers = {
1815
'zhipuai': lambda: ZhipuAIClient(),
File renamed without changes.

biz/utils/code_reviewer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import os
21
import re
32

43
import yaml
54

65
from biz.utils.log import logger
7-
from core.llm.factory import Factory
6+
from biz.llm.factory import Factory
87

98

109
class CodeReviewer:
@@ -14,7 +13,7 @@ def __init__(self):
1413

1514
def _load_prompts(self) -> dict:
1615
"""加载提示词配置"""
17-
prompt_templates_file = "prompt_templates.yml"
16+
prompt_templates_file = "conf/prompt_templates.yml"
1817
with open(prompt_templates_file, "r") as file:
1918
prompt_templates = yaml.safe_load(file)
2019
system_prompt = prompt_templates['system_prompt']

biz/utils/log.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
import os
33
from logging.handlers import RotatingFileHandler
44

5-
from dotenv import load_dotenv
6-
7-
load_dotenv()
85
log_file = os.environ.get("LOG_FILE", "log/app.log")
96
log_max_bytes = int(os.environ.get("LOG_MAX_BYTES", 10 * 1024 * 1024)) # 默认10MB
107
log_backup_count = int(os.environ.get("LOG_BACKUP_COUNT", 5)) # 默认保留5个备份文件

biz/utils/reporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from core.llm.factory import Factory
1+
from biz.llm.factory import Factory
22

33

44
class Reporter:
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

core/llm/client/__init__.py

Whitespace-only changes.

docker-compose.prod.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
volumes:
1212
- data:/app/data
1313
- log:/app/log
14+
- conf:/app/conf
1415
env_file:
1516
- .env
1617
restart: unless-stopped

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ services:
1111
volumes:
1212
- ./biz:/app/biz
1313
- ./core:/app/core
14+
- ./conf:/app/conf
1415
- ./data:/app/data
1516
- ./log:/app/log
1617
- ./api.py:/app/api.py
17-
- ./prompt_templates.yml:/app/prompt_templates.yml
1818
- ./requirements.txt:/app/requirements.txt
1919
- ./supervisord.dev.conf:/etc/supervisor/conf.d/supervisord.conf
2020
- ./ui.py:/app/ui.py

ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from biz.service.review_service import ReviewService
99

10-
load_dotenv()
10+
load_dotenv("conf/.env")
1111

1212
# 从环境变量中读取用户名和密码
1313
DASHBOARD_USER = os.getenv("DASHBOARD_USER", "admin")

0 commit comments

Comments
 (0)