Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chat: add streaming option in manager dashboard (fixes #7439) #7440

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/app/chat/chat-sidebar/chat-sidebar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<mat-icon>help_outline</mat-icon>
</button>
<ng-template cdkConnectedOverlay [cdkConnectedOverlayOrigin]="trigger" [cdkConnectedOverlayOpen]="overlayOpen">
<span class="overlay-text" i18n>search through the entire conversation, not just the title</span>
<span class="overlay-text" i18n>Search through the entire conversation, not just the title</span>
</ng-template>
<div>
<mat-button-toggle-group *ngIf="fullTextSearch" [(ngModel)]="searchType" (change)="filterConversations()">
Expand Down
12 changes: 10 additions & 2 deletions src/app/chat/chat-window/chat-window.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ConversationForm, AIProvider } from '../chat.model';
import { ChatService } from '../../shared/chat.service';
import { showFormErrors } from '../../shared/table-helpers';
import { UserService } from '../../shared/user.service';
import { StateService } from '../../shared/state.service';

@Component({
selector: 'planet-chat-window',
Expand All @@ -17,7 +18,7 @@ import { UserService } from '../../shared/user.service';
export class ChatWindowComponent implements OnInit, OnDestroy {
private onDestroy$ = new Subject<void>();
spinnerOn = true;
setStreamOn = false;
streaming: boolean;
disabled = false;
provider: AIProvider;
conversations: any[] = [];
Expand All @@ -37,6 +38,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy {
private changeDetectorRef: ChangeDetectorRef,
private chatService: ChatService,
private formBuilder: FormBuilder,
private stateService: StateService,
private userService: UserService
) {}

Expand All @@ -47,6 +49,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy {
this.initializeChatStream();
this.initializeErrorStream();
this.subscribeToAIService();
this.isStreamingEnabled();
}

ngOnDestroy() {
Expand Down Expand Up @@ -87,6 +90,11 @@ 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 ],
Expand Down Expand Up @@ -185,7 +193,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy {

this.setSelectedConversation();

if (this.setStreamOn) {
if (this.streaming) {
this.conversations.push({ role: 'user', query: content, response: '' });
this.chatService.sendUserInput(this.data);
} else {
Expand Down
10 changes: 10 additions & 0 deletions src/app/manager-dashboard/manager-dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ <h3 i18n *ngIf="showParentList">{{ planetType === 'community' ? 'Nation' : 'Cent
<b>{{ ' Planet ' + planetConfiguration.name + ' ' }}</b>
<a class="margin-lr-8" [routerLink]="['reports', 'detail']" i18n mat-raised-button>Report Detail</a>
</p>
<p>
<span i18n>Chat streaming</span>
<mat-slide-toggle [(ngModel)]="streaming" (ngModelChange)="toggleStreaming()"></mat-slide-toggle>
<button mat-icon-button style="margin-left: 1rem;" (mouseenter)="toggleOverlay()" (mouseleave)="toggleOverlay()" cdkOverlayOrigin #trigger="cdkOverlayOrigin">
<mat-icon>info_outline</mat-icon>
</button>
<ng-template cdkConnectedOverlay [cdkConnectedOverlayOrigin]="trigger" [cdkConnectedOverlayOpen]="overlayOpen">
<span class="overlay-text" i18n>Quicker line by line chat responses, could be costlier</span>
</ng-template>
</p>
</div>
<mat-grid-list cols="4" rowHeight="2rem">
<mat-grid-tile i18n>Last Upgrade</mat-grid-tile><mat-grid-tile i18n>Last Sync</mat-grid-tile>
Expand Down
17 changes: 17 additions & 0 deletions src/app/manager-dashboard/manager-dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class ManagerDashboardComponent implements OnInit, OnDestroy {
fetchItemCount = 0;
pendingPushCount = 0;
isHub = false;
streaming: boolean;
overlayOpen = false;

constructor(
private userService: UserService,
Expand All @@ -84,6 +86,7 @@ export class ManagerDashboardComponent implements OnInit, OnDestroy {
) {}

ngOnInit() {
this.streaming = this.planetConfiguration.streaming;
this.isUserAdmin = this.userService.get().isUserAdmin;
if (this.planetType !== 'center') {
this.checkRequestStatus();
Expand Down Expand Up @@ -300,4 +303,18 @@ export class ManagerDashboardComponent implements OnInit, OnDestroy {
});
}

toggleOverlay(): void {
this.overlayOpen = !this.overlayOpen;
}

toggleStreaming(): void {
const configuration = this.planetConfiguration;
this.configurationService.updateConfiguration({ ...configuration, streaming: this.streaming }).subscribe(null,
error => this.planetMessageService.showAlert($localize`An error occurred please try again.`),
() => {
this.planetMessageService.showMessage($localize`Streaming has been ${this.streaming ? 'enabled' : 'disabled'}.`);
}
);
}

}
Loading