Struct Client

Source
pub struct Client {
    pub base_url: String,
    pub api_token: String,
    /* private fields */
}

Fields§

§base_url: String§api_token: String

Implementations§

Source§

impl Client

Source

pub fn new(api_token: String) -> Result<Self, ApiError>

A new instance of an Aleph Alpha client helping you interact with the Aleph Alpha API.

Source

pub fn new_with_base_url( base_url: String, api_token: String, ) -> Result<Self, ApiError>

In production you typically would want set this to https://api.aleph-alpha.com. Yet you may want to use a different instances for testing.

Source

pub async fn post<I: Serialize, O: DeserializeOwned>( &self, path: &str, data: &I, query: Option<Vec<(String, String)>>, ) -> Result<O, ApiError>

Source

pub async fn post_nice<I: Serialize, O: DeserializeOwned>( &self, path: &str, data: &I, nice: Option<bool>, ) -> Result<O, ApiError>

Source

pub async fn get<O: DeserializeOwned>(&self, path: &str) -> Result<O, ApiError>

Source

pub async fn get_string(&self, path: &str) -> Result<String, ApiError>

Source

pub async fn get_binary(&self, path: &str) -> Result<Bytes, ApiError>

Source

pub async fn completion( &self, req: &CompletionRequest, nice: Option<bool>, ) -> Result<CompletionResponse, ApiError>

Will complete a prompt using a specific model. Example usage:

use aleph_alpha_api::{error::ApiError, Client, CompletionRequest, LUMINOUS_BASE};

const AA_API_TOKEN: &str = "<YOUR_AA_API_TOKEN>";

async fn print_completion() -> Result<(), ApiError> {
   let client = Client::new(AA_API_TOKEN.to_owned())?;

   let request =
       CompletionRequest::from_text(LUMINOUS_BASE.to_owned(), "An apple a day".to_owned(), 10)
           .temperature(0.8)
           .top_k(50)
           .top_p(0.95)
           .best_of(2)
           .minimum_tokens(2);

   let response = client.completion(&request, Some(true)).await?;

   println!("An apple a day{}", response.best_text());

   Ok(())
}
Source

pub async fn evaluate( &self, req: &EvaluationRequest, nice: Option<bool>, ) -> Result<EvaluationResponse, ApiError>

Evaluates the model’s likelihood to produce a completion given a prompt.

Source

pub async fn explain( &self, req: &ExplanationRequest, nice: Option<bool>, ) -> Result<ExplanationResponse, ApiError>

Better understand the source of a completion, specifically on how much each section of a prompt impacts each token of the completion.

Source

pub async fn embed( &self, req: &EmbeddingRequest, nice: Option<bool>, ) -> Result<EmbeddingResponse, ApiError>

Embeds a text using a specific model. Resulting vectors that can be used for downstream tasks (e.g. semantic similarity) and models (e.g. classifiers).

Source

pub async fn semantic_embed( &self, req: &SemanticEmbeddingRequest, nice: Option<bool>, ) -> Result<SemanticEmbeddingResponse, ApiError>

Embeds a prompt using a specific model and semantic embedding method. Resulting vectors that can be used for downstream tasks (e.g. semantic similarity) and models (e.g. classifiers). To obtain a valid model,

Source

pub async fn batch_semantic_embed( &self, req: &BatchSemanticEmbeddingRequest, nice: Option<bool>, ) -> Result<BatchSemanticEmbeddingResponse, ApiError>

Embeds multiple prompts using a specific model and semantic embedding method. Resulting vectors that can be used for downstream tasks (e.g. semantic similarity) and models (e.g. classifiers).

Source

pub async fn tokenize( &self, req: &TokenizationRequest, ) -> Result<TokenizationResponse, ApiError>

Tokenize a prompt for a specific model.

Source

pub async fn detokenize( &self, req: &DetokenizationRequest, ) -> Result<DetokenizationResponse, ApiError>

Detokenize a list of tokens into a string.

Source

pub async fn get_tokenizer_binary(&self, model: &str) -> Result<Bytes, ApiError>

Source

pub async fn get_tokenizer(&self, model: &str) -> Result<Tokenizer, ApiError>

Source

pub async fn get_version(&self) -> Result<String, ApiError>

Will return the version number of the API that is deployed to this environment.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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,

Source§

impl<T> MaybeSendSync for T