pub struct OpenAiAdapter { /* private fields */ }
Expand description
Thin wrapper that wires the HTTP client [OpenAiClient
] into a value that
implements artificial_core::backend::Backend
.
Think of it as the service locator for the OpenAI back-end:
- stores the API key (and optionally a custom base URL in the future),
- owns a shareable, connection-pooled
reqwest::Client
, - provides a fluent
OpenAiAdapterBuilder
so callers don’t have to juggleOption<String>
manually.
The type itself purposefully exposes no additional methods—all user-
facing functionality sits on the generic artificial_core::ArtificialClient
once the adapter is plugged in.
Trait Implementations§
Source§impl Backend for OpenAiAdapter
Implementation of Backend
for the OpenAiAdapter
.
impl Backend for OpenAiAdapter
Implementation of Backend
for the OpenAiAdapter
.
The type is only a thin glue layer—almost all heavy lifting is done by the
inner OpenAiClient
(HTTP) and the adapter’s config (API key, base URL, …).
Responsibilities:
- Convert the generic prompt into OpenAI‐compatible chat messages.
- Enrich the request with a JSON Schema derived from
Prompt::Output
. - Call the
/v1/chat/completions
endpoint and bubble up transport errors. - Validate & deserialize the returned JSON into
Prompt::Output
.
The implementation purposefully rejects any streaming or multi-choice responses for now; this keeps the surface minimal and makes error handling easier to reason about.
Source§type Message = ChatCompletionMessage
type Message = ChatCompletionMessage
Provider-specific chat message type.