AsyncChatCompletion

Struct AsyncChatCompletion 

Source
pub struct AsyncChatCompletion<N, M, S = StreamOff>{
    pub key: String,
    /* private fields */
}

Fields§

§key: String

Implementations§

Source§

impl<N, M> AsyncChatCompletion<N, M, StreamOff>

Source

pub fn new(model: N, messages: M, key: String) -> Self

Source

pub fn body_mut(&mut self) -> &mut ChatBody<N, M>

Source

pub fn add_messages(self, messages: M) -> Self

Source

pub fn with_request_id(self, request_id: impl Into<String>) -> Self

Source

pub fn with_do_sample(self, do_sample: bool) -> Self

Source

pub fn with_stream(self, stream: bool) -> Self

👎Deprecated: Use enable_stream()/disable_stream() for compile-time guarantees
Source

pub fn with_tool_stream(self, tool_stream: bool) -> Self

Source

pub fn with_temperature(self, temperature: f32) -> Self

Source

pub fn with_top_p(self, top_p: f32) -> Self

Source

pub fn with_max_tokens(self, max_tokens: u32) -> Self

Source

pub fn add_tool(self, tool: Tools) -> Self

Source

pub fn add_tools(self, tools: Vec<Tools>) -> Self

Source

pub fn with_user_id(self, user_id: impl Into<String>) -> Self

Source

pub fn with_stop(self, stop: String) -> Self

Source

pub fn with_thinking(self, thinking: ThinkingType) -> Self
where N: ThinkEnable,

Source

pub fn enable_stream(self) -> AsyncChatCompletion<N, M, StreamOn>

Source

pub fn disable_stream(self) -> AsyncChatCompletion<N, M, StreamOff>

Source

pub fn validate(&self) -> Result<()>

Validate request parameters for non-stream async chat (StreamOff)

Source

pub async fn send(&self) -> Result<ChatCompletionResponse>
where N: Serialize, M: Serialize,

Send the request and parse typed response. Automatically runs validate() before sending.

Source§

impl<N, M> AsyncChatCompletion<N, M, StreamOn>

Source

pub fn with_tool_stream(self, tool_stream: bool) -> Self

Trait Implementations§

Source§

impl<N, M, S> HttpClient for AsyncChatCompletion<N, M, S>

Source§

type Body = ChatBody<N, M>

The request body type that must implement JSON serialization.
Source§

type ApiUrl = &'static str

The API URL type that must be convertible to a string reference.
Source§

type ApiKey = String

The API key type that must be convertible to a string reference.
Source§

fn api_url(&self) -> &Self::ApiUrl

Returns a reference to the API URL.
Source§

fn api_key(&self) -> &Self::ApiKey

Returns a reference to the API key for authentication.
Source§

fn body(&self) -> &Self::Body

Returns a reference to the request body.
Source§

fn post(&self) -> impl Future<Output = Result<Response>> + Send

Sends a POST request to the API endpoint. Read more
Source§

fn get(&self) -> impl Future<Output = Result<Response>> + Send

Sends a GET request to the API endpoint. Read more
Source§

impl<N, M> SseStreamable for AsyncChatCompletion<N, M, StreamOn>

Source§

fn stream_sse_for_each<'a, F>( &'a mut self, on_data: F, ) -> impl Future<Output = Result<()>> + 'a
where F: FnMut(&[u8]) + 'a,

Source§

impl<N, M> StreamChatLikeExt for AsyncChatCompletion<N, M, StreamOn>

Source§

fn stream_for_each<'a, F, Fut>( &'a mut self, on_chunk: F, ) -> impl Future<Output = Result<()>> + 'a
where F: FnMut(ChatStreamResponse) -> Fut + 'a, Fut: Future<Output = Result<()>> + 'a,

Processes streaming responses using an async callback function. Read more
Source§

fn to_stream<'a>( &'a mut self, ) -> impl Future<Output = Result<Pin<Box<dyn Stream<Item = Result<ChatStreamResponse>> + Send + 'static>>>> + 'a

Converts the streaming response into a composable Stream. Read more

Auto Trait Implementations§

§

impl<N, M, S> Freeze for AsyncChatCompletion<N, M, S>
where N: Freeze,

§

impl<N, M, S> RefUnwindSafe for AsyncChatCompletion<N, M, S>

§

impl<N, M, S> Send for AsyncChatCompletion<N, M, S>
where N: Send, S: Send, M: Send,

§

impl<N, M, S> Sync for AsyncChatCompletion<N, M, S>
where N: Sync, S: Sync, M: Sync,

§

impl<N, M, S> Unpin for AsyncChatCompletion<N, M, S>
where N: Unpin, S: Unpin, M: Unpin,

§

impl<N, M, S> UnwindSafe for AsyncChatCompletion<N, M, S>
where N: UnwindSafe, S: UnwindSafe, M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,