API概要
Potatoとプログラムで連携するためのHTTP APIリファレンス。
APIリファレンス
Potatoは、カスタムフロントエンド、自動化スクリプト、または外部システムとの統合のためのHTTP APIエンドポイントを提供します。
概要
ベースURL
text
http://localhost:8000
認証
ほとんどのエンドポイントは、ログインエンドポイントを介して確立され、Cookieで維持されるアクティブなセッションが必要です。
プログラムによるアクセスの場合:
- ブラウザからのセッションCookieを使用する
- 自動ユーザー作成でデバッグモードを使用する
- ログインフローをプログラムで実装する
レスポンス形式
すべてのAPIエンドポイントはJSONレスポンスを返します。エラーレスポンスにはerrorフィールドが含まれます。
セッション管理
ログイン
http
POST /auth
Content-Type: application/x-www-form-urlencoded
username=your_username&password=your_passwordセッション確認
http
GET /api/current_instanceレスポンス:
json
{
"instance_id": "item_001",
"current_index": 0,
"total_instances": 100
}ログアウト
http
POST /logoutアノテーションエンドポイント
現在のインスタンスを取得
http
GET /api/current_instanceユーザーの現在のアノテーションインスタンスに関する情報を返します。
インスタンスのコンテンツを取得
http
GET /api/spans/{instance_id}テキストコンテンツと既存のスパンアノテーションを返します。
レスポンス:
json
{
"instance_id": "item_001",
"text": "The quick brown fox jumps over the lazy dog.",
"spans": [
{
"id": "span_123",
"schema": "entities",
"label": "ANIMAL",
"start": 16,
"end": 19,
"text": "fox",
"color": "#ff6b6b"
}
]
}アノテーションを取得
http
GET /get_annotations?instance_id={instance_id}特定のインスタンスのすべてのアノテーションを返します。
アノテーションを送信
http
POST /updateinstance
Content-Type: application/json
{
"instance_id": "item_001",
"annotations": {
"sentiment:positive": "1"
},
"span_annotations": [
{
"schema": "entities",
"name": "PERSON",
"start": 0,
"end": 5,
"value": "true"
}
]
}レスポンス(成功時):
json
{
"status": "success",
"processing_time_ms": 15
}レスポンス(品質管理あり):
json
{
"status": "success",
"qc_result": {
"type": "gold_standard",
"correct": false,
"gold_label": {"sentiment": "positive"}
}
}インスタンスに移動
http
POST /go_to
Content-Type: application/json
{"go_to": "item_005"}またはアクションで指定:
json
{"action": "next_instance"}スキーマ情報
アノテーションスキーマを取得
http
GET /api/schemasラベルカラーを取得
http
GET /api/colorsキーワードハイライトを取得
http
GET /api/keyword_highlights/{instance_id}管理者APIエンドポイント
管理者エンドポイントには管理者権限が必要です。
ヘルスチェック
http
GET /admin/healthダッシュボード概要
http
GET /admin/api/overviewレスポンス:
json
{
"total_items": 1000,
"total_annotations": 5000,
"total_users": 25,
"completion_rate": 0.45
}アノテーター一覧を取得
http
GET /admin/api/annotatorsインスタンス一覧を取得
http
GET /admin/api/instances?status=completed&limit=100設定を取得
http
GET /admin/api/config設定を更新
http
POST /admin/api/config
Content-Type: application/json
{"setting_name": "value"}品質管理API
品質管理メトリクス
http
GET /admin/api/quality_control注意力チェックとゴールドスタンダードの統計情報を返します。
一致度メトリクス
http
GET /admin/api/agreementスキーマ別のKrippendorffのalphaを返します。
AIアシスタントAPI
AI提案を取得
http
GET /get_ai_suggestion?instance_id={instance_id}AIアシスタントヘルプを取得
http
GET /api/ai_assistant?instance_id={instance_id}&schema={schema_name}例:完全なアノテーションフロー
python
import requests
BASE_URL = "http://localhost:8000"
session = requests.Session()
# 1. Login
session.post(f"{BASE_URL}/auth", data={
"username": "annotator1",
"password": "password123"
})
# 2. Get current instance
response = session.get(f"{BASE_URL}/api/current_instance")
instance_id = response.json()["instance_id"]
# 3. Get instance content
response = session.get(f"{BASE_URL}/api/spans/{instance_id}")
print(f"Text: {response.json()['text']}")
# 4. Submit annotation
session.post(f"{BASE_URL}/updateinstance", json={
"instance_id": instance_id,
"annotations": {"sentiment:positive": "1"}
})
# 5. Navigate to next instance
session.post(f"{BASE_URL}/go_to", json={"action": "next_instance"})例:管理者モニタリング
python
import requests
BASE_URL = "http://localhost:8000"
# Get overview
overview = requests.get(f"{BASE_URL}/admin/api/overview").json()
print(f"Progress: {overview['completion_rate']*100:.1f}%")
# Get agreement metrics
agreement = requests.get(f"{BASE_URL}/admin/api/agreement").json()
print(f"Agreement: alpha = {agreement['overall']['average_krippendorff_alpha']:.3f}")エラーレスポンス
すべてのエンドポイントはエラーレスポンスを返す可能性があります:
json
{"error": "Description of the error"}一般的なHTTPステータスコード:
400- Bad Request(無効なパラメータ)401- Unauthorized(セッションなし)403- Forbidden(権限不足)404- Not Found500- Internal Server Error
関連情報
- 管理者ダッシュボード - ウェブベースの管理インターフェース
- 品質管理 - 品質メトリクスAPI
- 行動トラッキング - インタラクショントラッキングAPI
実装の詳細については、ソースドキュメントを参照してください。