mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 18:26:05 +08:00
feat(core): convert ai think tag to markdown divider (#10459)
Support issue [AF-2282](https://linear.app/affine-design/issue/AF-2282).
This commit is contained in:
@@ -221,11 +221,12 @@ export class PerplexityProvider implements CopilotTextToTextProvider {
|
|||||||
message: data.detail[0].msg || 'Unexpected perplexity response',
|
message: data.detail[0].msg || 'Unexpected perplexity response',
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const parser = new CitationParser();
|
const citationParser = new CitationParser();
|
||||||
const { content } = data.choices[0].message;
|
const { content } = data.choices[0].message;
|
||||||
const { citations } = data;
|
const { citations } = data;
|
||||||
let result = parser.parse(content, citations);
|
let result = content.replaceAll(/<\/?think>\n/g, '\n---\n');
|
||||||
result += parser.end();
|
result = citationParser.parse(result, citations);
|
||||||
|
result += citationParser.end();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
@@ -264,7 +265,7 @@ export class PerplexityProvider implements CopilotTextToTextProvider {
|
|||||||
params
|
params
|
||||||
);
|
);
|
||||||
if (response.body) {
|
if (response.body) {
|
||||||
const parser = new CitationParser();
|
const citationParser = new CitationParser();
|
||||||
const provider = this.type;
|
const provider = this.type;
|
||||||
const eventStream = response.body
|
const eventStream = response.body
|
||||||
.pipeThrough(new TextDecoderStream())
|
.pipeThrough(new TextDecoderStream())
|
||||||
@@ -289,12 +290,13 @@ export class PerplexityProvider implements CopilotTextToTextProvider {
|
|||||||
}
|
}
|
||||||
const { content } = data.choices[0].delta;
|
const { content } = data.choices[0].delta;
|
||||||
const { citations } = data;
|
const { citations } = data;
|
||||||
const result = parser.parse(content, citations);
|
let result = content.replaceAll(/<\/?think>\n?/g, '\n---\n');
|
||||||
|
result = citationParser.parse(result, citations);
|
||||||
controller.enqueue(result);
|
controller.enqueue(result);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
flush(controller) {
|
flush(controller) {
|
||||||
controller.enqueue(parser.end());
|
controller.enqueue(citationParser.end());
|
||||||
controller.enqueue(null);
|
controller.enqueue(null);
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user