LLMクイックスタート
このガイドでは、Shisa LLMに対して最初のチャット補完を行います。APIキーが必要です — Shisaプラットフォームで作成してください。新規アカウントには10ドル分の無料クレジットが含まれます。
1. エンドポイントとキーを設定する
Shisa LLMはOpenAI互換です。任意のOpenAIクライアントをShisaのベースURLに向け、ベアラートークンで認証します。
Base URL: https://api.shisa.ai/openai/v1
Auth: Authorization: Bearer YOUR_API_KEY
Model: shisa-ai/shisa-v2.1-llama3.3-70b
ヒント
APIキーはソース管理に含めないでください。実際のアプリケーションでは、環境変数(例えばSHISA_API_KEY)から読み込んでください。
2. リクエストを行う
curl
curl -XPOST https://api.shisa.ai/openai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "shisa-ai/shisa-v2.1-llama3.3-70b",
"stream": true,
"messages": [
{
"role": "system",
"content": "You are a helpful assistant fluent in Japanese and English."
},
{
"role": "user",
"content": "日本の四季について教えてください。"
}
],
"temperature": 0.7
}'
Python
from openai import OpenAI
# Initialize client with Shisa AI endpoint
client = OpenAI(
base_url="https://api.shisa.ai/openai/v1",
api_key="YOUR_API_KEY"
)
def chat_with_shisa(message, model="shisa-ai/shisa-v2.1-llama3.3-70b"):
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": message}
],
stream=True,
temperature=0.7
)
for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
# Example usage
chat_with_shisa("東京でおすすめの観光スポットを教えてください。")
Node.js
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.shisa.ai/openai/v1',
apiKey: 'YOUR_API_KEY',
});
async function chatWithShisa(message) {
const stream = await client.chat.completions.create({
model: 'shisa-ai/shisa-v2.1-llama3.3-70b',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: message }
],
stream: true,
temperature: 0.7,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content || '';
process.stdout.write(content);
}
}
// Example usage
await chatWithShisa('日本語で自己紹介をしてください。');
3. レスポンスを読み取る
"stream": trueの場合、APIはServer-Sent Eventsを返します。各イベントはchoices[0].delta.contentにトークンを含みます。"stream": falseを設定すると、完全なメッセージがchoices[0].message.contentに含まれる単一のJSONレスポンスを受け取ります。レスポンスの形式はOpenAI Chat Completions APIと一致します — 完全なスキーマについてはチャット補完リファレンスを参照してください。
次のステップ
- モデルでワークロードに適したモデルを選びましょう。
- チャット補完リファレンスでサポートされているすべてのパラメータを確認しましょう。
- 認証でサービス間の認証ヘッダー規約を学びましょう。