pub struct Client {
pub base_url: String,
pub api_token: String,
/* private fields */
}
Fields§
§base_url: String
§api_token: String
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(api_token: String) -> Result<Self, ApiError>
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.
Sourcepub fn new_with_base_url(
base_url: String,
api_token: String,
) -> Result<Self, ApiError>
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.
pub async fn post<I: Serialize, O: DeserializeOwned>( &self, path: &str, data: &I, query: Option<Vec<(String, String)>>, ) -> Result<O, ApiError>
pub async fn post_nice<I: Serialize, O: DeserializeOwned>( &self, path: &str, data: &I, nice: Option<bool>, ) -> Result<O, ApiError>
pub async fn get<O: DeserializeOwned>(&self, path: &str) -> Result<O, ApiError>
pub async fn get_string(&self, path: &str) -> Result<String, ApiError>
pub async fn get_binary(&self, path: &str) -> Result<Bytes, ApiError>
Sourcepub async fn completion(
&self,
req: &CompletionRequest,
nice: Option<bool>,
) -> Result<CompletionResponse, ApiError>
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(())
}
Sourcepub async fn evaluate(
&self,
req: &EvaluationRequest,
nice: Option<bool>,
) -> Result<EvaluationResponse, ApiError>
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.
Sourcepub async fn explain(
&self,
req: &ExplanationRequest,
nice: Option<bool>,
) -> Result<ExplanationResponse, ApiError>
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.
Sourcepub async fn embed(
&self,
req: &EmbeddingRequest,
nice: Option<bool>,
) -> Result<EmbeddingResponse, ApiError>
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).
Sourcepub async fn semantic_embed(
&self,
req: &SemanticEmbeddingRequest,
nice: Option<bool>,
) -> Result<SemanticEmbeddingResponse, ApiError>
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,
Sourcepub async fn batch_semantic_embed(
&self,
req: &BatchSemanticEmbeddingRequest,
nice: Option<bool>,
) -> Result<BatchSemanticEmbeddingResponse, ApiError>
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).
Sourcepub async fn tokenize(
&self,
req: &TokenizationRequest,
) -> Result<TokenizationResponse, ApiError>
pub async fn tokenize( &self, req: &TokenizationRequest, ) -> Result<TokenizationResponse, ApiError>
Tokenize a prompt for a specific model.
Sourcepub async fn detokenize(
&self,
req: &DetokenizationRequest,
) -> Result<DetokenizationResponse, ApiError>
pub async fn detokenize( &self, req: &DetokenizationRequest, ) -> Result<DetokenizationResponse, ApiError>
Detokenize a list of tokens into a string.
pub async fn get_tokenizer_binary(&self, model: &str) -> Result<Bytes, ApiError>
pub async fn get_tokenizer(&self, model: &str) -> Result<Tokenizer, ApiError>
Sourcepub async fn get_version(&self) -> Result<String, ApiError>
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> 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> 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 more