diff --git a/src/app/chat/chat-sidebar/chat-sidebar.component.ts b/src/app/chat/chat-sidebar/chat-sidebar.component.ts index e5ff372e37..b41dd7a11b 100644 --- a/src/app/chat/chat-sidebar/chat-sidebar.component.ts +++ b/src/app/chat/chat-sidebar/chat-sidebar.component.ts @@ -120,19 +120,23 @@ export class ChatSidebarComponent implements OnInit, OnDestroy { } getChatHistory() { - this.chatService.findConversations([], [ this.userService.get().name ]).subscribe( - (conversations: any) => { - this.conversations = conversations.sort((a, b) => { - const dateA = a.updatedDate || a.createdDate; - const dateB = b.updatedDate || b.createdDate; - - return dateB - dateA; - }); - this.filteredConversations = [ ...conversations ]; - this.initializeFormGroups(); - }, - (error) => console.log(error) - ); + this.chatService + .findConversations([], [ this.userService.get().name ]) + .subscribe( + (conversations: any) => { + this.conversations = conversations + .filter((conversation) => !conversation?.context) + .sort((a, b) => { + const dateA = a.updatedDate || a.createdDate; + const dateB = b.updatedDate || b.createdDate; + + return dateB - dateA; + }); + this.filteredConversations = [ ...this.conversations ]; + this.initializeFormGroups(); + }, + (error) => console.log(error) + ); } selectConversation(conversation, index: number) { diff --git a/src/app/chat/chat-window/chat-window.component.html b/src/app/chat/chat-window/chat-window.component.html index 7cbee2408f..3c06a04609 100644 --- a/src/app/chat/chat-window/chat-window.component.html +++ b/src/app/chat/chat-window/chat-window.component.html @@ -12,7 +12,16 @@ Chat
- +
diff --git a/src/app/chat/chat-window/chat-window.component.ts b/src/app/chat/chat-window/chat-window.component.ts index c85cf65efe..3927ca3ea5 100644 --- a/src/app/chat/chat-window/chat-window.component.ts +++ b/src/app/chat/chat-window/chat-window.component.ts @@ -33,6 +33,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy { assistant: false, context: '', }; + providers: AIProvider[] = []; @Input() context: any; @ViewChild('chat') chatContainer: ElementRef; @@ -51,6 +52,9 @@ export class ChatWindowComponent implements OnInit, OnDestroy { this.subscribeToSelectedConversation(); this.subscribeToAIService(); this.checkStreamingStatusAndInitialize(); + this.chatService.listAIProviders().subscribe((providers) => { + this.providers = providers; + }); } ngOnDestroy() { diff --git a/src/app/chat/chat.component.html b/src/app/chat/chat.component.html index 17c655299e..2701f4a0d4 100644 --- a/src/app/chat/chat.component.html +++ b/src/app/chat/chat.component.html @@ -3,7 +3,7 @@ AI Chat - {{service.name}} + {{service.name}} {{activeService}} diff --git a/src/app/chat/chat.component.ts b/src/app/chat/chat.component.ts index 2d5a4ef03f..6aed46a070 100644 --- a/src/app/chat/chat.component.ts +++ b/src/app/chat/chat.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { ChatService } from '../shared/chat.service'; +import { AIProvider } from './chat.model'; @Component({ selector: 'planet-chat', @@ -10,7 +11,7 @@ import { ChatService } from '../shared/chat.service'; }) export class ChatComponent implements OnInit { activeService: string; - aiServices: { name: string, value: string }[] = []; + aiServices: AIProvider[] = []; displayToggle: boolean; constructor( @@ -22,7 +23,7 @@ export class ChatComponent implements OnInit { ngOnInit() { this.chatService.listAIProviders().subscribe((providers) => { this.aiServices = providers; - this.activeService = this.aiServices[0]?.value; + this.activeService = this.aiServices[0]?.model; this.displayToggle = this.aiServices.length > 0; this.chatService.toggleAIServiceSignal(this.activeService); }); diff --git a/src/app/chat/chat.model.ts b/src/app/chat/chat.model.ts index 1e1b394992..f4566fcbc6 100644 --- a/src/app/chat/chat.model.ts +++ b/src/app/chat/chat.model.ts @@ -16,6 +16,7 @@ export interface Conversation { title: string; createdDate: number; updatedDate: number; + context?: any; } export interface Message { diff --git a/src/app/courses/step-view-courses/courses-step-view.component.ts b/src/app/courses/step-view-courses/courses-step-view.component.ts index 36a02ddbc8..7ea1ff1026 100644 --- a/src/app/courses/step-view-courses/courses-step-view.component.ts +++ b/src/app/courses/step-view-courses/courses-step-view.component.ts @@ -78,7 +78,7 @@ export class CoursesStepViewComponent implements OnInit, OnDestroy { }); this.resourcesService.requestResourcesUpdate(this.parent); this.chatService.listAIProviders().subscribe((providers) => { - this.isOpenai = providers.some(provider => provider.value === 'openai'); + this.isOpenai = providers.some(provider => provider.model === 'openai'); }); } diff --git a/src/app/shared/chat.service.ts b/src/app/shared/chat.service.ts index 06b8c6ea58..387be33bb8 100644 --- a/src/app/shared/chat.service.ts +++ b/src/app/shared/chat.service.ts @@ -1,12 +1,12 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { BehaviorSubject, Observable, Subject, of } from 'rxjs'; -import { catchError, map, shareReplay } from 'rxjs/operators'; +import { catchError, map } from 'rxjs/operators'; import { environment } from '../../environments/environment'; import { findDocuments, inSelector } from '../shared/mangoQueries'; import { CouchService } from '../shared/couchdb.service'; -import { AIServices } from '../chat/chat.model'; +import { AIServices, AIProvider } from '../chat/chat.model'; @Injectable({ providedIn: 'root' @@ -22,7 +22,7 @@ import { AIServices } from '../chat/chat.model'; private newChatSelected: Subject = new Subject(); private toggleAIService = new Subject(); private selectedConversationIdSubject = new BehaviorSubject(null); - private aiProvidersSubject = new BehaviorSubject>([]); + private aiProvidersSubject = new BehaviorSubject>([]); newChatAdded$ = this.newChatAdded.asObservable(); newChatSelected$ = this.newChatSelected.asObservable(); @@ -61,8 +61,8 @@ import { AIServices } from '../chat/chat.model'; map((services: AIServices) => { if (services) { return Object.entries(services) - .filter(([ _, value ]) => value === true) - .map(([ key ]) => ({ name: key, value: key })); + .filter(([ _, model ]) => model === true) + .map(([ key ]) => ({ name: key, model: key })); } else { return []; } @@ -73,7 +73,7 @@ import { AIServices } from '../chat/chat.model'; }); } - listAIProviders(): Observable> { + listAIProviders(): Observable> { return this.aiProviders$; }