diff --git a/frontend/src/app/@shared/services/llm.service.ts b/frontend/src/app/@shared/services/llm.service.ts index 50d01d7a..2a0c9eb8 100644 --- a/frontend/src/app/@shared/services/llm.service.ts +++ b/frontend/src/app/@shared/services/llm.service.ts @@ -10,7 +10,7 @@ export interface LLM { } @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class LlmService { private apiUrl = `${environment.serverUrl}/api/llms`; diff --git a/frontend/src/app/chat/chat-controls/chat-controls.component.html b/frontend/src/app/chat/chat-controls/chat-controls.component.html index 0ebbfe93..588b22b1 100644 --- a/frontend/src/app/chat/chat-controls/chat-controls.component.html +++ b/frontend/src/app/chat/chat-controls/chat-controls.component.html @@ -18,7 +18,12 @@ - diff --git a/frontend/src/app/chat/chat-controls/chat-controls.component.ts b/frontend/src/app/chat/chat-controls/chat-controls.component.ts index 181de3ad..0b292335 100644 --- a/frontend/src/app/chat/chat-controls/chat-controls.component.ts +++ b/frontend/src/app/chat/chat-controls/chat-controls.component.ts @@ -18,14 +18,10 @@ export class ChatControlsComponent implements OnInit { isSending: boolean = false; llms: any[] = []; - constructor( - private chatService: ApiChatService, - private llmService: LlmService, - private fb: FormBuilder - ) { + constructor(private chatService: ApiChatService, private llmService: LlmService, private fb: FormBuilder) { this.chatForm = this.fb.group({ message: [''], - selectedLlm: [''] + selectedLlm: [''], }); } @@ -33,8 +29,9 @@ export class ChatControlsComponent implements OnInit { this.scrollBottom(); this.fetchLlms(); - this.chatForm.get('message')?.valueChanges - .pipe( + this.chatForm + .get('message') + ?.valueChanges.pipe( filter((data: string) => data !== ''), throttleTime(1400) ) @@ -42,8 +39,9 @@ export class ChatControlsComponent implements OnInit { // Implement typing indicator if needed }); - this.chatForm.get('message')?.valueChanges - .pipe( + this.chatForm + .get('message') + ?.valueChanges.pipe( filter((data: string) => data !== ''), debounceTime(1500) ) @@ -63,7 +61,7 @@ export class ChatControlsComponent implements OnInit { error: (error) => { console.error('Error fetching LLMs:', error); // Consider showing a user-friendly error message here - } + }, }); } @@ -94,7 +92,7 @@ export class ChatControlsComponent implements OnInit { console.error('Error sending message:', err); this.isSending = false; alert('Failed to send message. Please try again.'); - } + }, }); } diff --git a/frontend/src/app/chat/chat/chat.component.ts b/frontend/src/app/chat/chat/chat.component.ts index e93e53e3..aa52f55e 100644 --- a/frontend/src/app/chat/chat/chat.component.ts +++ b/frontend/src/app/chat/chat/chat.component.ts @@ -50,16 +50,11 @@ export class ChatComponent implements OnInit, OnDestroy { error: (error) => { console.error('Error loading chat:', error); // Handle error (e.g., show error message to user) - } + }, }); } - this.scrollEvent$ - .pipe( - debounceTime(200), - takeUntil(this.destroy$) - ) - .subscribe(() => this.checkScrollPosition()); + this.scrollEvent$.pipe(debounceTime(200), takeUntil(this.destroy$)).subscribe(() => this.checkScrollPosition()); } ngOnDestroy() { diff --git a/frontend/src/app/chat/model/chat.ts b/frontend/src/app/chat/model/chat.ts index 3e49421a..6ad475d8 100644 --- a/frontend/src/app/chat/model/chat.ts +++ b/frontend/src/app/chat/model/chat.ts @@ -1,4 +1,3 @@ - export interface LlmMessage { role: 'system' | 'user' | 'assistant'; text: string; diff --git a/frontend/src/app/chat/services/api/api-chat.service.ts b/frontend/src/app/chat/services/api/api-chat.service.ts index 25f87fec..1f507648 100644 --- a/frontend/src/app/chat/services/api/api-chat.service.ts +++ b/frontend/src/app/chat/services/api/api-chat.service.ts @@ -34,5 +34,4 @@ export class ApiChatService { sendMessage(chatId: string, content: string, llmId: string): Observable { return this.http.post(`/chat/${chatId}/send`, { text: content, llmId }); } - } diff --git a/frontend/src/app/runAgent/runAgent.component.ts b/frontend/src/app/runAgent/runAgent.component.ts index 031f7762..9a075798 100644 --- a/frontend/src/app/runAgent/runAgent.component.ts +++ b/frontend/src/app/runAgent/runAgent.component.ts @@ -85,7 +85,7 @@ export class RunAgentComponent implements OnInit { (this.runAgentForm as FormGroup).addControl('function' + index, new FormControl(false)); }); }); - + this.llmService.getLlms().subscribe({ next: (llms) => { this.llms = llms; @@ -93,9 +93,9 @@ export class RunAgentComponent implements OnInit { error: (error) => { console.error('Error fetching LLMs:', error); this.snackBar.open('Failed to load LLMs', 'Close', { duration: 3000 }); - } + }, }); - + this.loadUserProfile(); } diff --git a/frontend/src/app/shared/services/llm.service.spec.ts b/frontend/src/app/shared/services/llm.service.spec.ts index 807e9ddf..db87d803 100644 --- a/frontend/src/app/shared/services/llm.service.spec.ts +++ b/frontend/src/app/shared/services/llm.service.spec.ts @@ -3,6 +3,8 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/ import { LlmService, LLM } from './llm.service'; import { environment } from '@env/environment'; +const LLM_LIST_API_URL = `${environment.serverUrl}/llms/list`; + describe('LlmService', () => { let service: LlmService; let httpMock: HttpTestingController; @@ -10,7 +12,7 @@ describe('LlmService', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule], - providers: [LlmService] + providers: [LlmService], }); service = TestBed.inject(LlmService); httpMock = TestBed.inject(HttpTestingController); @@ -27,31 +29,29 @@ describe('LlmService', () => { it('should fetch LLMs from the server', () => { const mockLlms: LLM[] = [ { id: 'llm1', name: 'LLM 1', isConfigured: true }, - { id: 'llm2', name: 'LLM 2', isConfigured: false } + { id: 'llm2', name: 'LLM 2', isConfigured: false }, ]; - service.getLlms().subscribe(llms => { + service.getLlms().subscribe((llms) => { expect(llms).toEqual(mockLlms); }); - const req = httpMock.expectOne(`${environment.serverUrl}/api/llms/list`); + const req = httpMock.expectOne(LLM_LIST_API_URL); expect(req.request.method).toBe('GET'); req.flush({ data: mockLlms }); }); it('should cache LLMs after the first request', () => { - const mockLlms: LLM[] = [ - { id: 'llm1', name: 'LLM 1', isConfigured: true } - ]; + const mockLlms: LLM[] = [{ id: 'llm1', name: 'LLM 1', isConfigured: true }]; service.getLlms().subscribe(); - httpMock.expectOne(`${environment.serverUrl}/api/llms/list`).flush({ data: mockLlms }); + httpMock.expectOne(LLM_LIST_API_URL).flush({ data: mockLlms }); - service.getLlms().subscribe(llms => { + service.getLlms().subscribe((llms) => { expect(llms).toEqual(mockLlms); }); - httpMock.expectNone(`${environment.serverUrl}/api/llms/list`); + httpMock.expectNone(LLM_LIST_API_URL); }); it('should handle errors when fetching LLMs', () => { @@ -59,10 +59,10 @@ describe('LlmService', () => { next: () => fail('should have failed with the 404 error'), error: (error) => { expect(error.message).toContain('Error Code: 404'); - } + }, }); - const req = httpMock.expectOne(`${environment.serverUrl}/api/llms/list`); + const req = httpMock.expectOne(LLM_LIST_API_URL); req.flush('Not Found', { status: 404, statusText: 'Not Found' }); }); }); diff --git a/frontend/src/app/shared/services/llm.service.ts b/frontend/src/app/shared/services/llm.service.ts index 7faccb7e..b7f036b2 100644 --- a/frontend/src/app/shared/services/llm.service.ts +++ b/frontend/src/app/shared/services/llm.service.ts @@ -11,7 +11,7 @@ export interface LLM { } @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class LlmService { private llmsSubject = new BehaviorSubject([]); @@ -22,7 +22,7 @@ export class LlmService { getLlms(): Observable { if (!this.llmsLoaded) { return this.fetchLlms().pipe( - tap(llms => { + tap((llms) => { this.llmsSubject.next(llms); this.llmsLoaded = true; }), @@ -33,12 +33,11 @@ export class LlmService { } private fetchLlms(): Observable { - return this.http.get<{ data: LLM[] }>(`${environment.serverUrl}/llms/list`) - .pipe( - map(response => response.data), - retry(3), - catchError(this.handleError) - ); + return this.http.get<{ data: LLM[] }>(`${environment.serverUrl}/llms/list`).pipe( + map((response) => response.data), + retry(3), + catchError(this.handleError) + ); } private handleError(error: HttpErrorResponse) {