メインコンテンツまでスキップ

入力フォーマット

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..."
}

パラメータ

必須パラメータ

パラメータ説明
modelstring使用するモデル (例: "helix-v1", "iroha")
messagesarrayrole と content を持つメッセージオブジェクトの配列

オプションパラメータ

パラメータデフォルト説明
temperaturefloat0.7ランダム性を制御 (0.0 - 2.0)
max_tokensinteger2048応答の最大トークン数
top_pfloat1.0Nucleus sampling パラメータ
frequency_penaltyfloat0.0繰り返しを減らす (-2.0 to 2.0)
presence_penaltyfloat0.0新しいトピックを促す (-2.0 to 2.0)
stopstring or arraynull生成を停止するシーケンス

リクエスト例

シンプルな会話

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())

ベストプラクティス

  1. システムメッセージを使用して一貫した動作を設定
  2. 会話履歴を保持してマルチターン対話でコンテキストを維持
  3. ユースケースに基づいて温度を調整:
    • 低め (0.1-0.5) で事実的で一貫した応答
    • 高め (0.7-1.2) でクリエイティブなコンテンツ
  4. 適切な max_tokens を設定して応答の長さとコストを制御
  5. stop シーケンスを使用して望ましくない継続を防ぐ

次のステップ