pub struct ChatGptClient { /* private fields */ }Expand description
OpenAI chat completion client.
Implementations§
Source§impl ChatGptClient
impl ChatGptClient
Sourcepub fn new(api_key: &str, model: &str) -> Result<Self>
pub fn new(api_key: &str, model: &str) -> Result<Self>
Create a new client. The API key is baked into the underlying
reqwest::Client as a default header so it doesn’t need to be
cloned per-request.
Sourcepub async fn chat(&self, messages: Vec<Message>) -> Result<String, LlmError>
pub async fn chat(&self, messages: Vec<Message>) -> Result<String, LlmError>
Send a blocking chat completion request, returning the full response.
Sourcepub async fn chat_with_tools(
&self,
messages: Vec<Message>,
tools: Option<&[ToolDefinition]>,
) -> Result<(Message, Option<String>), LlmError>
pub async fn chat_with_tools( &self, messages: Vec<Message>, tools: Option<&[ToolDefinition]>, ) -> Result<(Message, Option<String>), LlmError>
Non-streaming chat completion with tool support.
Returns the full assistant Message and the finish_reason.
The agent loop inspects these to decide whether to execute tools
or return the final answer.
Sourcepub fn chat_stream(
&self,
messages: Vec<Message>,
) -> impl Stream<Item = Result<String, LlmError>> + Send
pub fn chat_stream( &self, messages: Vec<Message>, ) -> impl Stream<Item = Result<String, LlmError>> + Send
Stream a chat completion, yielding content tokens as they arrive.
The returned stream is 'static – it clones the HTTP client and model
name so callers don’t need to worry about lifetimes.
Trait Implementations§
Source§impl Clone for ChatGptClient
impl Clone for ChatGptClient
Source§fn clone(&self) -> ChatGptClient
fn clone(&self) -> ChatGptClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ChatGptClient
impl !RefUnwindSafe for ChatGptClient
impl Send for ChatGptClient
impl Sync for ChatGptClient
impl Unpin for ChatGptClient
impl !UnwindSafe for ChatGptClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more