Skip to content

Commit 768f3d5

Browse files
committed
feat(gpt-runner-shared): add json schema auto generate
1 parent 1c8bde4 commit 768f3d5

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

packages/gpt-runner-shared/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"dist"
5353
],
5454
"scripts": {
55-
"build": "unbuild",
55+
"build": "unbuild && pnpm build:json-schema",
56+
"build:json-schema": "pnpm esno ./scripts/zod-to-json-schema.ts",
5657
"stub": "unbuild --stub"
5758
},
5859
"peerDependencies": {
@@ -83,4 +84,4 @@
8384
"@types/ip": "^1.1.0",
8485
"express": "^4.18.2"
8586
}
86-
}
87+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { zodToJsonSchema } from 'zod-to-json-schema'
2+
import { SingleFileConfigSchema, UserConfigSchema } from '../src/common'
3+
import { FileUtils, PathUtils } from '../src/node'
4+
5+
const userConfigJsonSchema = zodToJsonSchema(UserConfigSchema)
6+
const singleFileJsonSchema = zodToJsonSchema(SingleFileConfigSchema)
7+
8+
interface JsonSchemaFile {
9+
fileName: string
10+
content: string
11+
}
12+
async function generateJsonSchemaFile() {
13+
const jsonSchemaFiles: JsonSchemaFile[] = [
14+
{
15+
fileName: 'user-config.json',
16+
content: JSON.stringify(userConfigJsonSchema, null, 2),
17+
},
18+
{
19+
fileName: 'single-file-config.json',
20+
content: JSON.stringify(singleFileJsonSchema, null, 2),
21+
},
22+
]
23+
24+
for (const { fileName, content } of jsonSchemaFiles) {
25+
try {
26+
await FileUtils.writeFile({
27+
filePath: PathUtils.resolve(__dirname, `../dist/json-schema/${fileName}`),
28+
content,
29+
valid: false,
30+
})
31+
32+
console.log(`${fileName} written successfully`)
33+
}
34+
catch (e) {
35+
console.error(`${fileName} could not be written: ${e}`)
36+
}
37+
}
38+
}
39+
40+
generateJsonSchemaFile().then(() => {
41+
console.log('generateJsonSchemaFile done')
42+
}).catch((e) => {
43+
console.error('generateJsonSchemaFile error:', e)
44+
})

packages/gpt-runner-shared/src/common/zod/config.zod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const OpenaiConfigSchema = OpenaiBaseConfigSchema.extend({
3232

3333
export const UserConfigSchema = z.object({
3434
model: OpenaiConfigSchema.optional(),
35-
rootPath: z.string().optional().default(() => process.cwd()),
35+
rootPath: z.string().optional(),
3636
exts: z.array(z.string()).optional().default(['.gpt.md']),
3737
includes: FilterPatternSchema.optional().default(null),
3838
excludes: FilterPatternSchema.optional().default(null),

playground/scripts/gpt/frontend-eng.gpt.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
```json
22
{
3-
"title": "common/前端工程师"
3+
"title": "common/前端工程师",
4+
"model": {
5+
"temperature": 0
6+
}
47
}
58
```
69

710
# System Prompt
811

912
#01 你充当前端开发专家。
1013
#02 user 将提供一些关于前端代码问题的具体信息,而你的工作就是想出为 user 解决问题的策略。这可能包括建议代码、代码逻辑思路策略。
11-
#03 你如果想要增删改文件,应该需要告诉 user 文件的路径,以及你想要增删改的内容。
14+
#03 你如果想要增删改文件,应该需要告诉 user 文件的完整路径,以及你想要增删改的内容。
15+
#04 你的代码应该遵循 SOLID and KISS and DRY principles
16+
#05 你应该一步步思考完再作答
17+
#06 你应该非常细心,不要遗漏 user 提问的任何信息或需求,回答要完整
1218

1319
# User Prompt
1420

0 commit comments

Comments
 (0)