翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
Mistral AI テキスト補完
- Mistral AI テキスト補完APIを使用すると、 を使用してテキストを生成できます。Mistral AI モデル。
に推論リクエストを行う Mistral AI InvokeModel または InvokeModelWithResponseStream (ストリーミング) を使用する モデル。
Mistral AI モデルは Apache 2.0 ライセンス
サポートされているモデル
以下を使用できます。Mistral AI モデル。
Mistral 7B Instruct
Mixtral 8X7B Instruct
Mistral Large
Mistral Small
このとき、使用するモデルのモデル ID が必要になります。モデル ID を取得するには、「Amazon Bedrock でサポートされている基盤モデル」を参照してください。
リクエストとレスポンス
コード例
この例では、 を呼び出す方法を示します。Mistral 7B Instruct モデル。
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Shows how to generate text using a Mistral AI model. """ import json import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) def generate_text(model_id, body): """ Generate text using a Mistral AI model. Args: model_id (str): The model ID to use. body (str) : The request body to use. Returns: JSON: The response from the model. """ logger.info("Generating text with Mistral AI model %s", model_id) bedrock = boto3.client(service_name='bedrock-runtime') response = bedrock.invoke_model( body=body, modelId=model_id ) logger.info("Successfully generated text with Mistral AI model %s", model_id) return response def main(): """ Entrypoint for Mistral AI example. """ logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") try: model_id = 'mistral.mistral-7b-instruct-v0:2' prompt = """<s>[INST] In Bash, how do I list all text files in the current directory (excluding subdirectories) that have been modified in the last month? [/INST]""" body = json.dumps({ "prompt": prompt, "max_tokens": 400, "temperature": 0.7, "top_p": 0.7, "top_k": 50 }) response = generate_text(model_id=model_id, body=body) response_body = json.loads(response.get('body').read()) outputs = response_body.get('outputs') for index, output in enumerate(outputs): print(f"Output {index + 1}\n----------") print(f"Text:\n{output['text']}\n") print(f"Stop reason: {output['stop_reason']}\n") except ClientError as err: message = err.response["Error"]["Message"] logger.error("A client error occurred: %s", message) print("A client error occured: " + format(message)) else: print(f"Finished generating text with Mistral AI model {model_id}.") if __name__ == "__main__": main()