Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2481a76

Browse files
feat: improve
- fix image parts - add bodyLimit configure
1 parent 9f5f295 commit 2481a76

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,4 @@ genai.config.json
134134

135135
/output
136136
/gaoas_*.zip
137+
tmp_*.*

‎.vscode/launch.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "run main.ts",
6+
"type": "node",
7+
"request": "launch",
8+
"program": "./src/main.ts",
9+
"runtimeExecutable": "tsx",
10+
"console": "integratedTerminal",
11+
"internalConsoleOptions": "neverOpen",
12+
"skipFiles": ["<node_internals>/**", "${workspaceFolder}/node_modules/**"]
13+
}
14+
]
15+
}

‎src/args.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const configJson = JSON.parse(fs.readFileSync(config, "utf8")) as {
3333
log?: boolean;
3434
};
3535
};
36+
bodyLimit?: number;
3637
};
3738

3839
if (configJson.api_key === "") {

‎src/main.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import v1_embeddings from "./v1/embeddings";
2121

2222
import { configJson } from "./args";
2323

24+
const s_10mb = 10 * 1024 * 1024;
2425
const app = fastify({
2526
logger: true,
27+
bodyLimit: Math.max(configJson?.bodyLimit ?? 0, s_10mb) ?? 1024 * 1024 * 50, // 50MB
2628
});
2729
app.setValidatorCompiler(validatorCompiler);
2830
app.setSerializerCompiler(serializerCompiler);

‎src/v1/chat/completions.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const CHAT_COMPLETION_SCHEMA = z.object({
5252
text: z.string(),
5353
}),
5454
z.object({
55-
type: z.literal("image"),
55+
type: z.literal("image_url"),
5656
image_url: z.object({
5757
url: z.string(),
5858
}),
@@ -257,7 +257,7 @@ class ChatCompletionsHandler {
257257
text: y.text,
258258
};
259259
}
260-
if (y.type === "image") {
260+
if (y.type === "image_url") {
261261
let url = y.image_url.url;
262262
if (url.startsWith("http")) {
263263
const image = await fetch(y.image_url.url);
@@ -286,6 +286,7 @@ class ChatCompletionsHandler {
286286
};
287287
}
288288
}
289+
// NOTE: 目前不支持音频,因为不知道怎么测也不通用
289290
throw new Error(`not support content type: ${y.type}`);
290291
})
291292
);
@@ -401,6 +402,10 @@ class ChatCompletionsHandler {
401402

402403
private async handleStream() {
403404
const payload = await this.buildGeneratePayload();
405+
// writeFileSync(
406+
// "./tmp_payload.json",
407+
// JSON.stringify({ ...payload, id: this.id }, null, 2)
408+
// );
404409
const abortSignal = new AbortController();
405410
const result = await payload.gen_model.generateContentStream(
406411
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /