Skip to content

Commit

Permalink
Merge branch 'master' into 7586-suppress-vertical-scroll-bars
Browse files Browse the repository at this point in the history
  • Loading branch information
dogi authored Oct 4, 2024
2 parents 9423473 + c2b051d commit 058275d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 24 deletions.
30 changes: 17 additions & 13 deletions src/app/chat/chat-sidebar/chat-sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion src/app/chat/chat-window/chat-window.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
<mat-label i18n>Chat</mat-label>
<div class="textarea-container">
<textarea matInput [formControl]="promptForm.controls.prompt" rows="5" placeholder="Send a message" i18n-placeholder></textarea>
<button mat-icon-button [planetSubmit]="promptForm.valid && spinnerOn" [disabled]="!promptForm.valid" color="primary"><mat-icon>send</mat-icon></button>
<button
mat-icon-button
[planetSubmit]="promptForm.valid && spinnerOn"
[disabled]="!promptForm.valid || providers.length === 0"
matTooltip="chat is disabled, contact community admin"
[matTooltipDisabled]="providers.length > 0"
color="primary"
>
<mat-icon>send</mat-icon>
</button>
</div>
</mat-form-field>
</form>
Expand Down
4 changes: 4 additions & 0 deletions src/app/chat/chat-window/chat-window.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class ChatWindowComponent implements OnInit, OnDestroy {
assistant: false,
context: '',
};
providers: AIProvider[] = [];

@Input() context: any;
@ViewChild('chat') chatContainer: ElementRef;
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/chat/chat.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span class="titlebar" i18n>AI Chat</span>
<span class="toolbar-fill"></span>
<mat-button-toggle-group *ngIf="displayToggle; else textDisplay" [(ngModel)]="activeService" (change)="toggleAIService()">
<mat-button-toggle *ngFor="let service of aiServices" [value]="service.value" i18n>{{service.name}}</mat-button-toggle>
<mat-button-toggle *ngFor="let service of aiServices" [value]="service.model" i18n>{{service.name}}</mat-button-toggle>
</mat-button-toggle-group>
<ng-template #textDisplay>
<span i18n>{{activeService}}</span>
Expand Down
5 changes: 3 additions & 2 deletions src/app/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand All @@ -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);
});
Expand Down
1 change: 1 addition & 0 deletions src/app/chat/chat.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface Conversation {
title: string;
createdDate: number;
updatedDate: number;
context?: any;
}

export interface Message {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}

Expand Down
12 changes: 6 additions & 6 deletions src/app/shared/chat.service.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -22,7 +22,7 @@ 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<Array<{ name: string; value: string }>>([]);
private aiProvidersSubject = new BehaviorSubject<Array<AIProvider>>([]);

newChatAdded$ = this.newChatAdded.asObservable();
newChatSelected$ = this.newChatSelected.asObservable();
Expand Down Expand Up @@ -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 [];
}
Expand All @@ -73,7 +73,7 @@ import { AIServices } from '../chat/chat.model';
});
}

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

Expand Down

0 comments on commit 058275d

Please sign in to comment.