Skip to content

Commit 8373bde

Browse files
implement some coderabbit suggestions
1 parent 9d98648 commit 8373bde

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

backend/src/modules/ai/services/summarization.service.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { env } from '../../../shared/config/environment';
99
import { getEncoding } from 'js-tiktoken';
1010

1111
export class SummarizationService {
12-
private model: GenerativeModel;
12+
private readonly defaultModelType: AIModel;
1313
private prompt: PromptTemplate;
1414

1515
constructor() {
@@ -18,22 +18,20 @@ export class SummarizationService {
1818
throw new AppError(500, 'Gemini API key not found in environment variables. Please set GEMINI_API_KEY.', 'summarization.service');
1919
}
2020

21-
// Initialize Gemini model
22-
const defaultModel = AIModel.Gemini20Flash;
23-
const genAI = new GoogleGenerativeAI(env.ai.geminiKey);
24-
this.model = genAI.getGenerativeModel({
25-
model: defaultModel,
26-
systemInstruction: SUMMARY_SYSTEM_PROMPT,
27-
generationConfig: MODEL_CONFIGS[defaultModel],
28-
});
29-
30-
// Initialize prompt template
21+
this.defaultModelType = AIModel.Gemini20Flash;
3122
this.prompt = PromptTemplate.fromTemplate(SUMMARY_USER_PROMPT);
3223
}
3324

3425
async summarize(request: SummarizationRequest): Promise<SummarizationResponse> {
3526
const startTime = Date.now();
36-
const model = request.options?.model || AIModel.Gemini15Flash;
27+
const modelType = request.options?.model || this.defaultModelType;
28+
29+
const genAI = new GoogleGenerativeAI(env.ai.geminiKey!);
30+
const model = genAI.getGenerativeModel({
31+
model: modelType,
32+
systemInstruction: SUMMARY_SYSTEM_PROMPT,
33+
generationConfig: MODEL_CONFIGS[modelType],
34+
});
3735

3836
try {
3937
// Format the prompt with system and user messages combined
@@ -42,7 +40,7 @@ export class SummarizationService {
4240
});
4341

4442
// Call the model
45-
const result = await this.model.generateContent(formattedPrompt);
43+
const result = await model.generateContent(formattedPrompt);
4644
const summary = result.response.text();
4745

4846
const endTime = Date.now();
@@ -57,7 +55,7 @@ export class SummarizationService {
5755
return {
5856
summary,
5957
metadata: {
60-
model,
58+
model: modelType,
6159
processingTime,
6260
tokenCount
6361
}

backend/tests/ai-module.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from 'axios';
22
import { describe, it, expect } from '@jest/globals';
33

4-
const API_URL = 'http://localhost:3000';
4+
const API_URL = process.env.BACKEND_URL || 'http://localhost:3000';
55

66
describe('Summarization Route Tests', () => {
77
it('should return a summary for valid input', async () => {

backend/tests/user-module.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import axios from "axios";
22
import { describe, expect, afterAll } from "@jest/globals";
33

44
// Configuration for tests
5-
const API_URL = 'http://localhost:3000';
5+
const API_URL = process.env.BACKEND_URL || 'http://localhost:3000';
66
const testUserCredentials = {
77
firstName: 'Test',
88
lastName: 'User',

0 commit comments

Comments
 (0)