use helios_engine::{Agent, CalculatorTool, Config, EndpointBuilder, ServerBuilder};
#[tokio::main]
async fn main() -> helios_engine::Result<()> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.init();
let config = Config::from_file("config.toml")?;
let agent = Agent::builder("API Agent")
.config(config)
.system_prompt("You are a helpful AI assistant with access to a calculator tool.")
.tool(Box::new(CalculatorTool))
.max_iterations(5)
.build()
.await?;
println!("🎉 Creating custom endpoints with the new simplified API!\n");
let version_endpoint = helios_engine::get(
"/api/version",
serde_json::json!({
"version": "0.4.4",
"service": "Helios Engine",
"features": ["agents", "tools", "streaming", "custom_endpoints"]
}),
);
let status_endpoint = helios_engine::get(
"/api/status",
serde_json::json!({
"status": "operational",
"model": "agent-based"
}),
);
let info_endpoint = EndpointBuilder::get("/api/info")
.json(serde_json::json!({
"name": "Helios Engine API",
"description": "AI Agent Server with Custom Endpoints",
"documentation": "https://helios-engine.vercel.app/"
}))
.description("API information endpoint")
.build();
let echo_endpoint = EndpointBuilder::post("/api/echo")
.handle(|req| {
let message = req
.and_then(|r| r.body)
.and_then(|b| b.get("message").cloned())
.unwrap_or_else(|| serde_json::json!("No message provided"));
helios_engine::EndpointResponse::ok(serde_json::json!({
"echo": message,
"timestamp": chrono::Utc::now().to_rfc3339()
}))
})
.description("Echo endpoint that returns your message")
.build();
let create_endpoint = EndpointBuilder::post("/api/create")
.json(serde_json::json!({
"message": "Resource created",
"id": "12345"
}))
.description("Simulates creating a resource")
.build();
let update_endpoint = EndpointBuilder::put("/api/update")
.json(serde_json::json!({
"message": "Resource updated"
}))
.description("Simulates updating a resource")
.build();
let delete_endpoint = helios_engine::delete(
"/api/delete",
serde_json::json!({
"message": "Resource deleted"
}),
);
let custom_endpoints = vec![
version_endpoint,
status_endpoint,
info_endpoint,
echo_endpoint,
create_endpoint,
update_endpoint,
delete_endpoint,
];
println!("🚀 Starting server with custom endpoints...\n");
println!("📡 OpenAI-compatible API endpoints:");
println!(" POST /v1/chat/completions");
println!(" GET /v1/models");
println!("\n📡 Custom endpoints:");
println!(" GET /api/version");
println!(" GET /api/status");
println!(" GET /api/info");
println!(" POST /api/echo");
println!(" POST /api/create");
println!(" PUT /api/update");
println!(" DELETE /api/delete");
println!("\n💡 Try these commands:");
println!(" curl http://127.0.0.1:8000/api/version");
println!(" curl http://127.0.0.1:8000/api/status");
println!(" curl -X POST http://127.0.0.1:8000/api/echo \\");
println!(" -H 'Content-Type: application/json' \\");
println!(" -d '{{\"message\": \"Hello, Helios!\"}}'");
println!();
ServerBuilder::with_agent(agent, "local-model")
.address("127.0.0.1:8000")
.endpoints(custom_endpoints)
.serve()
.await?;
Ok(())
}