@louloulinx/metagpt 0.1.4 → 0.1.5
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/README.md +105 -0
- package/package.json +1 -1
package/README.md
CHANGED
@@ -141,6 +141,111 @@ config.OPENAI_API_KEY = "sk-..."; // Your API key
|
|
141
141
|
config.OPENAI_API_MODEL = "gpt-4-1106-preview"; // Model version
|
142
142
|
```
|
143
143
|
|
144
|
+
## Tutorial Assistant Example
|
145
|
+
|
146
|
+
The Tutorial Assistant is a specialized role that can generate comprehensive tutorial documents in Markdown format.
|
147
|
+
|
148
|
+
```typescript
|
149
|
+
import { VercelLLMProvider } from '@louloulinx/metagpt';
|
150
|
+
import { TutorialAssistant } from '@louloulinx/metagpt';
|
151
|
+
import { v4 as uuidv4 } from 'uuid';
|
152
|
+
|
153
|
+
/**
|
154
|
+
* 教程助手示例
|
155
|
+
*
|
156
|
+
* 该示例演示如何使用教程助手生成Markdown格式的教程文档
|
157
|
+
*/
|
158
|
+
async function main() {
|
159
|
+
console.log(`🚀 开始执行教程生成 [${new Date().toISOString()}]`);
|
160
|
+
|
161
|
+
try {
|
162
|
+
// 从环境变量获取API密钥
|
163
|
+
const apiKey = process.env.DASHSCOPE_API_KEY;
|
164
|
+
console.log('✓ 检查环境变量');
|
165
|
+
|
166
|
+
if (!apiKey) {
|
167
|
+
console.error('❌ 错误: 请设置环境变量: DASHSCOPE_API_KEY');
|
168
|
+
process.exit(1);
|
169
|
+
}
|
170
|
+
console.log('✓ 环境变量已设置');
|
171
|
+
|
172
|
+
// 初始化Vercel LLM提供商 - 使用百炼大模型(qwen)
|
173
|
+
console.log('⚙️ 配置百炼大模型...');
|
174
|
+
const llmProvider = new VercelLLMProvider({
|
175
|
+
providerType: 'qwen',
|
176
|
+
apiKey,
|
177
|
+
model: 'qwen-plus-2025-01-25',
|
178
|
+
baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1', // 自定义API端点
|
179
|
+
extraConfig: {
|
180
|
+
qwenOptions: {
|
181
|
+
debug: true, // 启用调试日志
|
182
|
+
},
|
183
|
+
generateOptions: {
|
184
|
+
system: '你是一位专业的教程编写专家,擅长生成高质量、结构清晰的教程文档。'
|
185
|
+
}
|
186
|
+
}
|
187
|
+
});
|
188
|
+
console.log(`✓ 模型配置完成: ${llmProvider.config?.providerType} - ${llmProvider.config?.model}`);
|
189
|
+
|
190
|
+
console.log('⚙️ 初始化教程助手...');
|
191
|
+
console.time('教程助手初始化时间');
|
192
|
+
|
193
|
+
// 创建教程助手
|
194
|
+
const tutorialAssistant = new TutorialAssistant({
|
195
|
+
llm: llmProvider,
|
196
|
+
language: 'Chinese', // 可选: 'English'
|
197
|
+
outputDir: './output/tutorials', // 可选,默认为 './tutorials'
|
198
|
+
});
|
199
|
+
|
200
|
+
console.timeEnd('教程助手初始化时间');
|
201
|
+
console.log('✓ 教程助手初始化完成');
|
202
|
+
|
203
|
+
// 设置要生成的教程主题
|
204
|
+
const topic = 'rust语言教程';
|
205
|
+
console.log(`📝 生成主题: "${topic}"`);
|
206
|
+
|
207
|
+
// 生成教程
|
208
|
+
console.log('🔄 开始生成教程...');
|
209
|
+
console.log('👉 步骤 1: 生成目录结构');
|
210
|
+
console.time('教程生成总时间');
|
211
|
+
|
212
|
+
const result = await tutorialAssistant.react({
|
213
|
+
id: uuidv4(),
|
214
|
+
role: 'user',
|
215
|
+
content: topic,
|
216
|
+
sentFrom: 'user',
|
217
|
+
sendTo: new Set(['*']),
|
218
|
+
instructContent: null,
|
219
|
+
});
|
220
|
+
|
221
|
+
console.timeEnd('教程生成总时间');
|
222
|
+
console.log('✅ 教程生成完成!');
|
223
|
+
|
224
|
+
// 提取文件路径(假设结果消息中包含文件路径信息)
|
225
|
+
const filePath = result.content.includes('saved to')
|
226
|
+
? result.content.split('saved to ')[1].trim()
|
227
|
+
: '未找到文件路径';
|
228
|
+
|
229
|
+
console.log(`📄 生成结果: ${result.content}`);
|
230
|
+
console.log(`📂 输出文件: ${filePath}`);
|
231
|
+
console.log(`🏁 教程生成完成 [${new Date().toISOString()}]`);
|
232
|
+
} catch (error) {
|
233
|
+
console.error('❌ 生成教程时出错:', error);
|
234
|
+
if (error instanceof Error) {
|
235
|
+
console.error(`错误类型: ${error.name}`);
|
236
|
+
console.error(`错误信息: ${error.message}`);
|
237
|
+
console.error(`错误堆栈: ${error.stack}`);
|
238
|
+
}
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
// 运行示例
|
243
|
+
console.log('📌 教程助手示例');
|
244
|
+
main();
|
245
|
+
```
|
246
|
+
|
247
|
+
|
248
|
+
|
144
249
|
## Basic Usage Example (Coming Soon)
|
145
250
|
|
146
251
|
```typescript
|