LLM 快速开始
本指南将引导您对 Shisa LLM 发出第一个聊天补全请求。您需要一个 API 密钥 —— 在 Shisa 平台创建一个。新账户包含价值 10 美元的免费额度。
1. 设置您的端点和密钥
Shisa LLM 兼容 OpenAI。将任意 OpenAI 客户端指向 Shisa 的基础 URL,并使用 bearer 令牌进行认证:
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 可接收单个 JSON 响应,完整消息位于 choices[0].message.content。响应结构与 OpenAI Chat Completions API 一致 —— 完整结构请参阅聊天补全参考。