sidebar: ai: loading skeleton

This commit is contained in:
end-4
2024-04-14 21:00:52 +07:00
parent 72121dac20
commit 69fdb53c9d
6 changed files with 90 additions and 40 deletions
+7 -7
View File
@@ -62,11 +62,11 @@ class GeminiMessage extends Service {
_role = '';
_parts = [{ text: '' }];
_thinking = false;
_thinking;
_done = false;
_rawData = '';
constructor(role, content, thinking = false, done = false) {
constructor(role, content, thinking = true, done = false) {
super();
this._role = role;
this._parts = [{ text: content }];
@@ -97,8 +97,8 @@ class GeminiMessage extends Service {
get label() { return this._parserState.parsed + this._parserState.stack.join('') }
get thinking() { return this._thinking }
set thinking(thinking) {
this._thinking = thinking;
set thinking(value) {
this._thinking = value;
this.notify('thinking')
this.emit('changed')
}
@@ -116,7 +116,7 @@ class GeminiMessage extends Service {
parseSection() {
if (this._thinking) {
this._thinking = false;
this.thinking = false;
this._parts[0].text = '';
}
const parsedData = JSON.parse(this._rawData);
@@ -273,12 +273,12 @@ class GeminiService extends Service {
}
addMessage(role, message) {
this._messages.push(new GeminiMessage(role, message));
this._messages.push(new GeminiMessage(role, message, false));
this.emit('newMsg', this._messages.length - 1);
}
send(msg) {
this._messages.push(new GeminiMessage('user', msg));
this._messages.push(new GeminiMessage('user', msg, false));
this.emit('newMsg', this._messages.length - 1);
const aiResponse = new GeminiMessage('model', 'thinking...', true, false)
+6 -5
View File
@@ -76,10 +76,10 @@ class GPTMessage extends Service {
_role = '';
_content = '';
_thinking = false;
_thinking;
_done = false;
constructor(role, content, thinking = false, done = false) {
constructor(role, content, thinking = true, done = false) {
super();
this._role = role;
this._content = content;
@@ -103,8 +103,8 @@ class GPTMessage extends Service {
get label() { return this._parserState.parsed + this._parserState.stack.join('') }
get thinking() { return this._thinking }
set thinking(thinking) {
this._thinking = thinking;
set thinking(value) {
this._thinking = value;
this.notify('thinking')
this.emit('changed')
}
@@ -202,6 +202,7 @@ class GPTService extends Service {
}
readResponse(stream, aiResponse) {
aiResponse.thinking = false;
stream.read_line_async(
0, null,
(stream, res) => {
@@ -234,7 +235,7 @@ class GPTService extends Service {
}
send(msg) {
this._messages.push(new GPTMessage('user', msg));
this._messages.push(new GPTMessage('user', msg, false, true));
this.emit('newMsg', this._messages.length - 1);
const aiResponse = new GPTMessage('assistant', 'thinking...', true, false)