-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7815213
commit 1b43819
Showing
7 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,17 @@ jobs: | |
source: "./docker-compose.yml" | ||
target: /home/${{ vars.VM_USERNAME }}/${{ github.repository }} | ||
|
||
- name: Create Environment File | ||
env: | ||
ANGULAR_APP_API_KEY: ${{ secrets.ANGELOS_APP_API_KEY }} | ||
run: | | ||
echo "export const environment = { | ||
production: true, | ||
angelosUrl: '/api/v1/question/chat', | ||
angelosToken: '/api/token', | ||
angelosAppApiKey: '${ANGELOS_APP_API_KEY}' | ||
};" > src/environments/environment.prod.ts | ||
- name: SSH to VM and Execute Docker-Compose Up | ||
uses: appleboy/[email protected] | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { AuthService } from './auth.service'; | ||
|
||
describe('AuthService', () => { | ||
let service: AuthService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(AuthService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { HttpClient, HttpHeaders } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, tap } from 'rxjs'; | ||
import { environment } from '../../environments/environment'; | ||
|
||
export interface AuthResponse { | ||
access_token: string; | ||
token_type: string; | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AuthService { | ||
|
||
constructor(private http: HttpClient) { } | ||
|
||
login(): Observable<AuthResponse> { | ||
const headers = new HttpHeaders().set('x-api-key', environment.angelosAppApiKey); | ||
return this.http.post<AuthResponse>(environment.angelosToken, { headers }).pipe( | ||
tap((response: AuthResponse) => { | ||
sessionStorage.setItem('access_token', response.access_token); | ||
}) | ||
); | ||
} | ||
|
||
// Method to retrieve the stored token | ||
public getToken(): string | null { | ||
return sessionStorage.getItem('access_token'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,37 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { HttpClient, HttpHeaders } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { ChatMessage } from '../chat/chat.component'; | ||
import { Observable } from 'rxjs'; | ||
import { Observable, switchMap } from 'rxjs'; | ||
import { environment } from '../../environments/environment'; | ||
import { AuthService } from './auth.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ChatbotService { | ||
|
||
constructor(private http: HttpClient) { } | ||
constructor(private http: HttpClient, private authService: AuthService) { } | ||
|
||
sendBotRequest(token: string | null, chatHistory: ChatMessage[], study_program: string): Observable<any> { | ||
const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`); | ||
return this.http.post(environment.angelosUrl, | ||
{ messages: chatHistory, study_program: study_program }, | ||
{ headers } | ||
); | ||
} | ||
|
||
getBotResponse(chatHistory: ChatMessage[], study_program: string): Observable<any> { | ||
return this.http.post(environment.angelosUrl, { messages: chatHistory, study_program: study_program }); | ||
const token = this.authService.getToken(); | ||
if (token) { | ||
return this.sendBotRequest(token, chatHistory, study_program); | ||
} else { | ||
// Login if no token is stored, then proceed with the bot request | ||
return this.authService.login().pipe( | ||
switchMap(() => { | ||
const newToken = this.authService.getToken(); | ||
return this.sendBotRequest(newToken, chatHistory, study_program); | ||
}) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export const environment = { | ||
production: false, | ||
angelosUrl: 'http://localhost:8000/api/v1/question/chat' | ||
}; | ||
angelosUrl: 'http://localhost:8000/api/v1/question/chat', | ||
angelosToken: 'http://localhost:8000/api/token', | ||
angelosAppApiKey: 'SOME_SECRET_KEY', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export const environment = { | ||
production: true, | ||
angelosUrl: '/api/v1/question/chat' | ||
angelosUrl: '/api/v1/question/chat', | ||
angelosToken: '/api/token', | ||
angelosAppApiKey: 'SOME_SECRET_KEY', | ||
}; |