11import { Injectable } from '@angular/core' ;
22import { HttpClient , HttpHeaders } from '@angular/common/http' ;
3- import { environment } from '../../../environments/environments' ;
43import { firstValueFrom } from 'rxjs' ;
54import { GlobalLoaderService } from '../global-loader/global-loader.service' ;
65import { ExpenseService , Expense } from '../localStorage/expense.service' ;
@@ -18,10 +17,16 @@ import { ConfigService } from '../config/config.service';
1817 providedIn : 'root'
1918} )
2019export class GeminiApiService {
20+
2121 /**
22- * API URL for the Gemini model including the environment API key .
22+ * API URL for the Gemini model.
2323 */
24- private apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=${ environment . geminiApiKey } ` ;
24+ private geminiApiUrl = '' ;
25+
26+ /**
27+ * API key for accessing the Gemini AI API.
28+ */
29+ private geminiAPIKey : string | null = null ;
2530
2631 /**
2732 * Creates an instance of GeminiApiService.
@@ -36,7 +41,10 @@ export class GeminiApiService {
3641 private globalLoaderService : GlobalLoaderService ,
3742 private expenseService : ExpenseService ,
3843 private configService : ConfigService
39- ) { }
44+ ) {
45+ this . geminiAPIKey = this . configService . getGeminiApiKey ( ) || '' ;
46+ this . geminiApiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=${ this . geminiAPIKey } ` ;
47+ }
4048
4149 /**
4250 * Sends a prompt to the Gemini API and returns the generated response.
@@ -57,7 +65,7 @@ export class GeminiApiService {
5765 } ;
5866
5967 try {
60- const res : any = await firstValueFrom ( this . http . post ( this . apiUrl , body , { headers } ) ) ;
68+ const res : any = await firstValueFrom ( this . http . post ( this . geminiApiUrl , body , { headers } ) ) ;
6169 const parts = res ?. candidates ?. [ 0 ] ?. content ?. parts ;
6270 this . globalLoaderService . hide ( ) ;
6371 return parts ?. map ( ( p : any ) => p . text ) . join ( '\n\n' ) || 'No response' ;
0 commit comments