> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sambanova.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Vision・マルチモーダル機能の実装

SambaNova の Vision (視覚) モデルはマルチモーダル入力に対応しており、テキストと画像の両方を処理できます。これらのモデルは画像を分析し、コンテキストを踏まえたテキスト応答を生成します。本ページでは、SambaNova または OpenAI の Python クライアントを使用して、SambaNova の Vision モデルにクエリを送信する方法を解説します。

## 画像を使用したクエリの作成

SambaNova では、Vision モデルへのリクエストは OpenAI のマルチモーダル入力フォーマットに従い、構造化されたペイロードでテキストと画像の両方を受け付けます。呼び出し方法は [Text generation (テキスト生成)](/docs/ja/features/text-generation) と似ていますが、`image_path` 変数で参照されるエンコード済みの画像ファイルを含める点が異なります。画像を base64 文字列に変換するにはヘルパー関数を使用します。これにより、テキストと一緒に画像をリクエストへ渡せるようになります。

<Steps>
  <Step title="ステップ 1">
    新しい Python ファイルを作成し、以下のコードをコピーします。

    <Note>
      この例では gemma-4-31B-it モデルを使用しています。
    </Note>

    <CodeGroup>
      ```python Python (SambaNova) theme={}
      from sambanova import SambaNova
      import base64

      client = SambaNova(
          base_url="your-sambanova-base-url",
          api_key="your-sambanova-api-key",
      )

      # Helper function to encode the image
      def encode_image(image_path):
        with open(image_path, "rb") as image_file:
          return base64.b64encode(image_file.read()).decode('utf-8')

      # The path to your image
      image_path = "sample.JPEG"

      # The base64 string of the image
      image_base64 = encode_image(image_path)

      print(image_base64)

      response = client.chat.completions.create(
          model="gemma-4-31B-it",
          messages=[
              {
                  "role": "user",
                  "content": [
                      {"type": "text", "text": "What is happening in this image?"},
                      {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_base64}"}}
                  ]
              }
          ]
      )

      print(response.choices[0].message.content)
      ```

      ```python Python (OpenAI) theme={}
      from openai import OpenAI
      import base64

      client = OpenAI(
          base_url="your-sambanova-base-url",
          api_key="your-sambanova-api-key",
      )

      # Helper function to encode the image
      def encode_image(image_path):
        with open(image_path, "rb") as image_file:
          return base64.b64encode(image_file.read()).decode('utf-8')

      # The path to your image
      image_path = "sample.JPEG"

      # The base64 string of the image
      image_base64 = encode_image(image_path)

      print(image_base64)

      response = client.chat.completions.create(
          model="gemma-4-31B-it",
          messages=[
              {
                  "role": "user",
                  "content": [
                      {"type": "text", "text": "What is happening in this image?"},
                      {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_base64}"}}
                  ]
              }
          ]
      )

      print(response.choices[0].message.content)
      ```
    </CodeGroup>
  </Step>

  <Step title="ステップ 2">
    クライアントの生成部分にある文字列フィールド `"your-sambanova-api-key"` と `"your-sambanova-base-url"` を、[API キーと URL](/docs/ja/get-started/api-keys-urls) ページで取得した SambaNova API キーとベース URL に置き換えます。
  </Step>

  <Step title="ステップ 3">
    使用する画像を選択し、以下の行で指定できる適切なパスに配置します。

    ```python theme={}
    # The path to your image
    image_path = "sample.JPEG"
    ```
  </Step>

  <Step title="ステップ 4">
    `user` プロンプトの `content` 部分で、画像と組み合わせるプロンプトを確認します。
  </Step>

  <Step title="ステップ 5">
    Python ファイルを実行して、テキスト出力を受け取ります。
  </Step>
</Steps>
