mirror of
https://github.com/LLM-Red-Team/glm-free-api.git
synced 2024-11-01 07:59:24 +08:00
优化非流式搜索结果展示
This commit is contained in:
parent
cb044beae0
commit
53f3365872
@ -731,6 +731,7 @@ async function receiveStream(stream: any): Promise<any> {
|
|||||||
let codeTemp = "";
|
let codeTemp = "";
|
||||||
let lastExecutionOutput = "";
|
let lastExecutionOutput = "";
|
||||||
let textOffset = 0;
|
let textOffset = 0;
|
||||||
|
let refContent = '';
|
||||||
const parser = createParser((event) => {
|
const parser = createParser((event) => {
|
||||||
try {
|
try {
|
||||||
if (event.type !== "event") return;
|
if (event.type !== "event") return;
|
||||||
@ -772,14 +773,9 @@ async function receiveStream(stream: any): Promise<any> {
|
|||||||
meta_data &&
|
meta_data &&
|
||||||
_.isArray(meta_data.metadata_list)
|
_.isArray(meta_data.metadata_list)
|
||||||
) {
|
) {
|
||||||
const searchText =
|
refContent = meta_data.metadata_list.reduce((meta, v) => {
|
||||||
meta_data.metadata_list.reduce(
|
return meta + `${v.title} - ${v.url}\n`;
|
||||||
(meta, v) => meta + `检索 ${v.title}(${v.url}) ...`,
|
}, refContent);
|
||||||
""
|
|
||||||
) + "\n";
|
|
||||||
textOffset += searchText.length;
|
|
||||||
toolCall = true;
|
|
||||||
return innerStr + searchText;
|
|
||||||
} else if (
|
} else if (
|
||||||
type == "image" &&
|
type == "image" &&
|
||||||
_.isArray(image) &&
|
_.isArray(image) &&
|
||||||
@ -839,7 +835,7 @@ async function receiveStream(stream: any): Promise<any> {
|
|||||||
data.choices[0].message.content += chunk;
|
data.choices[0].message.content += chunk;
|
||||||
} else {
|
} else {
|
||||||
data.choices[0].message.content =
|
data.choices[0].message.content =
|
||||||
data.choices[0].message.content.replace(/【\d+†来源】/g, "");
|
data.choices[0].message.content.replace(/【\d+†(来源|source)】/g, "") + (refContent ? `\n\n搜索结果来自:\n${refContent.replace(/\n$/, '')}` : '');
|
||||||
resolve(data);
|
resolve(data);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user