Skip to main content

Crate menta

Crate menta 

Source
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)] and ToolExecute
  • 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§

providers

Macros§

tools
Convenience macro for building a Vec<Tool> from one or more tool types.

Structs§

BatchEmbeddingResult
Batched embedding result.
EmbeddingResult
Single embedding result.
GenerateTextRequest
Builder for text generation requests.
GenerateTextResult
Final result returned by generate_text.
ModelMessage
A provider-agnostic chat/message item used for prompts, history, and tool results.
ModelRequest
Low-level provider request produced from a GenerateTextRequest.
ModelResponse
Raw provider response before typed output parsing.
ModelSettings
Per-request model configuration.
ProviderRegistration
Provider registration entry collected through inventory.
Tool
Executable tool wrapper used in requests.
ToolCall
A single model-initiated tool call.
ToolDefinition
Public description of a tool exposed to a model.
ToolFieldSchema
A named field inside a ToolObjectSchema.
ToolObjectSchema
Object schema used by ToolSchema::Object.
ToolResult
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.
FinishReason
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.
StreamEvent
Event returned by stream_text.
ToolChoice
Controls whether the model may call tools.
ToolSchema
JSON-schema-like description used for tool inputs, tool outputs, and typed outputs.

Traits§

EmbeddingModel
Trait implemented by embedding providers.
LanguageModel
Trait implemented by language model providers.
ToolExecute
Trait for executable tools that can be attached to a GenerateTextRequest.
ToolInput
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 implementing ToolExecute.

Type Aliases§

Result
Convenience result type used across the crate.
StreamTextStream

Derive Macros§

Tool
Derive macro for declaring tool input schemas from a struct with named fields.