AWS Bedrock의 Converse API에서 Sonnet 3.7 Reasoning 사용하기

2025. 2. 26. 08:51개발/AWS

Claude 3.7 Sonnet

Claude 3.7 Sonnet의 발표가 있었습니다.

 

Claude 3.7 Sonnet and Claude Code

Today, we’re announcing Claude 3.7 Sonnet, our most intelligent model to date and the first hybrid reasoning model generally available on the market.

www.anthropic.com

 

이번 업데이트 중에 extended thinking mode가 생겼는데요.
이는 AI 모델이 대답하기전에 스스로 생각을 하는 일종의 추론 모델입니다.

AWS에서도 해당 내용이 바로 블로그에 올라왔고 Claude 3.7 Sonnet의 사용과 reasoning mode(extended thinking mode)를 바로 사용할수 있었습니다.

 

Anthropic’s Claude 3.7 Sonnet hybrid reasoning model is now available in Amazon Bedrock | Amazon Web Services

Claude 3.7 Sonnet hybrid reasoning model is Anthropic’s most intelligent model to date excelling at coding and powering AI agents. It is the first Claude model to offer extended thinking—the ability to solve complex problems with careful, step-by-step

aws.amazon.com

 

*NEW* Anthropic Claude 3.7 Sonnet - Amazon Bedrock

*NEW* Anthropic Claude 3.7 Sonnet Anthropic Claude 3.7 Sonnet is the first Claude model to offer step-by-step reasoning, which Anthropic has termed “extended thinking”. With Claude 3.7 Sonnet, use of step-by-step reasoning is optional. You can choose b

docs.aws.amazon.com

 

Converse API에서 사용하기

저는 Converse API를 사용하기 때문에 사용 방법을 찾기가 쉽지 않았는데요.
additionalModelRequestFields를 이용해서 사용할 수 있다는 것을 찾았습니다.

response = bedrock_runtime.converse(
    modelId='us.anthropic.claude-3-7-sonnet-20250219-v1:0',
    messages=[{
        'role': 'user',
        'content': [
            {
                'text': 'What are the advantages of aws bedrock?'
            },
        ]
    }],
    additionalModelRequestFields={
        "reasoning_config": {
            "type": "enabled",
            "budget_tokens": 1024
        },
    }
)

 

위 코드를 실행하면 reasoningContent 영역에 대해 추론의 결과를 함께 받을 수 있습니다.

'output': {
    'message': {
      'role': 'assistant',
      'content': [
        {
          'reasoningContent': {
            'reasoningText': {
              'text': "AWS Bedrock is Amazon's managed service ~~",
              'signature': 'EqgBCkYQARgCIkCy0Q ~~'
            }
          }
        },
        {
          'text': "# Advantages of AWS Bedrock\n\nAWS Bedrock is ~~"
        }
      ]
    }
  },

 

사용에 몇가지 참고할 사항이 있습니다.

  • modelId는 cross region을 해야만 작동합니다. 그렇지 않으면 예외가 발생합니다.
  • budget_token도 일종의 출력 토큰으로 과금의 대상입니다.

 

마지막으로, 정작 실제 서비스에서는 Converse Stream을 이용하는데요.
Converse Stream에서의 사용 방법도 공유합니다.

response = bedrock_runtime.converse_stream(
    modelId='us.anthropic.claude-3-7-sonnet-20250219-v1:0',
    messages=[{
        'role': 'user',
        'content': [
            {
                'text': 'What are the advantages of aws bedrock?'
            },
        ]
    }],
    additionalModelRequestFields={
        "reasoning_config": {
            "type": "enabled",
            "budget_tokens": 1024
        },
    }
)

reasoning = ''
text = ''

for chunk in response["stream"]:
    if "contentBlockDelta" in chunk:
        delta = chunk['contentBlockDelta']['delta']

        if "reasoningContent" in delta:
            reasoningContent = delta['reasoningContent']

            if 'text' in reasoningContent:
                reasoning += reasoningContent['text']
        if 'text' in delta:
            text += delta['text']
            
print(reasoning)
print(text)