SambaNova 빠른 시작

SambaNova 빠른 시작

SambaNova API는 몇 분이면 첫 요청을 보내볼 수 있을 만큼 간단해요. 필요한 건 SambaCloud 계정(또는 SambaStack 배포 접근 권한)과 API 키, 그리고 선호하는 개발 환경뿐이에요. 공식 SDK, OpenAI 호환 클라이언트, CURL 중 원하는 방식으로 시작하면 돼요.

출처: SambaNova 빠른 시작

준비 사항

시작하기 전에 다음을 확인해요.

  • SambaCloud 계정, 또는 시스템 관리자를 통해 받은 SambaStack 배포 접근 권한
  • Python 3, Node.js, 또는 CURL (사용하는 통합 방식에 따라)

API 키 발급하기

API 키와 URL 페이지에서 API 키를 생성해요. 키는 다시 볼 수 없으니 생성 후 안전한 곳에 꼭 보관해 두어야 해요. 계정당 최대 25개의 API 키를 만들고 사용할 수 있어요.

모델 고르기

  • SambaCloud 개발자는 SambaCloud 모델 페이지에서 사용 가능한 모델과 세부 정보를 확인할 수 있어요.
  • SambaStack 개발자는 시스템 관리자에게 어떤 모델이 배포돼 있는지 문의하고, 해당 모델 페이지에서 세부 정보를 보면 돼요.

이 가이드에서는 예시로 Meta-Llama-3.3-70B-Instruct를 사용할게요.

SambaNova SDK로 요청하기

SambaNova 전용 SDK를 쓰는 방법이에요. 먼저 패키지를 설치해요.

npm install sambanova
pip install sambanova

설치 후 새 파일을 만들어 아래 코드를 붙여 넣어요.

import SambaNova from "sambanova";

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

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",
});

console.log(chatCompletion.choices[0].message.content);
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"}
    ]
)

print(completion.choices[0].message.content)

"your-sambanova-base-url""your-sambanova-api-key" 자리를 실제 Base URL과 API 키로 바꾼 뒤 실행해요.

node hello-world.js
python hello_world.py

실행하면 모델이 생성한 행복한 이야기가 출력돼요.

OpenAI 클라이언트로 요청하기

이미 OpenAI SDK에 익숙하다면 그대로 가져다 쓸 수 있어요. openai 패키지를 설치하고 Base URL과 API 키만 바꿔주면 돼요.

npm install openai
pip install openai
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "your-sambanova-base-url",
  apiKey: "your-...ey",
});

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",
});

console.log(chatCompletion.choices[0].message.content);
from openai import OpenAI

client = OpenAI(
    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"}
    ]
)

print(completion.choices[0].message.content)

hello_world.py 파일에 담아 실행하면 SambaNova SDK 방식과 같은 출력을 얻어요.

CURL로 요청하기

터미널에서 CURL 명령으로도 바로 호출할 수 있어요.

export API_KEY="your-api-key-here"
export URL="your-url-here"

curl -H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "system", "content": "Answer the question in a couple sentences."},
{"role": "user", "content": "Share a happy story with me"}
],
"stop": ["<|eot_id|>"],
"model": "Meta-Llama-3.3-70B-Instruct",
"stream": true, "stream_options": {"include_usage": true}
}' \
-X POST $URL

다음 단계

첫 요청이 동작하면 AI 애플리케이션을 만들 준비가 된 거예요. 어떤 걸 만들 수 있을지 아이디어가 필요하면 AI 스타터 키트에서 오픈소스 Python 프로젝트 모음을 살펴보세요.

더 알아보기 (Learn more)