Skip to content

Commit

Permalink
fix(#36): filter method type별로 확장가능하게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kimhji committed Feb 6, 2025
1 parent 1639981 commit e7c1e76
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions server/src/ai/ai.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class AIService {
headers: this.getHeader(AIType.Summary),
body: JSON.stringify(body),
});

if (response.status === 429) {
console.warn('Rate limit 초과. 재시도 중...');
await delay(500);
Expand All @@ -90,11 +91,11 @@ export class AIService {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

if (!response.body) {
throw new Error('응답 스트림이 없습니다.');
}
result = await this.filterResponse(response);

result = await this.filterResponse(type, response);
resLength = result.length;
count++;
}
Expand All @@ -109,7 +110,14 @@ export class AIService {
}
}

async filterResponse(response: Response) {
filterResponse(type: AIType, response: Response) {
if (type == AIType.Summary) {
return this.summaryResFilter(response);
}
return '';
}

async summaryResFilter(response: Response) {
const reader = response.body.getReader();
const decoder = new TextDecoder('utf-8');
let accumulatedText = '';
Expand Down

0 comments on commit e7c1e76

Please sign in to comment.