aleph_alpha_client/semantic_embedding/
embedding_batch.rs1use crate::semantic_embedding::{RequestBody, DEFAULT_EMBEDDING_MODEL};
2use crate::{Job, Prompt, SemanticRepresentation};
3use serde::{Deserialize, Serialize};
4
5const ENDPOINT: &str = "batch_semantic_embed";
6
7#[derive(Serialize, Debug)]
9pub struct TaskBatchSemanticEmbedding<'a> {
10 pub prompts: Vec<Prompt<'a>>,
12 pub representation: SemanticRepresentation,
15 #[serde(skip_serializing_if = "Option::is_none")]
25 pub compress_to_size: Option<u32>,
26}
27
28#[derive(Deserialize)]
30pub struct BatchSemanticEmbeddingOutput {
31 pub embeddings: Vec<Vec<f32>>,
32}
33
34impl Job for TaskBatchSemanticEmbedding<'_> {
35 type Output = BatchSemanticEmbeddingOutput;
36 type ResponseBody = BatchSemanticEmbeddingOutput;
37
38 fn build_request(&self, client: &reqwest::Client, base: &str) -> reqwest::RequestBuilder {
39 let body = RequestBody {
40 model: DEFAULT_EMBEDDING_MODEL,
41 semantic_embedding_task: self,
42 };
43 client.post(format!("{base}/{ENDPOINT}")).json(&body)
44 }
45
46 fn body_to_output(&self, response: Self::ResponseBody) -> Self::Output {
47 response
48 }
49}