travel-agent-cli 0.2.2 → 0.2.4
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/.env.example +56 -0
- package/python/main.py +21 -2
- package/scripts/postinstall.js +69 -27
package/package.json
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# 旅行 Agent 配置 - 支持多 LLM 提供商
|
|
2
|
+
|
|
3
|
+
# ========== LLM 配置(必填:至少配置一个)==========
|
|
4
|
+
|
|
5
|
+
# 使用哪个 LLM 提供商:anthropic, openai, deepseek, azure, ollama, qwen
|
|
6
|
+
LLM_PROVIDER=anthropic
|
|
7
|
+
|
|
8
|
+
# 使用的模型名称(留空则使用默认)
|
|
9
|
+
# Anthropic: claude-sonnet-4-6, claude-opus-4-6
|
|
10
|
+
# OpenAI: gpt-4o, gpt-4-turbo
|
|
11
|
+
# DeepSeek: deepseek-chat
|
|
12
|
+
# Azure OpenAI: gpt-4
|
|
13
|
+
# Ollama: llama3, mistral, qwen2
|
|
14
|
+
# Qwen (通义千问): qwen-max, qwen-plus, qwen-turbo, qwen-long
|
|
15
|
+
LLM_MODEL=
|
|
16
|
+
|
|
17
|
+
# --- Anthropic 配置 ---
|
|
18
|
+
ANTHROPIC_API_KEY=
|
|
19
|
+
|
|
20
|
+
# --- OpenAI 配置 ---
|
|
21
|
+
OPENAI_API_KEY=
|
|
22
|
+
|
|
23
|
+
# --- DeepSeek 配置 ---
|
|
24
|
+
DEEPSEEK_API_KEY=
|
|
25
|
+
|
|
26
|
+
# --- Azure OpenAI 配置 ---
|
|
27
|
+
AZURE_OPENAI_API_KEY=
|
|
28
|
+
AZURE_OPENAI_ENDPOINT=
|
|
29
|
+
AZURE_OPENAI_API_VERSION=2024-02-15-preview
|
|
30
|
+
|
|
31
|
+
# --- Ollama 配置(本地部署,无需 API Key)---
|
|
32
|
+
OLLAMA_BASE_URL=http://localhost:11434
|
|
33
|
+
|
|
34
|
+
# --- 阿里云通义千问(Qwen)配置 ---
|
|
35
|
+
DASHSCOPE_API_KEY=
|
|
36
|
+
|
|
37
|
+
# ========== 其他配置(可选)==========
|
|
38
|
+
|
|
39
|
+
# 微博 API 配置
|
|
40
|
+
WEIBO_APP_KEY=
|
|
41
|
+
WEIBO_APP_SECRET=
|
|
42
|
+
|
|
43
|
+
# 代理配置(用于爬取)
|
|
44
|
+
HTTP_PROXY=
|
|
45
|
+
HTTPS_PROXY=
|
|
46
|
+
|
|
47
|
+
# 数据库路径
|
|
48
|
+
DATABASE_PATH=./data/travel_agent.db
|
|
49
|
+
|
|
50
|
+
# 报告输出目录
|
|
51
|
+
OUTPUT_DIR=./output
|
|
52
|
+
|
|
53
|
+
# HTTP 请求配置
|
|
54
|
+
REQUEST_TIMEOUT=30
|
|
55
|
+
MAX_RETRIES=3
|
|
56
|
+
REQUEST_DELAY=1.0
|
package/python/main.py
CHANGED
|
@@ -524,11 +524,30 @@ def _update_model_config(provider: str, model_name: Optional[str]):
|
|
|
524
524
|
def _init_config():
|
|
525
525
|
"""初始化配置文件"""
|
|
526
526
|
import shutil
|
|
527
|
-
|
|
528
|
-
|
|
527
|
+
|
|
528
|
+
# 在包的目录中查找 .env.example
|
|
529
|
+
possible_paths = [
|
|
530
|
+
Path(__file__).parent / ".env.example",
|
|
531
|
+
Path.cwd() / ".env.example",
|
|
532
|
+
Path.cwd() / "python" / ".env.example",
|
|
533
|
+
]
|
|
534
|
+
|
|
535
|
+
src = None
|
|
536
|
+
for p in possible_paths:
|
|
537
|
+
if p.exists():
|
|
538
|
+
src = p
|
|
539
|
+
break
|
|
540
|
+
|
|
541
|
+
if not src:
|
|
542
|
+
console.print("[red]错误:未找到 .env.example 文件[/red]")
|
|
543
|
+
console.print("请确保已正确安装 travel-agent-cli")
|
|
544
|
+
return
|
|
545
|
+
|
|
546
|
+
dst = Path.cwd() / ".env"
|
|
529
547
|
if not dst.exists():
|
|
530
548
|
shutil.copy(src, dst)
|
|
531
549
|
console.print("[green]已创建 .env 配置文件[/green]")
|
|
550
|
+
console.print(f"[dim]位置:{dst}[/dim]")
|
|
532
551
|
else:
|
|
533
552
|
console.print("[yellow].env 文件已存在[/yellow]")
|
|
534
553
|
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* npm 安装后执行的脚本
|
|
4
|
-
*
|
|
4
|
+
* 创建虚拟环境并安装 Python 依赖
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const { execSync } = require('child_process');
|
|
@@ -10,12 +10,13 @@ const path = require('path');
|
|
|
10
10
|
|
|
11
11
|
const packagePath = path.join(__dirname, '..');
|
|
12
12
|
const pythonDir = path.join(packagePath, 'python');
|
|
13
|
+
const venvPath = path.join(pythonDir, 'venv');
|
|
13
14
|
|
|
14
15
|
console.log('╭───────────────────────────────────────────────────────────────╮');
|
|
15
16
|
console.log('│ travel-agent-cli 正在安装 Python 依赖... │');
|
|
16
17
|
console.log('╰───────────────────────────────────────────────────────────────╯\n');
|
|
17
18
|
|
|
18
|
-
//
|
|
19
|
+
// 查找 Python
|
|
19
20
|
function findPython() {
|
|
20
21
|
try {
|
|
21
22
|
execSync('python3 --version', { stdio: 'ignore' });
|
|
@@ -30,48 +31,89 @@ function findPython() {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
//
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
console.error(' Linux: sudo apt install python3.10');
|
|
42
|
-
console.error(' Windows: https://www.python.org/downloads/');
|
|
43
|
-
return false;
|
|
34
|
+
// 获取虚拟环境的 Python 路径
|
|
35
|
+
function getVenvPython() {
|
|
36
|
+
const paths = [
|
|
37
|
+
path.join(venvPath, 'bin', 'python'),
|
|
38
|
+
path.join(venvPath, 'Scripts', 'python.exe'),
|
|
39
|
+
];
|
|
40
|
+
for (const p of paths) {
|
|
41
|
+
if (fs.existsSync(p)) return p;
|
|
44
42
|
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
// 创建虚拟环境
|
|
47
|
+
function createVenv(pythonCmd) {
|
|
48
|
+
if (fs.existsSync(venvPath)) {
|
|
49
|
+
console.log('✓ 虚拟环境:已存在');
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
47
52
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
console.
|
|
53
|
+
console.log('正在创建虚拟环境...');
|
|
54
|
+
try {
|
|
55
|
+
execSync(`${pythonCmd} -m venv "${venvPath}"`, { stdio: 'inherit' });
|
|
56
|
+
console.log('✓ 虚拟环境创建完成\n');
|
|
57
|
+
return true;
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error('✗ 虚拟环境创建失败');
|
|
52
60
|
return false;
|
|
53
61
|
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 安装依赖
|
|
65
|
+
function installDependencies(venvPython) {
|
|
66
|
+
console.log(`使用虚拟环境:${venvPython}`);
|
|
67
|
+
console.log('正在安装 Python 依赖...\n');
|
|
54
68
|
|
|
55
69
|
try {
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
70
|
+
// 先升级 pip
|
|
71
|
+
execSync(`${venvPython} -m pip install --upgrade pip`, { stdio: 'ignore' });
|
|
72
|
+
|
|
73
|
+
// 安装项目依赖
|
|
74
|
+
execSync(`${venvPython} -m pip install -e "${pythonDir}"`, { stdio: 'inherit' });
|
|
75
|
+
|
|
62
76
|
console.log('\n✓ Python 依赖安装完成\n');
|
|
63
77
|
return true;
|
|
64
78
|
} catch (e) {
|
|
65
79
|
console.error('\n⚠ Python 依赖安装失败');
|
|
66
|
-
console.error('\n手动安装:');
|
|
67
|
-
console.error(` ${pythonCmd} -m pip install -e "${pythonDir}"`);
|
|
68
80
|
return false;
|
|
69
81
|
}
|
|
70
82
|
}
|
|
71
83
|
|
|
72
84
|
// 主函数
|
|
73
85
|
function main() {
|
|
74
|
-
const
|
|
86
|
+
const pythonCmd = findPython();
|
|
87
|
+
|
|
88
|
+
if (!pythonCmd) {
|
|
89
|
+
console.error('\n⚠ 警告:未找到 Python');
|
|
90
|
+
console.error('请先安装 Python 3.10+');
|
|
91
|
+
console.error(' macOS: brew install python@3.10');
|
|
92
|
+
console.error(' Linux: sudo apt install python3.10');
|
|
93
|
+
console.error(' Windows: https://www.python.org/downloads/');
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log(`使用 Python: ${pythonCmd}\n`);
|
|
98
|
+
|
|
99
|
+
// 创建虚拟环境
|
|
100
|
+
if (!createVenv(pythonCmd)) {
|
|
101
|
+
console.error('\n请手动创建虚拟环境并安装依赖:');
|
|
102
|
+
console.error(` ${pythonCmd} -m venv "${venvPath}"`);
|
|
103
|
+
console.error(` source ${path.join(venvPath, 'bin', 'activate')}`);
|
|
104
|
+
console.error(` pip install -e "${pythonDir}"`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 获取虚拟环境的 Python
|
|
109
|
+
const venvPython = getVenvPython();
|
|
110
|
+
if (!venvPython) {
|
|
111
|
+
console.error('✗ 未找到虚拟环境的 Python');
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 安装依赖
|
|
116
|
+
const success = installDependencies(venvPython);
|
|
75
117
|
|
|
76
118
|
if (success) {
|
|
77
119
|
console.log('╭───────────────────────────────────────────────────────────────╮');
|