pub struct GenericOpenAI<C: Config + Default = OpenAIConfig> {
pub stream_full: bool,
/* private fields */
}
openai
only.Expand description
Generic client for OpenAI
APIs.
Fields§
§stream_full: bool
Convenience option to stream the full response. Defaults to true, because nobody has time to reconstruct the delta. Disabling this will make the streamed content only return the delta, for when performance matters. This only has effect when streaming is enabled.
Implementations§
Source§impl GenericOpenAI<DashscopeConfig>
impl GenericOpenAI<DashscopeConfig>
pub fn builder() -> DashscopeBuilder
dashscope
only.Source§impl GenericOpenAI<GeminiConfig>
impl GenericOpenAI<GeminiConfig>
pub fn builder() -> GeminiBuilder
gemini
only.Source§impl GenericOpenAI<GroqConfig>
impl GenericOpenAI<GroqConfig>
pub fn builder() -> GroqBuilder
groq
only.Source§impl GenericOpenAI<OllamaConfig>
impl GenericOpenAI<OllamaConfig>
Sourcepub fn builder() -> OllamaBuilder
Available on crate feature ollama
only.
pub fn builder() -> OllamaBuilder
ollama
only.Build a new Ollama
instance
Source§impl GenericOpenAI<OpenRouterConfig>
impl GenericOpenAI<OpenRouterConfig>
Sourcepub fn builder() -> OpenRouterBuilder
Available on crate feature open-router
only.
pub fn builder() -> OpenRouterBuilder
open-router
only.Creates a new OpenRouterBuilder
for constructing OpenRouter
instances.
Source§impl GenericOpenAI
impl GenericOpenAI
Sourcepub fn builder() -> OpenAIBuilder
pub fn builder() -> OpenAIBuilder
Creates a new OpenAIBuilder
for constructing OpenAI
instances.
Source§impl<C: Config + Default> GenericOpenAI<C>
impl<C: Config + Default> GenericOpenAI<C>
Sourcepub async fn estimate_tokens(&self, value: impl Estimatable) -> Result<usize>
Available on crate feature tiktoken
only.
pub async fn estimate_tokens(&self, value: impl Estimatable) -> Result<usize>
tiktoken
only.Estimates the number of tokens for implementors of the Estimatable
trait.
I.e. String
, ChatMessage
etc
§Errors
Errors if tokinization fails in any way
pub fn with_default_prompt_model( &mut self, model: impl Into<String>, ) -> &mut Self
pub fn with_default_embed_model( &mut self, model: impl Into<String>, ) -> &mut Self
Sourcepub fn options(&self) -> &Options
pub fn options(&self) -> &Options
Retrieve a reference to the default options for the OpenAI
instance.
Sourcepub fn options_mut(&mut self) -> &mut Options
pub fn options_mut(&mut self) -> &mut Options
Retrieve a mutable reference to the default options for the OpenAI
instance.
Trait Implementations§
Source§impl<C: Config + Default + Sync + Send + Debug + Clone> ChatCompletion for GenericOpenAI<C>
impl<C: Config + Default + Sync + Send + Debug + Clone> ChatCompletion for GenericOpenAI<C>
fn complete<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, LanguageModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn complete_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = ChatCompletionStream> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn complete_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = ChatCompletionStream> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl<C: Clone + Config + Default> Clone for GenericOpenAI<C>
impl<C: Clone + Config + Default> Clone for GenericOpenAI<C>
Source§fn clone(&self) -> GenericOpenAI<C>
fn clone(&self) -> GenericOpenAI<C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<C: Config + Default + Sync + Send + Debug + Clone> EmbeddingModel for GenericOpenAI<C>
impl<C: Config + Default + Sync + Send + Debug + Clone> EmbeddingModel for GenericOpenAI<C>
Source§impl<C: Config + Default + Sync + Send + Debug + Clone> SimplePrompt for GenericOpenAI<C>
The SimplePrompt
trait defines a method for sending a prompt to an AI model and receiving a
response.
impl<C: Config + Default + Sync + Send + Debug + Clone> SimplePrompt for GenericOpenAI<C>
The SimplePrompt
trait defines a method for sending a prompt to an AI model and receiving a
response.
Source§fn prompt<'life0, 'async_trait>(
&'life0 self,
prompt: Prompt,
) -> Pin<Box<dyn Future<Output = Result<String, LanguageModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn prompt<'life0, 'async_trait>(
&'life0 self,
prompt: Prompt,
) -> Pin<Box<dyn Future<Output = Result<String, LanguageModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sends a prompt to the OpenAI API and returns the response content.
§Parameters
prompt
: A string slice that holds the prompt to be sent to the OpenAI API.
§Returns
Result<String>
: On success, returns the content of the response as aString
. On failure, returns an error wrapped in aResult
.
§Errors
- Returns an error if the model is not set in the default options.
- Returns an error if the request to the OpenAI API fails.
- Returns an error if the response does not contain the expected content.
fn name(&self) -> &'static str
Auto Trait Implementations§
impl<C> Freeze for GenericOpenAI<C>
impl<C = OpenAIConfig> !RefUnwindSafe for GenericOpenAI<C>
impl<C> Send for GenericOpenAI<C>
impl<C> Sync for GenericOpenAI<C>
impl<C> Unpin for GenericOpenAI<C>
impl<C = OpenAIConfig> !UnwindSafe for GenericOpenAI<C>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.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>
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.