Ir al contenido

Inicio rápido

Elija su tiempo de ejecución y comience a realizar llamadas de IA en minutos.

  • Una clave API de cualquier proveedor compatible (por ejemplo, OPENAI_API_KEY, ANTHROPIC_API_KEY, DEEPSEEK_API_KEY)
  • El repositorio AI-Protocol (se obtiene automáticamente de GitHub si no es local)
[dependencies]
ai-lib = "0.7"
tokio = { version = "1", features = ["full"] }
Ventana de terminal
export ANTHROPIC_API_KEY="your-key-here"
use ai_lib::{AiClient, StreamingEvent};
use futures::StreamExt;
#[tokio::main]
async fn main() -> ai_lib::Result<()> {
// Create client — protocol manifest is loaded automatically
let client = AiClient::new("anthropic/claude-3-5-sonnet").await?;
// Streaming chat
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(())
}
Ventana de terminal
cargo run
Ventana de terminal
pip install ai-lib-python>=0.6.0
Ventana de terminal
export ANTHROPIC_API_KEY="your-key-here"
import asyncio
from ai_lib_python import AiClient
async def main():
# Create client — protocol manifest loaded automatically
client = await AiClient.create("anthropic/claude-3-5-sonnet")
# Streaming chat
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())
Ventana de terminal
python main.py

La magia de AI-Lib: cambie una cadena para cambiar de proveedor.

// Rust — just change the model 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 — same thing
client = await AiClient.create("openai/gpt-4o")
client = await AiClient.create("deepseek/deepseek-chat")
client = await AiClient.create("gemini/gemini-2.0-flash")

No se necesitan cambios de código. El manifiesto del protocolo maneja endpoint, autenticación, mapeo de parámetros y formato de streaming para cada proveedor.