处理token统计为0导致部分客户端无法识别问题

This commit is contained in:
Vinlic 2024-03-17 02:23:29 +08:00
parent e530317486
commit eef674eac8
3 changed files with 18 additions and 14 deletions

View File

@ -231,9 +231,9 @@ Authorization: Bearer [refresh_token]
} }
], ],
"usage": { "usage": {
"prompt_tokens": 0, "prompt_tokens": 1,
"completion_tokens": 0, "completion_tokens": 1,
"total_tokens": 0 "total_tokens": 2
}, },
"created": 1710152062 "created": 1710152062
} }
@ -293,9 +293,9 @@ Authorization: Bearer [refresh_token]
} }
], ],
"usage": { "usage": {
"prompt_tokens": 0, "prompt_tokens": 1,
"completion_tokens": 0, "completion_tokens": 1,
"total_tokens": 0 "total_tokens": 2
}, },
"created": 100920 "created": 100920
} }
@ -357,9 +357,9 @@ Authorization: Bearer [refresh_token]
} }
], ],
"usage": { "usage": {
"prompt_tokens": 0, "prompt_tokens": 1,
"completion_tokens": 0, "completion_tokens": 1,
"total_tokens": 0 "total_tokens": 2
}, },
"created": 1710123627 "created": 1710123627
} }
@ -382,4 +382,8 @@ tcp_nopush on;
tcp_nodelay on; tcp_nodelay on;
# 设置保持连接的超时时间这里设置为120秒。如果在这段时间内客户端和服务器之间没有进一步的通信连接将被关闭。 # 设置保持连接的超时时间这里设置为120秒。如果在这段时间内客户端和服务器之间没有进一步的通信连接将被关闭。
keepalive_timeout 120; keepalive_timeout 120;
``` ```
### Token统计
由于推理侧不再kimi-free-api因此token不可统计将以固定数字返回。

View File

@ -1,6 +1,6 @@
{ {
"name": "kimi-free-api", "name": "kimi-free-api",
"version": "0.0.13", "version": "0.0.14",
"description": "Kimi Free API Server", "description": "Kimi Free API Server",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -506,7 +506,7 @@ function checkResult(result: AxiosResponse, refreshToken: string) {
*/ */
async function receiveStream(convId: string, stream: any) { async function receiveStream(convId: string, stream: any) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// 第一条消息初始化 // 消息初始化
const data = { const data = {
id: convId, id: convId,
model: MODEL_NAME, model: MODEL_NAME,
@ -514,7 +514,7 @@ async function receiveStream(convId: string, stream: any) {
choices: [ choices: [
{ index: 0, message: { role: 'assistant', content: '' }, finish_reason: 'stop' } { index: 0, message: { role: 'assistant', content: '' }, finish_reason: 'stop' }
], ],
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 }, usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
created: util.unixTimestamp() created: util.unixTimestamp()
}; };
let refContent = ''; let refContent = '';
@ -612,7 +612,7 @@ function createTransStream(convId: string, stream: any, endCallback?: Function)
} : {}, finish_reason: 'stop' } : {}, finish_reason: 'stop'
} }
], ],
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 }, usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
created created
})}\n\n`; })}\n\n`;
!transStream.closed && transStream.write(data); !transStream.closed && transStream.write(data);