入力フォーマット
Rustellar AI モデルでサポートされている入力フォーマットについて学びます。
リクエスト構造
すべての API リクエストは、簡単な統合のために OpenAI 互換フォーマットに従います。
基本的なリクエストフォーマット
{
"model": "helix-v1",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
],
"temperature": 0.7,
"max_tokens": 1000
}
メッセージロール
System
システムメッセージは、AI モデルの動作とコンテキストを設定します。
{
"role": "system",
"content": "You are a helpful assistant specialized in programming."
}
User
ユーザーメッセージは、エンドユーザーからの入力を表します。
{
"role": "user",
"content": "What is Python?"
}
Assistant
アシスタントメッセージは、AI モデルからの以前の応答を表します。マルチターン会話に使用されます。
{
"role": "assistant",
"content": "Python is a high-level programming language..."
}
パラメータ
必須パラメータ
| パラメータ | 型 | 説明 |
|---|---|---|
model | string | 使用するモデル (例: "helix-v1", "iroha") |
messages | array | role と content を持つメッセージオブジェクトの配列 |
オプションパラメータ
| パラメータ | 型 | デフォルト | 説明 |
|---|---|---|---|
temperature | float | 0.7 | ランダム性を制御 (0.0 - 2.0) |
max_tokens | integer | 2048 | 応答の最大トークン数 |
top_p | float | 1.0 | Nucleus sampling パラメータ |
frequency_penalty | float | 0.0 | 繰り返しを減らす (-2.0 to 2.0) |
presence_penalty | float | 0.0 | 新しいトピックを促す (-2.0 to 2.0) |
stop | string or array | null | 生成を停止するシーケンス |
リクエスト例
シンプルな会話
import requests
# シンプルな会話リクエスト
response = requests.post(
"https://api.rustellar.com/v1/chat/completions",
headers={
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
json={
"model": "helix-v1",
"messages": [
{"role": "user", "content": "Tell me a joke"}
]
}
)
print(response.json())
マルチターン会話
# 複数ターンの会話履歴を含むリクエスト
response = requests.post(
"https://api.rustellar.com/v1/chat/completions",
headers={
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
json={
"model": "helix-v1",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is 2+2?"},
{"role": "assistant", "content": "2+2 equals 4."},
{"role": "user", "content": "What about 3+3?"}
],
"temperature": 0.7,
"max_tokens": 100
}
)
print(response.json())
Iroha によるストーリー生成
# Irohaモデルでストーリー生成
response = requests.post(
"https://api.rustellar.com/v1/chat/completions",
headers={
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
json={
"model": "iroha",
"messages": [
{
"role": "system",
"content": "You are a creative storyteller."
},
{
"role": "user",
"content": "Write a short story about a space explorer."
}
],
"temperature": 0.9, # より創造的な出力のため高めに設定
"max_tokens": 2000
}
)
print(response.json())
ベストプラクティス
- システムメッセージを使用して一貫した動作を設定
- 会話履歴を保持してマルチターン対話でコンテキストを維持
- ユースケースに基づいて温度を調整:
- 低め (0.1-0.5) で事実的で一貫した応答
- 高め (0.7-1.2) でクリエイティブなコンテンツ
- 適切な max_tokens を設定して応答の長さとコストを制御
- stop シーケンスを使用して望ましくない継続を防ぐ