View a markdown version of this page

Invoke API 사용 - Amazon Nova

Invoke API 사용

Invoke API는 요청 및 응답 형식을 제어하는 추가 기능과 함께 Amazon Nova 모델에 대한 직접 액세스 권한을 제공합니다. 모델별 세부 정보를 추상화하는 Converse API와 달리, Invoke API를 사용하면 모델의 기본 요청 및 응답 구조를 직접 작업할 수 있습니다.

참고

Invoke API는 Converse API에 특정한 문서 입력 양식을 제외하고 Converse API와 동일한 기능을 지원합니다.

요청 구조

Invoke API 요청에는 모델 ID 및 JSON 요청 본문이 필요합니다.

import boto3 import json bedrock = boto3.client('bedrock-runtime', region_name='us-east-1') request_body = { 'messages': [ { 'role': 'user', 'content': [{'text': 'What is machine learning?'}] } ], 'inferenceConfig': { 'maxTokens': 512, 'temperature': 0.7 } } response = bedrock.invoke_model( modelId='us.amazon.nova-2-lite-v1:0', body=json.dumps(request_body) ) response_body = json.loads(response['body'].read()) content_list = response_body["output"]["message"]["content"] # Extract the first text block text_block = next((item for item in content_list if "text" in item), None) if text_block is not None: print(text_block["text"])

요청 파라미터

Invoke API는 다음과 같은 주요 파라미터를 지원합니다.

  • messages: 역할 및 콘텐츠를 포함하는 대화 메시지 배열

  • system: 컨텍스트 및 지침에 대한 선택적 시스템 프롬프트

  • inferenceConfig: 모델 출력을 제어하는 파라미터(temperature, maxTokens, topP, topK, stopSequences, reasoningConfig)

  • toolConfig: 함수 직접 호출을 위한 도구 사양 및 도구 선택