travel-agent-cli 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/python/config/settings.py +9 -1
- package/python/main.py +6 -3
package/package.json
CHANGED
|
@@ -151,7 +151,7 @@ class Settings(BaseSettings):
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
class Config:
|
|
154
|
-
env_file =
|
|
154
|
+
env_file = ".env"
|
|
155
155
|
env_file_encoding = "utf-8"
|
|
156
156
|
extra = "ignore"
|
|
157
157
|
|
|
@@ -159,6 +159,14 @@ class Settings(BaseSettings):
|
|
|
159
159
|
@lru_cache()
|
|
160
160
|
def get_settings() -> Settings:
|
|
161
161
|
"""获取配置单例"""
|
|
162
|
+
# 如果 .env 文件不存在,自动从 .env.example 创建
|
|
163
|
+
env_path = Path(__file__).parent.parent / ".env"
|
|
164
|
+
env_example_path = Path(__file__).parent.parent / ".env.example"
|
|
165
|
+
|
|
166
|
+
if not env_path.exists() and env_example_path.exists():
|
|
167
|
+
import shutil
|
|
168
|
+
shutil.copy(env_example_path, env_path)
|
|
169
|
+
|
|
162
170
|
return Settings()
|
|
163
171
|
|
|
164
172
|
|
package/python/main.py
CHANGED
|
@@ -524,10 +524,13 @@ def _switch_model(settings, provider: str, model_name: Optional[str]):
|
|
|
524
524
|
|
|
525
525
|
def _update_model_config(provider: str, model_name: Optional[str]):
|
|
526
526
|
"""更新模型配置"""
|
|
527
|
-
|
|
527
|
+
# 在项目根目录下查找 .env 文件
|
|
528
|
+
env_path = Path(__file__).parent / ".env"
|
|
528
529
|
if not env_path.exists():
|
|
529
530
|
console.print("[yellow].env 文件不存在,正在创建...[/yellow]")
|
|
530
531
|
_init_config()
|
|
532
|
+
# 重新获取路径
|
|
533
|
+
env_path = Path(__file__).parent / ".env"
|
|
531
534
|
|
|
532
535
|
# 重新读取配置(如果刚创建)
|
|
533
536
|
if not env_path.exists():
|
|
@@ -594,8 +597,8 @@ def _init_config():
|
|
|
594
597
|
console.print("请确保已正确安装 travel-agent-cli")
|
|
595
598
|
return
|
|
596
599
|
|
|
597
|
-
#
|
|
598
|
-
dst = Path
|
|
600
|
+
# 在项目目录下创建 .env 文件
|
|
601
|
+
dst = Path(__file__).parent / ".env"
|
|
599
602
|
if not dst.exists():
|
|
600
603
|
shutil.copy(src, dst)
|
|
601
604
|
console.print("[green]已创建 .env 配置文件[/green]")
|