mirror of
https://github.com/LLM-Red-Team/kimi-free-api.git
synced 2024-12-23 03:29:20 +08:00
commit
38d59e20fc
@ -723,6 +723,7 @@ function checkResult(result: AxiosResponse, refreshToken: string) {
|
|||||||
* @param stream 消息流
|
* @param stream 消息流
|
||||||
*/
|
*/
|
||||||
async function receiveStream(model: string, convId: string, stream: any) {
|
async function receiveStream(model: string, convId: string, stream: any) {
|
||||||
|
let webSearchCount = 0;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 消息初始化
|
// 消息初始化
|
||||||
const data = {
|
const data = {
|
||||||
@ -756,8 +757,10 @@ async function receiveStream(model: string, convId: string, stream: any) {
|
|||||||
resolve(data);
|
resolve(data);
|
||||||
}
|
}
|
||||||
// 处理联网搜索
|
// 处理联网搜索
|
||||||
else if (!silentSearch && result.event == 'search_plus' && result.msg && result.msg.type == 'get_res')
|
else if (!silentSearch && result.event == 'search_plus' && result.msg && result.msg.type == 'get_res'){
|
||||||
refContent += `${result.msg.title} - ${result.msg.url}\n`;
|
webSearchCount += 1;
|
||||||
|
refContent += `【检索 ${webSearchCount}】 [${result.msg.title}](${result.msg.url})\n\n`;
|
||||||
|
}
|
||||||
// else
|
// else
|
||||||
// logger.warn(result.event, result);
|
// logger.warn(result.event, result);
|
||||||
}
|
}
|
||||||
@ -788,6 +791,7 @@ function createTransStream(model: string, convId: string, stream: any, endCallba
|
|||||||
const created = util.unixTimestamp();
|
const created = util.unixTimestamp();
|
||||||
// 创建转换流
|
// 创建转换流
|
||||||
const transStream = new PassThrough();
|
const transStream = new PassThrough();
|
||||||
|
let webSearchCount = 0;
|
||||||
let searchFlag = false;
|
let searchFlag = false;
|
||||||
const silentSearch = model.indexOf('silent_search') != -1;
|
const silentSearch = model.indexOf('silent_search') != -1;
|
||||||
!transStream.closed && transStream.write(`data: ${JSON.stringify({
|
!transStream.closed && transStream.write(`data: ${JSON.stringify({
|
||||||
@ -847,6 +851,7 @@ function createTransStream(model: string, convId: string, stream: any, endCallba
|
|||||||
else if (!silentSearch && result.event == 'search_plus' && result.msg && result.msg.type == 'get_res') {
|
else if (!silentSearch && result.event == 'search_plus' && result.msg && result.msg.type == 'get_res') {
|
||||||
if (!searchFlag)
|
if (!searchFlag)
|
||||||
searchFlag = true;
|
searchFlag = true;
|
||||||
|
webSearchCount += 1;
|
||||||
const data = `data: ${JSON.stringify({
|
const data = `data: ${JSON.stringify({
|
||||||
id: convId,
|
id: convId,
|
||||||
model,
|
model,
|
||||||
@ -854,7 +859,7 @@ function createTransStream(model: string, convId: string, stream: any, endCallba
|
|||||||
choices: [
|
choices: [
|
||||||
{
|
{
|
||||||
index: 0, delta: {
|
index: 0, delta: {
|
||||||
content: `检索 ${result.msg.title} - ${result.msg.url} ...\n`
|
content: `【检索 ${webSearchCount}】 [${result.msg.title}](${result.msg.url})\n`
|
||||||
}, finish_reason: null
|
}, finish_reason: null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user