forked from Shinonome/dots-hyprland
ai: add thinking block for online deepseek r1 (#1254)
This commit is contained in:
@@ -105,6 +105,8 @@ class GPTMessage extends Service {
|
|||||||
|
|
||||||
_role = '';
|
_role = '';
|
||||||
_content = '';
|
_content = '';
|
||||||
|
_hasReasoningContent = false;
|
||||||
|
_parsedReasoningContent = false;
|
||||||
_lastContentLength = 0;
|
_lastContentLength = 0;
|
||||||
_thinking;
|
_thinking;
|
||||||
_done = false;
|
_done = false;
|
||||||
@@ -112,6 +114,8 @@ class GPTMessage extends Service {
|
|||||||
constructor(role, content, thinking = true, done = false) {
|
constructor(role, content, thinking = true, done = false) {
|
||||||
super();
|
super();
|
||||||
this._role = role;
|
this._role = role;
|
||||||
|
this._hasReasoningContent = false;
|
||||||
|
this._parsedReasoningContent = false;
|
||||||
this._content = content;
|
this._content = content;
|
||||||
this._thinking = thinking;
|
this._thinking = thinking;
|
||||||
this._done = done;
|
this._done = done;
|
||||||
@@ -123,6 +127,18 @@ class GPTMessage extends Service {
|
|||||||
get role() { return this._role }
|
get role() { return this._role }
|
||||||
set role(role) { this._role = role; this.emit('changed') }
|
set role(role) { this._role = role; this.emit('changed') }
|
||||||
|
|
||||||
|
get hasReasoningContent() { return this._hasReasoningContent }
|
||||||
|
set hasReasoningContent(value) {
|
||||||
|
this._hasReasoningContent = value;
|
||||||
|
this.emit('changed')
|
||||||
|
}
|
||||||
|
|
||||||
|
get parsedReasoningContent() { return this._parsedReasoningContent }
|
||||||
|
set parsedReasoningContent(value) {
|
||||||
|
this._parsedReasoningContent = value;
|
||||||
|
this.emit('changed')
|
||||||
|
}
|
||||||
|
|
||||||
get content() { return this._content }
|
get content() { return this._content }
|
||||||
set content(content) {
|
set content(content) {
|
||||||
this._content = content;
|
this._content = content;
|
||||||
@@ -251,8 +267,24 @@ class GPTService extends Service {
|
|||||||
aiResponse.done = true;
|
aiResponse.done = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
aiResponse.addDelta(result.choices[0].delta.content);
|
|
||||||
// print(result.choices[0])
|
// aiResponse.addDelta(result.choices[0].delta.content);
|
||||||
|
if (!result.choices[0].delta.content && result.choices[0].delta.reasoning_content) {
|
||||||
|
if (!aiResponse.hasReasoningContent) {
|
||||||
|
aiResponse.hasReasoningContent = true;
|
||||||
|
aiResponse.addDelta(`<think>\n${result.choices[0].delta.reasoning_content}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
aiResponse.addDelta(`<think>\n${result.choices[0].delta.reasoning_content}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (aiResponse.hasReasoningContent) {
|
||||||
|
aiResponse.parsedReasoningContent = true;
|
||||||
|
aiResponse.addDelta(`\n</think>\n`);
|
||||||
|
}
|
||||||
|
aiResponse.addDelta(result.choices[0].delta.content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
aiResponse.addDelta(line + '\n');
|
aiResponse.addDelta(line + '\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user