Expand description
Minimal Rust primitives for non-UI LLM and AI workflows.
menta focuses on a small core API for:
- text generation through provider-prefixed model ids such as
openai/gpt-4.1-mini - typed outputs with
GenerateTextRequest<T> - tool calling via
#[derive(Tool)]andToolExecute - embeddings and similarity ranking
§Quick Start
use menta::{GenerateTextRequest, generate_text};
#[tokio::main]
async fn main() -> Result<(), menta::Error> {
let result = generate_text(
GenerateTextRequest::new()
.model("openai/gpt-4.1-mini")
.prompt("Write a one-line summary of Rust."),
)
.await?;
println!("{}", result.text);
Ok(())
}§Typed Output
use menta::{GenerateTextRequest, generate_text};
use serde::Deserialize;
#[derive(Debug, Deserialize, schemars::JsonSchema)]
struct Summary {
title: String,
bullets: Vec<String>,
}
#[tokio::main]
async fn main() -> Result<(), menta::Error> {
let result = generate_text(
GenerateTextRequest::<Summary>::typed()
.model("openai/gpt-4.1-mini")
.prompt("Summarize Rust for backend engineers."),
)
.await?;
println!("{}", result.output.title);
Ok(())
}Modules§
Macros§
- tools
- Convenience macro for building a
Vec<Tool>from one or more tool types.
Structs§
- Batch
Embedding Result - Batched embedding result.
- Embedding
Result - Single embedding result.
- Generate
Text Request - Builder for text generation requests.
- Generate
Text Result - Final result returned by
generate_text. - Model
Message - A provider-agnostic chat/message item used for prompts, history, and tool results.
- Model
Request - Low-level provider request produced from a
GenerateTextRequest. - Model
Response - Raw provider response before typed output parsing.
- Model
Settings - Per-request model configuration.
- Provider
Registration - Provider registration entry collected through
inventory. - Tool
- Executable tool wrapper used in requests.
- Tool
Call - A single model-initiated tool call.
- Tool
Definition - Public description of a tool exposed to a model.
- Tool
Field Schema - A named field inside a
ToolObjectSchema. - Tool
Object Schema - Object schema used by
ToolSchema::Object. - Tool
Result - Result produced after a tool call is executed.
- Usage
- Token usage summary returned by generation and embedding operations.
Enums§
- Error
- Error type returned by the crate’s public APIs.
- Finish
Reason - Reason a generation finished.
- Output
- Output mode used when parsing generation results.
- Part
- A content part inside a model message or model response.
- Role
- Model message role used in requests and responses.
- Stream
Event - Event returned by
stream_text. - Tool
Choice - Controls whether the model may call tools.
- Tool
Schema - JSON-schema-like description used for tool inputs, tool outputs, and typed outputs.
Traits§
- Embedding
Model - Trait implemented by embedding providers.
- Language
Model - Trait implemented by language model providers.
- Tool
Execute - Trait for executable tools that can be attached to a
GenerateTextRequest. - Tool
Input - Trait implemented by tool input types.
Functions§
- cosine_
similarity - Computes cosine similarity for two embedding vectors.
- embed
- Embeds a single string with the given model id.
- embed_
many - Embeds multiple strings with the given model id.
- generate_
text - Generates text or structured output from a model.
- language_
model - Resolves a provider-prefixed model id to a
LanguageModel. - provider_
registry - Backwards-compatible alias for
registered_providers. - rank_
by_ similarity - Scores and sorts named embeddings by similarity to the query embedding.
- registered_
providers - Returns the sorted set of registered provider ids.
- stream_
text - Runs a single provider stream pass and returns collected stream events.
- tool
- Creates an executable [
Tool] from a type implementingToolExecute.
Type Aliases§
- Result
- Convenience result type used across the crate.
- Stream
Text Stream
Derive Macros§
- Tool
- Derive macro for declaring tool input schemas from a struct with named fields.