Spaces:
Runtime error
Runtime error
File size: 751 Bytes
6b23458 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
use tonic::Request;
use crate::models::protos::text_embed::{
TextRequest, text_embedding_service_client::TextEmbeddingServiceClient,
};
pub struct TextEmbeddingService {
client: TextEmbeddingServiceClient<tonic::transport::Channel>,
}
impl TextEmbeddingService {
pub async fn new() -> anyhow::Result<Self> {
Ok(Self {
client: TextEmbeddingServiceClient::connect(std::env::var("EMBEDDING_SERVER_URL")?)
.await?,
})
}
pub async fn embed_text(&mut self, text: &str) -> anyhow::Result<Vec<f32>> {
let request = Request::new(TextRequest { text: text.into() });
let response = self.client.get_embedding(request).await?;
Ok(response.into_inner().embeddings)
}
}
|