Skip to main content

Module genai

Module genai 

Source
Available on crate feature genai only.
Expand description

OpenAI-compatible generation client: chat, model discovery, image, video and speech generation.

GenClient talks to anything speaking the OpenAI dialect - LiteLLM, Ollama, LM Studio, vLLM, OpenRouter, the real thing. The base URL may or may not already include /v1; it is normalised either way, and the Authorization: Bearer header is only sent when an API key is set.

use foukoapi::genai::{ChatMessage, GenClient};

let client = GenClient::new("http://localhost:11434", None);

let text = client
    .chat(
        "llama3",
        &[
            ChatMessage::system("You are terse."),
            ChatMessage::user("Say hi."),
        ],
    )
    .await?;
println!("{text}");

let png = client.image("dall-e-3", "a fox in the snow").await?;
println!("{} bytes", png.len());

Structs§

ChatMessage
One turn in a conversation sent to GenClient::chat.
ChatOutcome
What a chat turn produced: plain text and/or tool calls.
DiscoveredModel
A model reported by GenClient::list_models, with its capabilities.
GenClient
A client for one OpenAI-compatible host. Cheap to clone-by-recreate; each call builds its own reqwest client with a per-endpoint timeout.
ModelCaps
What a model can produce, as a compact bitmask. Text isn’t a bit: an empty mask means “plain text model”, which keeps stored records small.
ProbeReport
Result of a liveness probe: the verdict plus what led to it.
ToolCall
A call the model asked for.
ToolSpec
A function the model may call. parameters is a JSON Schema object.

Enums§

GenError
Why a call failed. NotSupported is separated out so the caller can tell a host that simply lacks the endpoint from a real failure.
ProbeVerdict
What a probe decided about a model behind this host.

Constants§

KNOWN_VOICES
Voices the OpenAI speech endpoint ships with. A hint for bot UIs only - proxies may serve their own voices, so nothing is validated against this list.

Functions§

caps_from_name
Guess capabilities from the model name (lowercase contains).
is_cert_error
Whether an error looks like a TLS certificate problem: rustls reports self-signed certs as “invalid peer certificate: UnknownIssuer”.