-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spa): displaying the bot's reply as a streaming message
- Loading branch information
1 parent
399a1d2
commit 9252292
Showing
5 changed files
with
86 additions
and
18 deletions.
There are no files selected for viewing
33 changes: 26 additions & 7 deletions
33
apps/spa/src/app/modules/+chat/shared/chat-gateway.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,41 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ChatEvents } from './chat.model'; | ||
import io from 'socket.io-client'; | ||
import { ChatCallDto } from '@boldare/openai-assistant'; | ||
import { | ||
ChatCallDto, | ||
TextCreatedPayload, TextDeltaPayload, TextDonePayload | ||
} from '@boldare/openai-assistant'; | ||
import { Observable } from 'rxjs'; | ||
import { environment } from '../../../../environments/environment'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ChatGatewayService { | ||
private socket = io(environment.websocketUrl); | ||
|
||
sendMessage(payload: ChatCallDto): void { | ||
watchEvent<T>(event: ChatEvents): Observable<T> { | ||
return new Observable<T>(observer => { | ||
this.socket.on(event, data => observer.next(data)); | ||
return () => this.socket.disconnect(); | ||
}); | ||
} | ||
|
||
callStart(payload: ChatCallDto): void { | ||
this.socket.emit(ChatEvents.CallStart, payload); | ||
} | ||
|
||
getMessages(): Observable<ChatCallDto> { | ||
return new Observable<ChatCallDto>(observer => { | ||
this.socket.on(ChatEvents.CallDone, data => observer.next(data)); | ||
return () => this.socket.disconnect(); | ||
}); | ||
callDone(): Observable<ChatCallDto> { | ||
return this.watchEvent(ChatEvents.CallDone); | ||
} | ||
|
||
textCreated(): Observable<TextCreatedPayload> { | ||
return this.watchEvent(ChatEvents.TextCreated); | ||
} | ||
|
||
textDelta(): Observable<TextDeltaPayload> { | ||
return this.watchEvent(ChatEvents.TextDelta); | ||
} | ||
|
||
textDone(): Observable<TextDonePayload> { | ||
return this.watchEvent(ChatEvents.TextDone); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters