> ## 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.

# Python および JavaScript のための SambaNova SDK

SambaNova は、Python および JavaScript/TypeScript 向けに SDK を提供しており、SambaNova REST API との連携を容易にします。[SambaNova Python クライアント](https://pypi.org/project/sambanova/) は Python 3.8 以降に対応し、[JavaScript/TypeScript 版](https://www.npmjs.com/package/sambanova) はサーバーサイド環境向けに設計されています。どちらのライブラリにも、リクエストパラメータとレスポンスフィールドの型定義が組み込まれており、同期・非同期の両方の利用に対応しています。

## 使用例

まずは、使用したいプログラミング言語を選択してください。次に、ターミナルウィンドウを開いて SambaNova SDK をインストールします。

<CodeGroup>
  ```javascript Javascript theme={}
  //ensure you have Node.js installed.
  npm install sambanova
  ```

  ```python Python theme={}
  # make sure you have Python3 and pip installed
  pip install sambanova
  ```
</CodeGroup>

次に、以下のコードを新しいファイルにコピーします。

<CodeGroup>
  ```javascript hello-world.js theme={}
  import SambaNova from "sambanova";

  const client = new SambaNova({
    baseURL: "your-sambanova-base-url",
    apiKey: "your-sambanova-api-key",
  });

  const chatCompletion = await client.chat.completions.create({
    messages: [
      { role: "system", content: "Answer the question in a couple sentences." },
      { role: "user", content: "Share a happy story with me" },
    ],
    model: "Meta-Llama-3.3-70B-Instruct",
    logprobs: true,
    top_logprobs: 2,
  });

  console.log(chatCompletion.choices[0].message.content);
  ```

  ```python hello_world.py theme={}
  from sambanova import SambaNova

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

  completion = client.chat.completions.create(
    model = "Meta-Llama-3.3-70B-Instruct",
    messages = [
        {"role": "system", "content": "Answer the question in a couple sentences."},
        {"role": "user", "content": "Share a happy story with me"}
      ],
    logprobs = True,
    top_logprobs = 2
  )

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

ファイルにコピーしたら、文字列フィールド `"your-sambanova-base-url"` と `"your-sambanova-api-key"` を、お使いのベース URL と API キーの値に置き換えてください。その後、ターミナルウィンドウで以下のコマンドを実行してファイルを実行します。

<CodeGroup>
  ```javascript Javascript theme={}
  node hello-world.js
  ```

  ```python Python theme={}
  python hello_world.py
  ```
</CodeGroup>

プログラムを実行すると、以下のような出力が表示されます。

```json theme={}
{
  "id": "d89243f2-de68-416f-85c6-27c244cf9c7f",
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "One day, a little girl named Sophie found a lost puppy in her neighborhood and decided to take care of it until she could find its owner. As she cared for the puppy, named Max, they formed an unbreakable bond, and when the owner was finally found, they were so grateful to Sophie that they asked her to be Max's permanent dog-sitter, bringing joy and companionship to Sophie's life.",
        "role": "assistant"
      },
      "logprobs": {
      	"content": [
        	{
             	"bytes": [...],
                "logprob": -0.06340447068214417,
                "token": "One",
                "top_logprobs": [
                	{
                    	"bytes": [...],
                        "logprob": -0.06340447068214417,
                        "token": "One"
                   	},
                    ...
                 ]
       		},
            ...
		]
    }
    }
  ],
  "created": 1759518870.892972,
  "model": "Meta-Llama-3.3-70B-Instruct",
  "object": "chat.completion",
  "system_fingerprint": "fastcoe",
  "usage": {
    "completion_tokens": 84,
    "prompt_tokens": 49,
    "total_tokens": 133,
    ...
    "stop_reason": "stop"
  }
}
```
