e7f2b240
tangwang
first commit
|
1
|
"""
|
bad17b15
tangwang
调通baseline
|
2
|
Configuration management for ShopAgent
|
e7f2b240
tangwang
first commit
|
3
4
5
|
Loads environment variables and provides configuration objects
"""
|
bad17b15
tangwang
调通baseline
|
6
|
from pathlib import Path
|
8810a6fa
tangwang
重构
|
7
|
from typing import Optional
|
e7f2b240
tangwang
first commit
|
8
|
|
bad17b15
tangwang
调通baseline
|
9
10
11
12
|
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource, SettingsConfigDict
# config.py sits at app/config.py → parent.parent = project root
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
e7f2b240
tangwang
first commit
|
13
14
15
16
17
18
|
class Settings(BaseSettings):
"""Application settings loaded from environment variables
All settings can be configured via .env file or environment variables.
|
bad17b15
tangwang
调通baseline
|
19
|
Priority (high → low): init kwargs > .env file > env vars > defaults
|
e7f2b240
tangwang
first commit
|
20
21
|
"""
|
bad17b15
tangwang
调通baseline
|
22
23
24
25
26
27
28
|
model_config = SettingsConfigDict(
env_file=str(PROJECT_ROOT / ".env"),
env_file_encoding="utf-8",
case_sensitive=False,
extra="ignore",
)
|
e7f2b240
tangwang
first commit
|
29
30
31
|
# OpenAI Configuration
openai_api_key: str
openai_model: str = "gpt-4o-mini"
|
46f8dd12
tangwang
1. add prod under...
|
32
33
|
# 图片理解 / 多模态模型(例如 Qwen3-Omni-Flash)
openai_vision_model: str = "qwen3-omni-flash"
|
e7f2b240
tangwang
first commit
|
34
35
|
openai_temperature: float = 0.7
openai_max_tokens: int = 1000
|
363578ca
tangwang
**feat: robust th...
|
36
37
38
39
|
# 对话调用大模型时是否开启 thinking:
# - OpenAI 官方 endpoint(含 api.openai.com base_url):走 Responses API reasoning
# - DashScope 兼容 endpoint:通过 extra_body.enable_thinking 开启
openai_use_reasoning: bool = True
|
621b6925
tangwang
up
|
40
|
openai_reasoning_effort: str = "medium" # low | medium | high
|
8810a6fa
tangwang
重构
|
41
42
43
|
# Base URL for OpenAI-compatible APIs (e.g. Qwen/DashScope)
# Qwen 北京: https://dashscope.aliyuncs.com/compatible-mode/v1
openai_api_base_url: Optional[str] = None
|
e7f2b240
tangwang
first commit
|
44
45
46
47
|
# Search Configuration
top_k_results: int = 10
similarity_threshold: float = 0.6
|
50fcfb9d
tangwang
up
|
48
49
|
# 商品搜索 API 单次请求最多返回条数(1–20),search_products 统一使用此配置
search_products_limit: int = 20
|
e7f2b240
tangwang
first commit
|
50
|
|
8810a6fa
tangwang
重构
|
51
52
|
# Search API (see docs/搜索API对接指南.md)
search_api_base_url: str = "http://120.76.41.98:6002"
|
bad17b15
tangwang
调通baseline
|
53
|
search_api_tenant_id: str = "170"
|
8810a6fa
tangwang
重构
|
54
|
|
e7f2b240
tangwang
first commit
|
55
56
57
58
59
60
61
62
63
64
65
|
# Application Configuration
app_host: str = "0.0.0.0"
app_port: int = 8000
debug: bool = True
log_level: str = "INFO"
# Data Paths
raw_data_path: str = "./data/raw"
processed_data_path: str = "./data/processed"
image_data_path: str = "./data/images"
|
bad17b15
tangwang
调通baseline
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
@classmethod
def settings_customise_sources(
cls,
settings_cls: type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]:
"""Make .env file take priority over system environment variables.
Default order: init > env > dotenv > secrets
Our order: init > dotenv > env > secrets
"""
return init_settings, dotenv_settings, env_settings, file_secret_settings
|
e7f2b240
tangwang
first commit
|
81
82
83
84
85
86
|
# Global settings instance
settings = Settings()
|
e7f2b240
tangwang
first commit
|
87
|
def get_absolute_path(relative_path: str) -> str:
|
bad17b15
tangwang
调通baseline
|
88
89
|
"""Convert relative path to absolute path based on project root"""
return str(PROJECT_ROOT / relative_path)
|