Skip to main content

Api

Struct Api 

Source
pub struct Api { /* private fields */ }
Expand description

Concrete API client that talks to the remote service using reqwest.

Implementations§

Source§

impl Api

Source

pub fn new(auth: Auth) -> Self

Constructs a new Api client with the supplied auth settings.

Trait Implementations§

Source§

impl ApiBase for Api

Source§

fn base_uri(&self) -> &str

Returns the root URL that is prepended to every request path.
Source§

async fn get(&self, endpoint: &str) -> Result<String>

Issues a GET request and returns the full response body as String.
Source§

async fn post_multipart( &self, endpoint: &str, multipart: Multipart, ) -> Result<String>

Issues a multipart POST request and returns the full response body as String.
Source§

async fn post_json<S>(&self, endpoint: &str, body: S) -> Result<String>
where S: Send + Serialize,

Issues a JSON POST request and returns the full response body as String.
Source§

async fn sse<S, H>( &self, endpoint: &str, body: S, options: SseOptions<H>, ) -> Result<Pin<Box<dyn Send + Stream<Item = Result<H::Event>>>>>
where S: Send + Serialize, H: 'static + EventHandler,

Performs a streaming POST request and yields server-sent events.
Source§

async fn sse_with_resume<S, H>( &self, endpoint: &str, body: S, options: SseOptions<H>, last_event_id: Option<&str>, ) -> Result<Pin<Box<dyn Send + Stream<Item = Result<H::Event>>>>>
where S: Send + Serialize, H: 'static + EventHandler,

Same as sse but supports resuming from a given event ID.
Source§

impl Clone for Api

Source§

fn clone(&self) -> Api

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Api

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Api

§

impl !UnwindSafe for Api

§

impl Freeze for Api

§

impl Send for Api

§

impl Sync for Api

§

impl Unpin for Api

§

impl UnsafeUnpin for Api

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> ApiBatch for T
where T: ApiBase,

Source§

fn create_batch( &self, request: BatchRequest, ) -> impl Send + Future<Output = Result<BatchObject>>

Create a batch.
Source§

fn retrieve_batch( &self, id: &str, ) -> impl Send + Future<Output = Result<BatchObject>>

Retrieve a batch by ID.
Source§

impl<T> ApiChat for T
where T: ApiBase,

Source§

fn create_chat( &self, request: ChatRequest, ) -> impl Send + Future<Output = Result<ChatObject>>

Create a chat.
Source§

fn create_chat_stream<H>( &self, request: ChatRequest, options: SseOptions<H>, ) -> impl Send + Future<Output = Result<Pin<Box<dyn Send + Stream<Item = Result<H::Event>>>>>>
where H: 'static + EventHandler,

Create a chat with streaming.
Source§

impl<T> ApiEmbedding for T
where T: ApiBase,

Source§

fn create_embedding( &self, request: EmbeddingRequest, ) -> impl Send + Future<Output = Result<EmbeddingResponse>>

Create an embedding.
Source§

impl<T> ApiFile for T
where T: ApiBase,

Source§

fn upload_file( &self, name: &str, content: Vec<u8>, purpose: Purpose, ) -> impl Send + Future<Output = Result<FileObject>>

Upload a file.
Source§

fn retrieve_file_content( &self, file_id: &str, ) -> impl Send + Future<Output = Result<String>>

Retrieve a file content by its ID.
Source§

impl<T> ApiResponse for T
where T: ApiBase,

Source§

fn create_response( &self, request: ResponseRequest, ) -> impl Send + Future<Output = Result<ResponseObject>>

Create a response (non-streaming).
Source§

fn create_response_stream<H>( &self, request: ResponseRequest, options: SseOptions<H>, ) -> impl Send + Future<Output = Result<Pin<Box<dyn Send + Stream<Item = Result<H::Event>>>>>>
where H: 'static + EventHandler,

Create a response with streaming.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

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: Sized + 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: Sized + 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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