@templmf/temp-solf-lmf 0.0.65 → 0.0.66
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/guanwang.zip +0 -0
- package/package.json +1 -1
- package/.roo/system-prompt-code +0 -0
- package/gateway/src/ai/ai.controller.ts +0 -42
- package/gateway/src/ai/ai.module.ts +0 -10
- package/gateway/src/ai/ai.service.ts +0 -16
- package/gateway/src/ai/providers/openai.provider.ts +0 -104
- package/gateway/src/app.module.ts +0 -7
- package/gateway/src/main.ts +0 -19
- package/gateway/src/package.json1 +0 -28
- package//344/274/230/345/214/226/347/232/204prompt.md +0 -48
- package//345/244/207/344/273/275/346/217/220/347/244/272.txt +0 -2
package/guanwang.zip
ADDED
|
Binary file
|
package/package.json
CHANGED
package/.roo/system-prompt-code
DELETED
|
File without changes
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Controller,
|
|
3
|
-
Post,
|
|
4
|
-
Param,
|
|
5
|
-
Req,
|
|
6
|
-
Res,
|
|
7
|
-
} from '@nestjs/common'
|
|
8
|
-
import { Request, Response } from 'express'
|
|
9
|
-
import { AiService } from './ai.service'
|
|
10
|
-
|
|
11
|
-
@Controller('/aiapi')
|
|
12
|
-
export class AiController {
|
|
13
|
-
constructor(private readonly aiService: AiService) {}
|
|
14
|
-
|
|
15
|
-
@Post('/:model/v1/chat/completions')
|
|
16
|
-
async chat(
|
|
17
|
-
@Param('model') model: string,
|
|
18
|
-
@Req() req: Request,
|
|
19
|
-
@Res() res: Response,
|
|
20
|
-
) {
|
|
21
|
-
const body = req.body
|
|
22
|
-
const isStream = body.stream === true
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
if (isStream) {
|
|
26
|
-
return await this.aiService.streamChat(model, body, res)
|
|
27
|
-
} else {
|
|
28
|
-
const data = await this.aiService.chat(model, body)
|
|
29
|
-
return res.json(data)
|
|
30
|
-
}
|
|
31
|
-
} catch (err: any) {
|
|
32
|
-
console.error('controller error:', err)
|
|
33
|
-
|
|
34
|
-
res.status(500).json({
|
|
35
|
-
error: {
|
|
36
|
-
message: err.message,
|
|
37
|
-
type: 'gateway_error',
|
|
38
|
-
},
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Module } from '@nestjs/common'
|
|
2
|
-
import { AiController } from './ai.controller'
|
|
3
|
-
import { AiService } from './ai.service'
|
|
4
|
-
import { OpenAIProvider } from './providers/openai.provider'
|
|
5
|
-
|
|
6
|
-
@Module({
|
|
7
|
-
controllers: [AiController],
|
|
8
|
-
providers: [AiService, OpenAIProvider],
|
|
9
|
-
})
|
|
10
|
-
export class AiModule {}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common'
|
|
2
|
-
import { Response } from 'express'
|
|
3
|
-
import { OpenAIProvider } from './providers/openai.provider'
|
|
4
|
-
|
|
5
|
-
@Injectable()
|
|
6
|
-
export class AiService {
|
|
7
|
-
constructor(private readonly openai: OpenAIProvider) {}
|
|
8
|
-
|
|
9
|
-
async chat(model: string, body: any) {
|
|
10
|
-
return this.openai.chat(model, body)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async streamChat(model: string, body: any, res: Response) {
|
|
14
|
-
return this.openai.streamChat(model, body, res)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common'
|
|
2
|
-
import { Response } from 'express'
|
|
3
|
-
|
|
4
|
-
@Injectable()
|
|
5
|
-
export class OpenAIProvider {
|
|
6
|
-
private baseUrl = 'https://api.openai.com/v1/chat/completions'
|
|
7
|
-
|
|
8
|
-
// ==========
|
|
9
|
-
// 超时控制
|
|
10
|
-
// ==========
|
|
11
|
-
private fetchWithTimeout(url: string, options: any, timeout = 30000) {
|
|
12
|
-
const controller = new AbortController()
|
|
13
|
-
const id = setTimeout(() => controller.abort(), timeout)
|
|
14
|
-
|
|
15
|
-
return fetch(url, {
|
|
16
|
-
...options,
|
|
17
|
-
signal: controller.signal,
|
|
18
|
-
}).finally(() => clearTimeout(id))
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// ==========
|
|
22
|
-
// 非流式
|
|
23
|
-
// ==========
|
|
24
|
-
async chat(model: string, body: any) {
|
|
25
|
-
const resp = await this.fetchWithTimeout(this.baseUrl, {
|
|
26
|
-
method: 'POST',
|
|
27
|
-
headers: {
|
|
28
|
-
'Content-Type': 'application/json',
|
|
29
|
-
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
|
|
30
|
-
},
|
|
31
|
-
body: JSON.stringify({
|
|
32
|
-
...body,
|
|
33
|
-
model,
|
|
34
|
-
}),
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
const text = await resp.text()
|
|
38
|
-
|
|
39
|
-
// ✅ 错误透传
|
|
40
|
-
if (!resp.ok) {
|
|
41
|
-
throw new Error(text)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return JSON.parse(text)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ==========
|
|
48
|
-
// Streaming(关键)
|
|
49
|
-
// ==========
|
|
50
|
-
async streamChat(model: string, body: any, res: Response) {
|
|
51
|
-
const resp = await this.fetchWithTimeout(this.baseUrl, {
|
|
52
|
-
method: 'POST',
|
|
53
|
-
headers: {
|
|
54
|
-
'Content-Type': 'application/json',
|
|
55
|
-
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
|
|
56
|
-
},
|
|
57
|
-
body: JSON.stringify({
|
|
58
|
-
...body,
|
|
59
|
-
model,
|
|
60
|
-
stream: true,
|
|
61
|
-
}),
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
// ❗上游直接报错(不是流)
|
|
65
|
-
if (!resp.ok) {
|
|
66
|
-
const errText = await resp.text()
|
|
67
|
-
res.status(resp.status).json({
|
|
68
|
-
error: {
|
|
69
|
-
message: errText,
|
|
70
|
-
type: 'upstream_error',
|
|
71
|
-
},
|
|
72
|
-
})
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// ✅ SSE 头(必须)
|
|
77
|
-
res.writeHead(200, {
|
|
78
|
-
'Content-Type': 'text/event-stream',
|
|
79
|
-
'Cache-Control': 'no-cache, no-transform',
|
|
80
|
-
Connection: 'keep-alive',
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
const reader = resp.body?.getReader()
|
|
84
|
-
|
|
85
|
-
if (!reader) {
|
|
86
|
-
res.end()
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
while (true) {
|
|
92
|
-
const { done, value } = await reader.read()
|
|
93
|
-
if (done) break
|
|
94
|
-
|
|
95
|
-
// ✅ 直接透传(不要解析!)
|
|
96
|
-
res.write(value)
|
|
97
|
-
}
|
|
98
|
-
} catch (err) {
|
|
99
|
-
console.error('stream error:', err)
|
|
100
|
-
} finally {
|
|
101
|
-
res.end()
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
package/gateway/src/main.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { NestFactory } from '@nestjs/core'
|
|
2
|
-
import { AppModule } from './app.module'
|
|
3
|
-
|
|
4
|
-
async function bootstrap() {
|
|
5
|
-
const app = await NestFactory.create(AppModule)
|
|
6
|
-
|
|
7
|
-
// ✅ CORS(解决跨域)
|
|
8
|
-
app.enableCors({
|
|
9
|
-
origin: true,
|
|
10
|
-
credentials: true,
|
|
11
|
-
methods: ['GET', 'POST', 'OPTIONS'],
|
|
12
|
-
allowedHeaders: ['Content-Type', 'Authorization'],
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
await app.listen(3000)
|
|
16
|
-
console.log('AI Gateway running on http://localhost:3000')
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
bootstrap()
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ai-gateway",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "AI Gateway for OpenAI / Qwen",
|
|
5
|
-
"private": true,
|
|
6
|
-
"scripts": {
|
|
7
|
-
"start": "node dist/main.js",
|
|
8
|
-
"start:dev": "nest start --watch",
|
|
9
|
-
"build": "nest build",
|
|
10
|
-
"start:prod": "node dist/main.js"
|
|
11
|
-
},
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"@nestjs/common": "^10.0.0",
|
|
14
|
-
"@nestjs/core": "^10.0.0",
|
|
15
|
-
"@nestjs/platform-express": "^10.0.0",
|
|
16
|
-
"reflect-metadata": "^0.1.13",
|
|
17
|
-
"rxjs": "^7.8.0"
|
|
18
|
-
},
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"@nestjs/cli": "^10.0.0",
|
|
21
|
-
"@nestjs/schematics": "^10.0.0",
|
|
22
|
-
"@nestjs/testing": "^10.0.0",
|
|
23
|
-
"@types/express": "^4.17.21",
|
|
24
|
-
"@types/node": "^20.0.0",
|
|
25
|
-
"typescript": "^5.0.0",
|
|
26
|
-
"ts-node": "^10.9.1"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
You are Roo, a skilled software engineer.
|
|
2
|
-
|
|
3
|
-
You can read and write files to help complete tasks.
|
|
4
|
-
|
|
5
|
-
====
|
|
6
|
-
|
|
7
|
-
TOOL USE
|
|
8
|
-
|
|
9
|
-
You may use tools when needed. Use XML format.
|
|
10
|
-
|
|
11
|
-
<tool_name>
|
|
12
|
-
<param>value</param>
|
|
13
|
-
</tool_name>
|
|
14
|
-
|
|
15
|
-
====
|
|
16
|
-
|
|
17
|
-
TOOLS
|
|
18
|
-
|
|
19
|
-
read_file:
|
|
20
|
-
- Read file content
|
|
21
|
-
- param: path
|
|
22
|
-
|
|
23
|
-
Example:
|
|
24
|
-
<read_file>
|
|
25
|
-
<path>src/index.js</path>
|
|
26
|
-
</read_file>
|
|
27
|
-
|
|
28
|
-
write_to_file:
|
|
29
|
-
- Write full file content (overwrite or create)
|
|
30
|
-
- params:
|
|
31
|
-
- path
|
|
32
|
-
- content
|
|
33
|
-
|
|
34
|
-
Example:
|
|
35
|
-
<write_to_file>
|
|
36
|
-
<path>src/index.js</path>
|
|
37
|
-
<content>
|
|
38
|
-
console.log("hello")
|
|
39
|
-
</content>
|
|
40
|
-
</write_to_file>
|
|
41
|
-
|
|
42
|
-
====
|
|
43
|
-
|
|
44
|
-
RULES
|
|
45
|
-
|
|
46
|
-
- You can understand images and convert them into code or text files
|
|
47
|
-
- Keep responses concise
|
|
48
|
-
- Prefer writing complete files when generating code
|