Skip to content

Commit

Permalink
chat fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcampagnolitg committed Nov 2, 2024
1 parent 02a2092 commit 9e83e72
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 39 deletions.
6 changes: 3 additions & 3 deletions frontend/src/app/core/auth/auth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const authInterceptor = (
});
}
} else {
// For IAP, do not modify the request headers
// For IAP, do not modify the request headers, the token is sent as a cookie.
newReq = req.clone();
}

Expand All @@ -43,8 +43,8 @@ export const authInterceptor = (
// Handle "401 Unauthorized" responses
if (error instanceof HttpErrorResponse && error.status === 401) {
if (environment.auth === 'google_iap') {
// Redirect to root to trigger IAP authentication
window.location.href = '/';
// Refresh to trigger IAP authentication
window.location.reload();
return throwError(() => new Error('Redirecting to IAP authentication'));
} else {
// Sign out and reload the app for other auth modes
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/modules/admin/apps/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class ChatService {
* Reset the selected chat
*/
resetChat(): void {
this._chat.next({ id: '', messages: [], title: '', updatedAt: Date.now() });
this._chat.next(null);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@
class="flex h-18 flex-0 items-center border-b bg-gray-50 px-4 dark:bg-transparent md:px-6"
>
<!-- Back button -->
<a
class="md:-ml-2 lg:hidden"
mat-icon-button
[routerLink]="['./']"
(click)="resetChat()"
>
<mat-icon
[svgIcon]="'heroicons_outline:arrow-long-left'"
></mat-icon>
</a>
@if (chats.length) {
<a
class="md:-ml-2 lg:hidden"
mat-icon-button
[routerLink]="['./']"
(click)="goBack()"
>
<mat-icon
[svgIcon]="'heroicons_outline:arrow-long-left'"
></mat-icon>
</a>
}

<button
class="ml-auto"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {MatSelect} from "@angular/material/select";
import {ReactiveFormsModule} from "@angular/forms";
import {MatTooltipModule} from "@angular/material/tooltip";


@Component({
selector: 'chat-conversation',
templateUrl: './conversation.component.html',
Expand Down Expand Up @@ -85,6 +84,7 @@ export class ConversationComponent implements OnInit, OnDestroy, AfterViewInit {
@ViewChild('messageInput') messageInput: ElementRef;
@ViewChild('llmSelect') llmSelect: MatSelect;
chat: Chat;
chats: Chat[];
drawerMode: 'over' | 'side' = 'side';
drawerOpened: boolean = false;
private _unsubscribeAll: Subject<any> = new Subject<any>();
Expand Down Expand Up @@ -161,7 +161,7 @@ export class ConversationComponent implements OnInit, OnDestroy, AfterViewInit {

if (chatId === 'new' || !chatId) {
// If 'new' or no ID, reset the chat
this.resetChat();
this.goBack();
}
});

Expand All @@ -176,21 +176,26 @@ export class ConversationComponent implements OnInit, OnDestroy, AfterViewInit {
return;
}
this.chat = clone(chat) || { id: '', messages: [], title: '', updatedAt: Date.now() };
console.log('this._chatService.chat$.subscribe')
console.log(chat);

if(chat.messages.length > 0) {
// Set the LLM selector as the LLM used to send the last message
const lastMessageLlmId = chat.messages.at(-1).llmId
if (lastMessageLlmId) { // TODO check the llmId is in the $llm list
this.llmId = lastMessageLlmId;
console.log(`last message llm ${this.llmId}`)
} else {
// TODO default to user profile default chat LLM
}
}
this._changeDetectorRef.markForCheck();
});

// Chats observable
this._chatService.chats$
.pipe(takeUntil(this._unsubscribeAll))
.subscribe((chats: Chat[]) => {
this.chats = chats;
});

// Media watcher (unchanged)
this._fuseMediaWatcherService.onMediaChange$
.pipe(takeUntil(this._unsubscribeAll))
Expand Down Expand Up @@ -232,23 +237,9 @@ export class ConversationComponent implements OnInit, OnDestroy, AfterViewInit {
/**
* Reset the chat
*/
resetChat(): void {
this.chat = { id: '', messages: [], title: '', updatedAt: Date.now() };
goBack(): void {
this._chatService.resetChat();
this.generating = false

// TODO set LLM field to the user profile default chat LLM

// Close the contact info in case it's opened
this.drawerOpened = false;

// Clear the input field
if (this.messageInput) {
this.messageInput.nativeElement.value = '';
}

// Mark for check
this._changeDetectorRef.markForCheck();
this.router.navigate(['/ui/apps/chat']).catch(console.error);
}

/**
Expand All @@ -257,8 +248,7 @@ export class ConversationComponent implements OnInit, OnDestroy, AfterViewInit {
deleteChat(): void {
if (this.chat && this.chat.id) {
this._chatService.deleteChat(this.chat.id).subscribe(() => {
this.resetChat();
this.router.navigate(['/ui/apps/chat']).catch(console.error);
this.goBack();
});
}
}
Expand Down Expand Up @@ -301,8 +291,7 @@ export class ConversationComponent implements OnInit, OnDestroy, AfterViewInit {
this.messageInput.nativeElement.value = '';

// If this is a new chat, then redirect to the created chat
if (!this.chat.id) {

if (!this.chat.id || this.chat.id === 'new') {
this._changeDetectorRef.markForCheck();
// TODO handle error, set the message back to the messageInput and remove from chat.messages
this._chatService.createChat(message, this.llmId).subscribe(async (chat: Chat) => {
Expand Down

0 comments on commit 9e83e72

Please sign in to comment.