Search Client¶
SearchClient は AI-Mage Search 向けの ORPC 専用クライアントです。すべての高レベル wrapper は選択された backend service の /rpc/<procedure> を呼び出します。
クライアント作成¶
from aimage import search
from aimage.search.settings import SearchService
client = search.client(
token="your_token_here",
service=SearchService.PROD,
)
直接作成することもできます。
from aimage.search.client import SearchClient
client = SearchClient(
api_key="your_api_key_here",
service="https://custom-api.example.com",
)
SearchClient は token、api_key、base_url、service、timeout、headers、その他の httpx.Client option を受け取ります。api_key は token より優先され、どちらも未指定の場合は AIMAGE_API_KEY と AIMAGE_SEARCH_TOKEN を読みます。
service には SearchService.PROD、SearchService.DEV、SearchService.STAGING、SearchService.LOCAL、または custom origin URL を渡せます。base_url を渡すと service より優先されます。
メールログインと TOTP¶
login context に入るとメールコードが送信されます。ユーザーがコードを受け取った後に検証します。
from aimage.search.client import SearchClient
from aimage.search.settings import SearchService
client = SearchClient(service=SearchService.PROD)
with client.login_with_email(email="[email protected]") as login:
result = login.code(input("email code> "))
backend が MFA を要求した場合は、続けて TOTP または recovery code を入力します。
with client.login_with_email(email="[email protected]") as login:
login.code(input("email code> "))
result = login.totp(input("totp> "))
一回の呼び出しでもログインできます。
client.login_with_email(
email="[email protected]",
email_code="123456",
totp_code="654321",
)
ORPC 呼び出し¶
SDK の wrapper はすべて ORPC endpoint を使います。
高レベル namespace は backend router の構造に合わせています。
client.data.characters.list(project_id="...")
client.data.translationTables.list(project_id="...")
client.kensaku.clips.textSearch(project_id="...", query="夕焼け")
client.kensaku.videos.processedFiles(video_id="...")
client.agent.read.projectContext(project_id="...")
主な namespace:
| Namespace | 範囲 |
|---|---|
client.auth |
login、現在ユーザー、MFA / TOTP |
client.data |
characters、resources、reference images、translation tables、manga、novels、dynamic tags |
client.kensaku |
projects、videos、clips、chatbot conversations |
client.agent |
agent read/write procedures |
作成、更新、削除、翻訳表、資料、Clip metadata、会話ブランチの API は CRUD と更新 API を参照してください。
読みやすい出力¶
主要モデルは短い str() 表示に対応しています。
repr() はデバッグ向けの詳細表示として残しています。