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§
- Chat
Message - One turn in a conversation sent to
GenClient::chat. - Chat
Outcome - What a chat turn produced: plain text and/or tool calls.
- Discovered
Model - 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
reqwestclient with a per-endpoint timeout. - Model
Caps - 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.
- Probe
Report - Result of a liveness probe: the verdict plus what led to it.
- Tool
Call - A call the model asked for.
- Tool
Spec - A function the model may call.
parametersis a JSON Schema object.
Enums§
- GenError
- Why a call failed.
NotSupportedis separated out so the caller can tell a host that simply lacks the endpoint from a real failure. - Probe
Verdict - 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”.