@yorha2b-lab/autodev 1.0.3 → 1.0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yorha2b-lab/autodev",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "基于视觉大模型的前端(Umi+Antd)全自动 CRUD 代码生成器",
5
5
  "bin": {
6
6
  "autodev": "bin/autodev.js"
@@ -1,13 +1,12 @@
1
1
  const JSON5 = require('json5')
2
2
  const sharp = require('sharp')
3
- const OpenAI = require('openai')
4
3
  const mockPrompt = require('../prompts/mock.js')
5
- const { getConfig } = require('../utils/utils.js')
6
4
  const apiPrompt = require('../prompts/watch-api.js')
5
+ const { getConfig, initOpenAI } = require('../utils/utils.js')
7
6
  const { UI_DESIGNER, API_DESIGNER, MOCK_DESIGNER } = require('../prompts/system.js')
8
7
 
9
8
  const config = getConfig()
10
- const openai = new OpenAI({ apiKey: process.env.API_KEY, baseURL: process.env.BASE_URL })
9
+ const openai = initOpenAI()
11
10
 
12
11
  const askAI = async (model, messages, retryCount = 0) => {
13
12
 
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
+ const OpenAI = require('openai')
3
4
 
4
5
  const getConfig = () => {
5
6
  const localConfigPath = path.join(process.cwd(), 'config.js')
@@ -12,6 +13,10 @@ const getConfig = () => {
12
13
  return config
13
14
  }
14
15
 
16
+ const initOpenAI = () => {
17
+ return new OpenAI({ apiKey: process.env.API_KEY, baseURL: process.env.BASE_URL })
18
+ }
19
+
15
20
  /**
16
21
  * 大模型输出的标准 JSON 无法携带 render: (text) => <Tag> 等箭头函数。
17
22
  * 我们在 Prompt 中要求大模型用 _CODE_ 占位符包裹函数字符串,
@@ -75,4 +80,4 @@ const copyComponents = (options, componentsDir = 'src/components') => {
75
80
  fs.readdirSync(componentsDirectory).forEach(file => fs.copyFileSync(path.join(componentsDirectory, file), path.join(targetDir, file)))
76
81
  }
77
82
 
78
- module.exports = { getConfig, copyHooks, cleanCode, copyComponents, getExistingMenus, generateSmartImports }
83
+ module.exports = { getConfig, copyHooks, cleanCode, initOpenAI, copyComponents, getExistingMenus, generateSmartImports }