23.06.15
DEVOTEE를 활성화 시키면
지금 작성한 커뮤니티 글에 대해 1개의 댓글을 달아줍니다.
버튼을 누르면 글 수정 시 ChatGPT가 작성한 댓글이 수정됩니다.
| 컨텐츠 유형 | 제목 | 저장일 | 삭제 |
|---|
본인인증 로그인에 실패하였습니다.
회원이 아니시거나 본인인증 등록이
완료되지 않은 사용자입니다.
Amazon Bedrock은 AI21 Labs, Anthropic, Cohere, Meta, Stability AI 등의 다양한 Foundation Model을 선택하여 사용할 수 있는 생성형 AI 서비스입니다.
Amazon Bedrock에 대한 자세한 소개 및 사용법은 서태호님께서 기재한 Amazon 생성형 AI 도구인 베드락 사용해 보자 편을 참고하시기 바랍니다.
이번 블로그에는 Amazon Bedrock를 어플리케이션에 통합하여 Foundation Model에 프롬프트를 입력하고, 그 결과를 출력할 수 있는 부분에 집중하여 설명하려 합니다.
Amazon Bedrock에서 제공하는 다양한 Foundation Model를 선택하고, 사용자가 작성한 프롬프트를 호출 하기 위해서는 Amazon Bedrock Endpoint를 사용합니다.
Amazon Bedrock Endpoint는 Amazon Bedrock 서비스를 제공하는 리전별 API를 호출할 수 있도록 제공합니다.
아래 이미지는 리전별로 호출 가능한 Bedrock Endpoint 주소 정보 및 Bedrock 사용 요금 입니다.
(예시로 사용할 Foundation Model은claude3 sonnet 을 사용할 예정입니다.)
또한 Endpoint를 어플리케이션에 통합하기 위해서는 AWS SDK인 boto3 패키지를 사용하여 Bedrock을 호출합니다.
아래 코드는 Pyhton의 Boto3 패키지를 이용하여 Bedrock Endpoint를 호출하는 예시 코드입니다.
import boto3
def call_bedrock_endpoint():
model = "anthropic.claude-3-sonnet-20240229-v1:0" #FM : claude3 sonnet
prompt = "토끼와 거북이 이야기를 영어로 200자 이내로 번역하여 지문으로 생성하고, 3지 선다로 문제와 답을 3개 생성해줘."
session = boto3.Session()
bedrock = session.client(service_name='bedrock-runtime') #creates a Bedrock client
body = json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 512,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": prompt
}
]
}
],
"temperature": 0.5,
"top_p": 0.9
})
response = bedrock.invoke_model(body=body, modelId=model, accept='application/json', contentType='application/json') #send the payload to Bedrock
response_body = json.loads(response.get('body').read()) # read the response
response_text = response_body.get("content")[0].get("text") #extract the text from the JSON response
print(response_text)위의 코드를 작성 후 호출하게 되면 다음과 같이 결과가 나오게 됩니다.
The Tortoise and the Hare
Once upon a time, a hare mocked a slow-moving tortoise for his sluggish pace. The tortoise challenged the hare to a race. The hare, confident in his speed, agreed. As the race began, the hare raced ahead, leaving the tortoise far behind. Feeling overconfident, the hare decided to take a nap. Meanwhile, the tortoise kept plodding along. When the hare awoke, he saw the tortoise nearing the finish line. Despite his swift speed, the hare could not overtake the steady tortoise, who won the race.
1. What did the hare do during the race?
a) He ran as fast as he could.
b) He took a nap.
c) He cheated.
2. Who won the race?
a) The hare
b) The tortoise
c) Neither, it was a tie.
3. What is the moral of the story?
a) Slow and steady wins the race.
b) Overconfidence leads to failure.
c) Both a and b.
Answers:
1. b
2. b
3. cAmazon Bedrock Endpoint를 사용하여 어플리케이션을 통합하면 빠르고 쉽게 챗봇 서비스, 이미지 생성 어플레케이션 등의 다양한 서비스를 구성할 수 있습니다.
AWS에서 제공하는 완전 관리형 서비스인 만큼Foundation Model 업데이트도 빠른 편이며, 사용자가 직접 생성한 Foundation Model을 import하여 구성할 수 있습니다.
뿐만 아니라, Knowledge Base, Agent, Playground 등의 다양한 기능을 제공 및 SageMaker 서비스와의 연동도 가능하니, 상황에 맞게 사용하시면 될 것으로 생각됩니다.
Amazon Bedrock Runtime examples using SDK for Python (Boto3)
DEVOTEE를 활성화 시키면
지금 작성한 댓글에 AI가 댓글을 달아줍니다.