@yorha2b-lab/autodev 1.0.5 → 1.0.6
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/bin/autodev.js +12 -0
- package/package.json +1 -1
- package/src/services/llm.js +10 -1
package/bin/autodev.js
CHANGED
|
@@ -26,6 +26,18 @@ program.version('1.0.0').description('AI驱动的前端CRUD代码生成器')
|
|
|
26
26
|
|
|
27
27
|
program.option('-t, --template <type>', '指定前端框架模板', 'react')
|
|
28
28
|
|
|
29
|
+
program
|
|
30
|
+
.command('init')
|
|
31
|
+
.description('在当前目录初始化 .env 和 config.js 配置文件')
|
|
32
|
+
.action(() => {
|
|
33
|
+
const tplConfig = path.resolve(__dirname, '../config.js')
|
|
34
|
+
const tplEnv = path.resolve(__dirname, '../.env.example')
|
|
35
|
+
fs.copyFileSync(tplConfig, path.join(process.cwd(), 'config.js'))
|
|
36
|
+
fs.copyFileSync(tplEnv, path.join(process.cwd(), '.env'))
|
|
37
|
+
console.log('✅ 已生成 config.js')
|
|
38
|
+
console.log('✅ 已生成 .env')
|
|
39
|
+
})
|
|
40
|
+
|
|
29
41
|
program
|
|
30
42
|
.command('watch:page')
|
|
31
43
|
.description('监听截图,自动生成完整的增删改查页面')
|
package/package.json
CHANGED
package/src/services/llm.js
CHANGED
|
@@ -7,13 +7,22 @@ const apiPrompt = require('../prompts/watch-api.js')
|
|
|
7
7
|
const { UI_DESIGNER, API_DESIGNER, MOCK_DESIGNER } = require('../prompts/system.js')
|
|
8
8
|
|
|
9
9
|
const config = getConfig()
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
let client = null
|
|
12
|
+
|
|
13
|
+
const getOpenAI = () => {
|
|
14
|
+
if (!client) {
|
|
15
|
+
client = new OpenAI({ apiKey: process.env.API_KEY, baseURL: process.env.BASE_URL })
|
|
16
|
+
}
|
|
17
|
+
return client
|
|
18
|
+
}
|
|
11
19
|
|
|
12
20
|
const askAI = async (model, messages, retryCount = 0) => {
|
|
13
21
|
|
|
14
22
|
if (retryCount > 3) throw new Error('AI 重试次数耗尽,请检查网络或图片')
|
|
15
23
|
|
|
16
24
|
try {
|
|
25
|
+
const openai = getOpenAI()
|
|
17
26
|
const response = await openai.chat.completions.create({ model, messages, response_format: { type: 'json_object' } })
|
|
18
27
|
let raw = response.choices[0].message.content.trim()
|
|
19
28
|
raw = raw.replace(/^```json\n?/, '').replace(/\n?```$/, '')
|