From 85648636765840c3d725672fc8fdd2278de57d6f Mon Sep 17 00:00:00 2001 From: mutugiii Date: Mon, 29 Apr 2024 14:31:27 +0300 Subject: [PATCH 1/4] Logging the streaming var --- chatapi/src/index.ts | 3 ++- src/app/chat/chat-window/chat-window.component.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/chatapi/src/index.ts b/chatapi/src/index.ts index 9835fc3ac6..4c4c39b747 100644 --- a/chatapi/src/index.ts +++ b/chatapi/src/index.ts @@ -47,7 +47,8 @@ wss.on('connection', (ws) => { })); } } catch (error: any) { - ws.send(`Error: ${error.message}`); + console.log(error); + ws.send(`Error: ${error.message}: Cannot connect to the streaming endpoint`); } }); diff --git a/src/app/chat/chat-window/chat-window.component.ts b/src/app/chat/chat-window/chat-window.component.ts index da08ef62df..5c3b22209a 100644 --- a/src/app/chat/chat-window/chat-window.component.ts +++ b/src/app/chat/chat-window/chat-window.component.ts @@ -192,6 +192,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy { this.data = { ...this.data, content, aiProvider: this.provider }; this.setSelectedConversation(); + console.log(this.streaming); if (this.streaming) { this.conversations.push({ role: 'user', query: content, response: '' }); From 4bebfd12f31d434c96c7252448dd975a41c6a211 Mon Sep 17 00:00:00 2001 From: mutugiii Date: Mon, 29 Apr 2024 15:07:15 +0300 Subject: [PATCH 2/4] Reorder streaming status calls --- .../chat/chat-window/chat-window.component.ts | 23 +++++++++++------- src/app/shared/chat.service.ts | 24 ++++++++++--------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/app/chat/chat-window/chat-window.component.ts b/src/app/chat/chat-window/chat-window.component.ts index 5c3b22209a..fbb721269d 100644 --- a/src/app/chat/chat-window/chat-window.component.ts +++ b/src/app/chat/chat-window/chat-window.component.ts @@ -46,10 +46,8 @@ export class ChatWindowComponent implements OnInit, OnDestroy { this.createForm(); this.subscribeToNewChatSelected(); this.subscribeToSelectedConversation(); - this.initializeChatStream(); - this.initializeErrorStream(); this.subscribeToAIService(); - this.isStreamingEnabled(); + this.checkStreamingStatusAndInitialize(); } ngOnDestroy() { @@ -90,11 +88,6 @@ export class ChatWindowComponent implements OnInit, OnDestroy { })); } - isStreamingEnabled() { - const configuration = this.stateService.configuration; - this.streaming = configuration.streaming; - } - createForm() { this.promptForm = this.formBuilder.group({ prompt: [ '', CustomValidators.required ], @@ -137,6 +130,20 @@ export class ChatWindowComponent implements OnInit, OnDestroy { } } + checkStreamingStatusAndInitialize() { + this.isStreamingEnabled(); + if (this.streaming) { + this.chatService.initializeWebSocket(); + this.initializeChatStream(); + this.initializeErrorStream(); + } + } + + isStreamingEnabled() { + const configuration = this.stateService.configuration; + this.streaming = configuration.streaming; + } + initializeErrorStream() { // Subscribe to WebSocket error messages this.chatService.getErrorStream().subscribe((errorMessage) => { diff --git a/src/app/shared/chat.service.ts b/src/app/shared/chat.service.ts index e70811d37e..4769500c71 100644 --- a/src/app/shared/chat.service.ts +++ b/src/app/shared/chat.service.ts @@ -30,19 +30,21 @@ import { CouchService } from '../shared/couchdb.service'; constructor( private httpClient: HttpClient, private couchService: CouchService - ) { - this.socket = new WebSocket('ws' + this.baseUrl.slice(4)); - - this.socket.onerror = (error) => { - this.errorSubject.next('WebSocket error'); - }; - - // Listen for messages - this.socket.addEventListener('message', (event) => { - this.chatStreamSubject.next(event.data); - }); + ) { } + + initializeWebSocket() { + if (!this.socket || this.socket.readyState === WebSocket.CLOSED) { + this.socket = new WebSocket('ws' + this.baseUrl.slice(4)); + this.socket.onerror = (error) => { + this.errorSubject.next('WebSocket error'); + }; + this.socket.addEventListener('message', (event) => { + this.chatStreamSubject.next(event.data); + }); + } } + fetchAIProviders() { return this.httpClient.get(`${this.baseUrl}/checkproviders`); } From 235db95e102c7aa44d2ee58f6dd67441046256f3 Mon Sep 17 00:00:00 2001 From: mutugiii Date: Mon, 29 Apr 2024 22:59:15 +0300 Subject: [PATCH 3/4] Cleanup --- chatapi/src/index.ts | 3 +-- src/app/chat/chat-window/chat-window.component.ts | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/chatapi/src/index.ts b/chatapi/src/index.ts index 4c4c39b747..bc9cd72ac3 100644 --- a/chatapi/src/index.ts +++ b/chatapi/src/index.ts @@ -47,8 +47,7 @@ wss.on('connection', (ws) => { })); } } catch (error: any) { - console.log(error); - ws.send(`Error: ${error.message}: Cannot connect to the streaming endpoint`); + ws.send(`${error.message}: Cannot connect to the streaming endpoint`); } }); diff --git a/src/app/chat/chat-window/chat-window.component.ts b/src/app/chat/chat-window/chat-window.component.ts index fbb721269d..8f5a00051c 100644 --- a/src/app/chat/chat-window/chat-window.component.ts +++ b/src/app/chat/chat-window/chat-window.component.ts @@ -199,7 +199,6 @@ export class ChatWindowComponent implements OnInit, OnDestroy { this.data = { ...this.data, content, aiProvider: this.provider }; this.setSelectedConversation(); - console.log(this.streaming); if (this.streaming) { this.conversations.push({ role: 'user', query: content, response: '' }); From 119aea6804721c9ce76608269b2082ca78dffc8c Mon Sep 17 00:00:00 2001 From: dogi Date: Fri, 3 May 2024 15:33:16 -0400 Subject: [PATCH 4/4] Update package.json --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8448617fb0..c945250c11 100755 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "planet", "license": "AGPL-3.0", - "version": "0.14.27", + "version": "0.14.29", "myplanet": { - "latest": "v0.14.98", - "min": "v0.14.0" + "latest": "v0.15.10", + "min": "v0.14.10" }, "scripts": { "ng": "ng",