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
OpenAiAdapterBuilderso 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 ChatCompletionProvider for OpenAiAdapter
impl ChatCompletionProvider for OpenAiAdapter
Source§fn chat_complete<'s, M>(
&'s self,
params: ChatCompleteParameters<M>,
) -> Pin<Box<dyn Future<Output = Result<GenericChatCompletionResponse<GenericMessage>>> + Send + 's>>
fn chat_complete<'s, M>( &'s self, params: ChatCompleteParameters<M>, ) -> Pin<Box<dyn Future<Output = Result<GenericChatCompletionResponse<GenericMessage>>> + Send + 's>>
P::Output.Source§impl PromptExecutionProvider for OpenAiAdapter
Implementation of [ChatCompletionProvider] for the OpenAiAdapter.
impl PromptExecutionProvider for OpenAiAdapter
Implementation of [ChatCompletionProvider] 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/completionsendpoint 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§fn prompt_execute<'a, 'p, P>(
&'a self,
prompt: P,
) -> Pin<Box<dyn Future<Output = Result<GenericChatCompletionResponse<P::Output>>> + Send + 'p>>where
P: PromptTemplate + Send + Sync + 'p,
<P as IntoPrompt>::Message: Into<Self::Message>,
'a: 'p,
fn prompt_execute<'a, 'p, P>(
&'a self,
prompt: P,
) -> Pin<Box<dyn Future<Output = Result<GenericChatCompletionResponse<P::Output>>> + Send + 'p>>where
P: PromptTemplate + Send + Sync + 'p,
<P as IntoPrompt>::Message: Into<Self::Message>,
'a: 'p,
Perform a non-streaming chat completion and deserialize the result.
The method is object-safe by returning a boxed Future rather than using
async/await syntax directly.