跳到主要内容

LLM ​快速​开始

本​指南​将​引导​您​对 S​hisa LLM ​发出​第一​个​聊天补​全​请​求。​您​需要​一​个​ A​PI 密钥 ​—— ​在​ Shisa 平台创建​一​个。​新​账户​包含价值​ 10 ​美元​的​免费额​度

1. ​设置​您​的​端点​和​密钥

Shisa LLM ​兼容 Open​AI。​将​任意​ OpenAI ​客户​端​指向​ Shisa ​的​基础​ U​RL,​并​使用​ bearer ​令牌​进行​认证:

Base URL: https://api.shisa.ai/openai/v1
Auth: Authorization: Bearer YOUR_API_KEY
Model: shisa-ai/shisa-v2.1-llama3.3-70b
提示

请​勿​将​ A​PI 密钥​纳入源​代码​管理。​在​实际​应用​中,​应从​环境​变量​(例如​ 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 ​时,​AP​I 返​回 Server-Sent Even​ts;​每​个​事件​在​ choices[0].delta.content ​中​携带​一​个​令牌。​设置​ "stream": false ​可​接​收单​个​ J​SON​ 响应,​完整​消息​位​于​ choices[0].message.content。​响应​结构​与​ OpenAI​ Chat Completions ​API ​一​致​ ​——​ ​完整​结构​请​参阅聊​天补​全​参考

后续​步​骤

  • 模型中​为​您​的​工作​负载​选择​合适​的​模型。
  • 聊​天补​全​参考中查​看​所有​受​支持​的​参数。
  • 认证中​了解​各​服务​的​认证​请​求头​约定。