pub struct Client { /* private fields */ }Implementations§
Source§impl Client
impl Client
pub fn new(api_key: &str) -> Self
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create a new xAI client from the XAI_API_KEY environment variable.
Panics if the environment variable is not set.
pub fn post(&self, path: &str) -> RequestBuilder
Sourcepub fn embedding_model(&self, model: &str) -> EmbeddingModel
pub fn embedding_model(&self, model: &str) -> EmbeddingModel
Create an embedding model with the given name.
Note: default embedding dimension of 0 will be used if model is not known.
If this is the case, it’s better to use function embedding_model_with_ndims
§Example
use rig::providers::xai::{Client, self};
// Initialize the xAI client
let xai = Client::new("your-xai-api-key");
let embedding_model = xai.embedding_model(xai::embedding::EMBEDDING_V1);Sourcepub fn embedding_model_with_ndims(
&self,
model: &str,
ndims: usize,
) -> EmbeddingModel
pub fn embedding_model_with_ndims( &self, model: &str, ndims: usize, ) -> EmbeddingModel
Create an embedding model with the given name and the number of dimensions in the embedding generated by the model.
§Example
use rig::providers::xai::{Client, self};
// Initialize the xAI client
let xai = Client::new("your-xai-api-key");
let embedding_model = xai.embedding_model_with_ndims("model-unknown-to-rig", 1024);Sourcepub fn embeddings<D: Embed>(
&self,
model: &str,
) -> EmbeddingsBuilder<EmbeddingModel, D>
pub fn embeddings<D: Embed>( &self, model: &str, ) -> EmbeddingsBuilder<EmbeddingModel, D>
Create an embedding builder with the given embedding model.
§Example
use rig::providers::xai::{Client, self};
// Initialize the xAI client
let xai = Client::new("your-xai-api-key");
let embeddings = xai.embeddings(xai::embedding::EMBEDDING_V1)
.simple_document("doc0", "Hello, world!")
.simple_document("doc1", "Goodbye, world!")
.build()
.await
.expect("Failed to embed documents");Sourcepub fn completion_model(&self, model: &str) -> CompletionModel
pub fn completion_model(&self, model: &str) -> CompletionModel
Create a completion model with the given name.
Sourcepub fn agent(&self, model: &str) -> AgentBuilder<CompletionModel>
pub fn agent(&self, model: &str) -> AgentBuilder<CompletionModel>
Create an agent builder with the given completion model.
§Example
use rig::providers::xai::{Client, self};
// Initialize the xAI client
let xai = Client::new("your-xai-api-key");
let agent = xai.agent(xai::completion::GROK_BETA)
.preamble("You are comedian AI with a mission to make people laugh.")
.temperature(0.0)
.build();Sourcepub fn extractor<T: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync>(
&self,
model: &str,
) -> ExtractorBuilder<T, CompletionModel>
pub fn extractor<T: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync>( &self, model: &str, ) -> ExtractorBuilder<T, CompletionModel>
Create an extractor builder with the given completion model.
Trait Implementations§
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
Mutably borrows from an owned value. Read more