기반 모델 선택

Amazon Bedrock 입문

Nikhil Rangarajan

Data Scientist

Amazon Bedrock에서 모델 액세스 활성화

  • 모델 액세스 설정 - 본 과정에선 별도 활성화 불필요

AWS 콘솔에서 Claude와 Nova 모델이 활성화된 스크린샷.

Amazon Bedrock 입문

경량 vs. 고급 기반 모델

  • 경량 모델
    • 적합: Q&A, 요약
    • 응답이 빠르고 비용 효율적
    • 예: Nova Micro, Claude Haiku

Amazon 로고.

  • 고급 모델
    • 적합: 복잡한 추론, 분석
    • 포괄적 분석 기능
    • 예: Nova Plus, Claude Sonnet

Anthropic 로고.

Amazon Bedrock 입문

Amazon Bedrock의 기타 기반 모델

Amazon Bedrock의 기타 모델:

  • Meta의 Llama

    • 📝 일반 텍스트 작업용 오픈 소스 LLM
  • Stability AI의 Stable Diffusion

    • 🖼 이미지 생성 특화
  • AI21의 Jurassic

    • 📈 텍스트 생성 및 분석

Meta의 Llama 로고.

Amazon Bedrock 입문

Bedrock 모델 호출

  • 기본 구조:
import json
bedrock = boto3.client('bedrock-runtime', region_name='us-east-1')
response = bedrock.invoke_model(modelId='amazon.nova-lite-v1:0',

body=json.dumps(input_dictionary)
)
  • 모델의 응답을 JSON으로 반환
Amazon Bedrock 입문

Claude 호출

  • Anthropic Claude
response = bedrock.invoke_model(
    modelId='anthropic.claude-3-5-sonnet-v2:0',
    body=json.dumps(

{"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 100,
"messages": [{ "role": "user", "content": [{"type": "text", "text": "your prompt here"}], }],
}
))
Amazon Bedrock 입문

Nova 호출

  • Amazon Nova
response = bedrock.invoke_model(
    modelId='amazon.nova-lite-v1:0', 
    body=json.dumps(

{"messages":
[{"role": "user", "content": [{"text": "your prompt here"}] }]
}
))
Amazon Bedrock 입문

모델 응답 추출

  • API 응답 본문 읽기
  • JSON을 Python 딕셔너리로 변환
  • 키로 출력 추출
print("Claude:",

json.loads( claude_response['body'].read() )
["content"][0]["text"]
)
Hello! It's nice to meet you. How can I assist you today?
Amazon Bedrock 입문

모델 응답 추출

  • API 응답 본문 읽기
  • JSON을 Python 딕셔너리로 변환
  • 키로 출력 추출
print("Nova:",

json.loads( nova_response.get("body").read().decode() )
["output"]["message"]["content"][0]["text"]
)
Hello! How can I assist you today?
Amazon Bedrock 입문

Ayo berlatih!

Amazon Bedrock 입문

Preparing Video For Download...