Expand description
§tiy-core
A unified LLM API and stateful Agent runtime in Rust.
This library provides:
- Unified API for multiple LLM providers (OpenAI, Anthropic, Google, Ollama, etc.)
- Streaming event-based responses
- Tool/function calling support
- Stateful agent with tool execution
§Example
use tiy_core::{provider::openai::OpenAIProvider, types::*};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a model
let model = Model {
id: "gpt-4o-mini".to_string(),
name: "GPT-4o Mini".to_string(),
api: None,
provider: Provider::OpenAI,
base_url: Some("https://api.openai.com/v1".to_string()),
reasoning: false,
input: vec![InputType::Text, InputType::Image],
cost: Cost::default(),
context_window: 128000,
max_tokens: 16384,
headers: None,
compat: None,
};
// Create context
let context = Context {
system_prompt: Some("You are a helpful assistant.".to_string()),
messages: vec![Message::User(UserMessage {
role: Role::User,
content: UserContent::Text("Hello!".to_string()),
timestamp: chrono::Utc::now().timestamp_millis(),
})],
tools: None,
};
Ok(())
}Re-exports§
pub use types::AgentLimits;pub use types::Api;pub use types::AssistantMessage;pub use types::ContentBlock;pub use types::Context;pub use types::Cost;pub use types::HeaderPolicy;pub use types::HttpLimits;pub use types::ImageContent;pub use types::InputType;pub use types::Message;pub use types::Model;pub use types::Provider;pub use types::Role;pub use types::SecurityConfig;pub use types::StopReason;pub use types::StreamLimits;pub use types::TextContent;pub use types::ThinkingContent;pub use types::Tool;pub use types::ToolCall;pub use types::ToolResultMessage;pub use types::UrlPolicy;pub use types::Usage;pub use types::UserMessage;pub use stream::EventStream;pub use agent::Agent;pub use agent::AgentStateSnapshot;pub use catalog::build_catalog_snapshot;pub use catalog::build_catalog_snapshot_manifest;pub use catalog::catalog_manifest_sidecar_path;pub use catalog::enrich_manual_model;pub use catalog::list_models;pub use catalog::list_models_with_enrichment;pub use catalog::load_catalog_metadata_store;pub use catalog::refresh_catalog_snapshot;pub use catalog::save_catalog_snapshot;pub use catalog::CatalogMetadataStore;pub use catalog::CatalogModelMatch;pub use catalog::CatalogModelMetadata;pub use catalog::CatalogRefreshResult;pub use catalog::CatalogRemoteConfig;pub use catalog::CatalogSnapshot;pub use catalog::CatalogSnapshotError;pub use catalog::CatalogSnapshotManifest;pub use catalog::EmptyCatalogMetadataStore;pub use catalog::FetchModelsRequest;pub use catalog::FileCatalogMetadataStore;pub use catalog::InMemoryCatalogMetadataStore;pub use catalog::ListModelsResult;pub use catalog::ModelCatalogError;pub use catalog::ProviderExtractedModel;pub use catalog::UnifiedModelInfo;
Modules§
- agent
- Agent module for stateful conversation handling.
- catalog
- Model catalog fetching, normalization, and metadata enrichment.
- models
- Predefined models and model registry.
- protocol
- Wire-format protocol implementations.
- provider
- LLM service provider facades and registry.
- stream
- Stream processing utilities.
- thinking
- Thinking/Reasoning configuration and utilities.
- transform
- Message transformation utilities.
- types
- Core type definitions for tiy-core.
- validation
- Tool parameter validation.