Skip to content

Commit

Permalink
courses: enabling context chat (fixes #7578) (#7579)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Mutugiii and dogi authored Sep 27, 2024
1 parent 554ba25 commit 3e5ae00
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 40 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "planet",
"license": "AGPL-3.0",
"version": "0.14.79",
"version": "0.14.80",
"myplanet": {
"latest": "v0.19.55",
"min": "v0.18.55"
"latest": "v0.19.65",
"min": "v0.18.65"
},
"scripts": {
"ng": "ng",
Expand Down
22 changes: 6 additions & 16 deletions src/app/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';

import { ChatService } from '../shared/chat.service';
import { AIServices, ProviderName } from './chat.model';

@Component({
selector: 'planet-chat',
Expand All @@ -11,7 +10,7 @@ import { AIServices, ProviderName } from './chat.model';
})
export class ChatComponent implements OnInit {
activeService: string;
aiServices: { name: ProviderName, value: ProviderName }[] = [];
aiServices: { name: string, value: string }[] = [];
displayToggle: boolean;

constructor(
Expand All @@ -21,20 +20,11 @@ export class ChatComponent implements OnInit {
) {}

ngOnInit() {
this.chatService.listAIProviders().subscribe((services: AIServices | null) => {
if (services) {
for (const [ key, value ] of Object.entries(services)) {
if (value === true) {
this.aiServices.push({
name: key as ProviderName,
value: key as ProviderName
});
}
}
this.activeService = this.aiServices[0].value;
this.displayToggle = this.aiServices.length > 0;
this.chatService.toggleAIServiceSignal(this.activeService);
}
this.chatService.listAIProviders().subscribe((providers) => {
this.aiServices = providers;
this.activeService = this.aiServices[0]?.value;
this.displayToggle = this.aiServices.length > 0;
this.chatService.toggleAIServiceSignal(this.activeService);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="space-container">
<mat-toolbar class="primary-color font-size-1">
<h3 class="margin-lr-3 ellipsis-title"><ng-container i18n>Step</ng-container> {{stepNum}}<span *ngIf="stepDetail.stepTitle">: </span>{{stepDetail.stepTitle}}</h3>
<button mat-stroked-button class="margin-lr-3" (click)="showChat = !showChat" i18n>
<button *ngIf="isOpenai" mat-stroked-button class="margin-lr-3" (click)="showChat = !showChat" i18n>
{{ showChat ? 'Hide Course Chat' : 'Show Course Chat' }}
</button>
<span class="toolbar-fill"></span>
Expand Down
16 changes: 11 additions & 5 deletions src/app/courses/step-view-courses/courses-step-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SubmissionsService } from '../../submissions/submissions.service';
import { ResourcesService } from '../../resources/resources.service';
import { DialogsSubmissionsComponent } from '../../shared/dialogs/dialogs-submissions.component';
import { StateService } from '../../shared/state.service';
import { ChatService } from '../../shared/chat.service';

@Component({
templateUrl: './courses-step-view.component.html',
Expand All @@ -36,17 +37,19 @@ export class CoursesStepViewComponent implements OnInit, OnDestroy {
countActivity = true;
isGridView = true;
showChat = false;
isOpenai = false;
@ViewChild(MatMenuTrigger) previewButton: MatMenuTrigger;

constructor(
private chatService: ChatService,
private coursesService: CoursesService,
private dialog: MatDialog,
private resourcesService: ResourcesService,
private router: Router,
private route: ActivatedRoute,
private dialog: MatDialog,
private coursesService: CoursesService,
private userService: UserService,
private stateService: StateService,
private submissionsService: SubmissionsService,
private resourcesService: ResourcesService,
private stateService: StateService
private userService: UserService,
) {}

ngOnInit() {
Expand Down Expand Up @@ -74,6 +77,9 @@ export class CoursesStepViewComponent implements OnInit, OnDestroy {
this.coursesService.requestCourse({ courseId: this.courseId, parent: this.parent });
});
this.resourcesService.requestResourcesUpdate(this.parent);
this.chatService.listAIProviders().subscribe((providers) => {
this.isOpenai = providers.some(provider => provider.value === 'openai');
});
}

getSubmission() {
Expand Down
3 changes: 0 additions & 3 deletions src/app/courses/view-courses/courses-view.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ <h3 class="margin-lr-3 ellipsis-title">{{courseDetail.courseTitle}}</h3>
<button mat-stroked-button *ngIf="canManage" (click)="updateCourse()">
<mat-icon>edit</mat-icon>
</button>
<!-- <button mat-stroked-button class="margin-lr-3" (click)="toggleFullView('chat')" i18n>
{fullView, select, on {Show Course Chat}}
</button> -->
<span class="toolbar-fill"></span>
</ng-template>

Expand Down
36 changes: 24 additions & 12 deletions src/app/shared/chat.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { BehaviorSubject, Observable, Subject, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { catchError, map, shareReplay } from 'rxjs/operators';

import { environment } from '../../environments/environment';
import { findDocuments, inSelector } from '../shared/mangoQueries';
Expand All @@ -22,12 +22,12 @@ import { AIServices } from '../chat/chat.model';
private newChatSelected: Subject<void> = new Subject<void>();
private toggleAIService = new Subject<string>();
private selectedConversationIdSubject = new BehaviorSubject<object | null>(null);
private aiProvidersSubject = new BehaviorSubject<AIServices | null>(null);
aiProviders$ = this.aiProvidersSubject.asObservable();
private aiProvidersSubject = new BehaviorSubject<Array<{ name: string; value: string }>>([]);

newChatAdded$ = this.newChatAdded.asObservable();
newChatSelected$ = this.newChatSelected.asObservable();
toggleAIService$ = this.toggleAIService.asObservable();
aiProviders$ = this.aiProvidersSubject.asObservable();
selectedConversationId$: Observable<object | null> = this.selectedConversationIdSubject.asObservable();


Expand All @@ -51,17 +51,29 @@ import { AIServices } from '../chat/chat.model';
}

private fetchAIProviders() {
this.httpClient.get<AIServices>(`${this.baseUrl}/checkproviders`).pipe(
catchError(err => {
console.error(err);
return of({ openai: false, perplexity: false, gemini: false });
})
).subscribe((services: AIServices) => {
this.aiProvidersSubject.next(services);
});
this.httpClient
.get<AIServices>(`${this.baseUrl}/checkproviders`)
.pipe(
catchError((err) => {
console.error(err);
return of({ openai: false, perplexity: false, gemini: false });
}),
map((services: AIServices) => {
if (services) {
return Object.entries(services)
.filter(([ _, value ]) => value === true)
.map(([ key ]) => ({ name: key, value: key }));
} else {
return [];
}
})
)
.subscribe((providers) => {
this.aiProvidersSubject.next(providers);
});
}

listAIProviders() {
listAIProviders(): Observable<Array<{ name: string; value: string }>> {
return this.aiProviders$;
}

Expand Down

0 comments on commit 3e5ae00

Please sign in to comment.