クイックスタート
クイックスタート
Section titled “クイックスタート”ランタイムを選んで、数分で AI 呼び出しを開始しましょう。
- サポート対象のプロバイダーの API キー(例:
OPENAI_API_KEY、ANTHROPIC_API_KEY、DEEPSEEK_API_KEY) - AI-Protocol リポジトリ(ローカルにない場合は GitHub から自動取得されます)
1. 依存関係を追加する
Section titled “1. 依存関係を追加する”[dependencies]ai-lib = "0.7"tokio = { version = "1", features = ["full"] }2. API キーを設定する
Section titled “2. API キーを設定する”export ANTHROPIC_API_KEY="your-key-here"3. 最初のプログラムを書く
Section titled “3. 最初のプログラムを書く”use ai_lib::{AiClient, StreamingEvent};use futures::StreamExt;
#[tokio::main]async fn main() -> ai_lib::Result<()> { // クライアントを作成 — プロトコルマニフェストは自動的に読み込まれます let client = AiClient::new("anthropic/claude-3-5-sonnet").await?;
// ストリーミングチャット let mut stream = client.chat() .user("What is AI-Protocol?") .temperature(0.7) .max_tokens(500) .stream() .execute_stream() .await?;
while let Some(event) = stream.next().await { match event? { StreamingEvent::ContentDelta { text, .. } => print!("{text}"), StreamingEvent::StreamEnd { .. } => println!(), _ => {} } } Ok(())}4. 実行する
Section titled “4. 実行する”cargo runPython
Section titled “Python”1. パッケージをインストールする
Section titled “1. パッケージをインストールする”pip install ai-lib-python>=0.6.02. API キーを設定する
Section titled “2. API キーを設定する”export ANTHROPIC_API_KEY="your-key-here"3. 最初のスクリプトを書く
Section titled “3. 最初のスクリプトを書く”import asynciofrom ai_lib_python import AiClient
async def main(): # クライアントを作成 — プロトコルマニフェストは自動的に読み込まれます client = await AiClient.create("anthropic/claude-3-5-sonnet")
# ストリーミングチャット async for event in client.chat() \ .user("What is AI-Protocol?") \ .temperature(0.7) \ .max_tokens(500) \ .stream(): if event.is_content_delta: print(event.as_content_delta.text, end="") print()
asyncio.run(main())4. 実行する
Section titled “4. 実行する”python main.pyプロバイダーの切り替え
Section titled “プロバイダーの切り替え”AI-Lib の醍醐味:1 つの文字列を変更するだけでプロバイダーを切り替えられます。
// Rust — モデル ID を変更するだけlet client = AiClient::new("openai/gpt-4o").await?;let client = AiClient::new("deepseek/deepseek-chat").await?;let client = AiClient::new("gemini/gemini-2.0-flash").await?;# Python — 同じことclient = await AiClient.create("openai/gpt-4o")client = await AiClient.create("deepseek/deepseek-chat")client = await AiClient.create("gemini/gemini-2.0-flash")コード変更は不要です。プロトコルマニフェストが各プロバイダーのエンドポイント、認証、パラメータマッピング、ストリーミング形式を処理します。
次のステップ
Section titled “次のステップ”- エコシステムアーキテクチャ — 構成要素の関係
- チャット補完ガイド — チャット API の詳細な使い方
- Function Calling — ツール使用と function calling
- Rust SDK 詳細 — Rust の詳細
- Python SDK 詳細 — Python の詳細