AWS Bedock을 이용해 LLM 모델 사용을 구현하였다.
사실 이미 LLM 모델 사용을 구현했었지만 아마존 LLM 모델을 사용하면 비용적, 성능적 측면에서 절감이 가능하지 않을까해서 변경해보았다.
constructor(){
this.client = new BedrockRuntimeClient({
region: process.env.AWS_REGION as string,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID as string,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string,
},
});
}
먼저 access_key, 엑세스 시크릿 키가 필요하다.
생성자에 BedrockRuntimeClient로 엑세스 키 정보를 주었다.
async sendMessage(projectId: string, body: any, user: any) {
const payload = {
anthropic_version: 'bedrock-2023-05-31',
temperature: 0.5,
top_p: 0.9,
top_k: 50,
system: `너의 역할은 사용자가 회의록을 작성해서 너에게 전송하면 여기서 이슈들을 자동으로
분류한 후 DB에 저장할 수 있게 json 형식으로 바꾸어서 다시 서버로 전송하는 거야.
json 형식은 다음과 같이 답변해줘
[
{
"id": uuid,
"title" : 이슈 제목,
"description" : 이슈 내용,
"issue_type" : "task",
"status" : "BACKLOG",
},
]
여기서 issue_type은 무조건 task로 설정해주고 status는 BACKLOG 값으로 해야해. NOT NULL이 아닌 항목은 작성하지 않아도 돼.
title과 description은 사용자가 입력한 회의록에서 추출해줘
id는 uuid를 기반으로 랜덤으로 생성해주고 project_id와 reporter_id는 내가 너에게 입력해 줄게.
정보를 종합해서 json형식으로 보내줘. 이 때 다른 수식어는 제거하고 오직 json 형식만 보내줘`,
max_tokens: 1024,
messages: [{role: 'user', content: body.text}]
};
const cmd = new InvokeModelCommand({
modelId: 'arn:aws:bedrock:ap-northeast-2:522814727185:inference-profile/apac.anthropic.claude-3-5-sonnet-20241022-v2:0',
contentType: 'application/json',
body: JSON.stringify(payload),
})
const response = await this.client.send(cmd);
const decoded = new TextDecoder().decode(response.body);
const result = JSON.parse(decoded);
console.log(result);
// 1. content에서 text만 추출
const text = result.content[0].text;
// 2. 마크다운 코드블록(```json ... ```) 제거
const jsonString = text.replace(/```json|```/g, '').trim();
// 3. 줄바꿈(\n) 등 불필요한 공백 제거 (JSON.parse는 줄바꿈 있어도 동작함)
const cleanJsonString = jsonString;
const issues = JSON.parse(cleanJsonString);
// 이제 issues는 JS 배열 객체!
console.log(issues);
return {
success: true,
projectId: projectId,
issues: issues,
timestamp: new Date().toISOString()
};
}
프롬프트는 기존과 비슷하게 가져갔고 이를 잘 정제해서 넣는것이 필요했다.
BedRock은 온도나 여러 수치들을 조절할 수 있었기에 이를 이용해 응답률을 줄이려고 하였다.
또한 여러 모델이 있어 다른 모델을 쓰는 방법도 있었다.
하지만 좀 힘들긴 하였다.
또한 기존과 그렇게 큰 성능 개선이 없다는 느낌이 들었다.
그래서 그냥 원래 모델을 쓰는게 나은것 같다.