Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion bricks/ai/src/chat-view/ChatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ export class ChatService {
async chat(msg: string | ChatBody): Promise<void> {
this.#ctrl = new AbortController();
let hadMatchMessage = false;
let hadUsefulMessage = false;
this.#chatting = true;
await fetchEventSource(
`${getBasePath()}api/gateway/[email protected]/api/aiops_chat/v1/chat/completions`,
Expand Down Expand Up @@ -423,9 +424,24 @@ export class ChatService {
const { data } = msg;
hadMatchMessage = true;
if (data === "[DONE]") {
if (!hadUsefulMessage) {
this.enqueue({
topic: "add",
message: {
created: moment().format("YYYY-MM-DD HH:mm:ss"),
delta: {
role: "assistant",
content: "",
},
agentId: this.#agentId,
robotId: this.#robotId,
},
});
}
this.#ctrl!.abort();
return;
}
hadUsefulMessage = true;
let result = {} as SSEMessageItem;
try {
result = JSON.parse(data);
Expand Down Expand Up @@ -538,7 +554,7 @@ export class ChatService {

stop() {
clearTimeout(this.#emitTimer);
this.#ctrl && this.#ctrl?.abort();
this.#ctrl?.abort();
this.#chatting = false;
this.#emitTimer = undefined;
this.#isStartEmitEvent = false;
Expand Down