aleph_alpha_client/semantic_embedding/
embedding_with_instruction.rs1use crate::{
2 semantic_embedding::{
3 embedding::SemanticEmbeddingOutput, RequestBody, DEFAULT_EMBEDDING_MODEL_WITH_INSTRUCTION,
4 },
5 Job, Prompt, Task,
6};
7use serde::Serialize;
8
9const ENDPOINT: &str = "instructable_embed";
10
11#[derive(Serialize, Debug)]
16pub struct TaskSemanticEmbeddingWithInstruction<'a> {
17 pub instruction: &'a str,
24 #[serde(rename = "input")]
26 pub prompt: Prompt<'a>,
27 #[serde(skip_serializing_if = "Option::is_none")]
30 pub normalize: Option<bool>,
31}
32
33impl Task for TaskSemanticEmbeddingWithInstruction<'_> {
34 type Output = SemanticEmbeddingOutput;
35 type ResponseBody = SemanticEmbeddingOutput;
36
37 fn build_request(
38 &self,
39 client: &reqwest::Client,
40 base: &str,
41 model: &str,
42 ) -> reqwest::RequestBuilder {
43 let body = RequestBody {
44 model,
45 semantic_embedding_task: self,
46 };
47 client.post(format!("{base}/{ENDPOINT}")).json(&body)
48 }
49
50 fn body_to_output(&self, response: Self::ResponseBody) -> Self::Output {
51 response
52 }
53}
54
55impl Job for TaskSemanticEmbeddingWithInstruction<'_> {
56 type Output = SemanticEmbeddingOutput;
57 type ResponseBody = SemanticEmbeddingOutput;
58
59 fn build_request(&self, client: &reqwest::Client, base: &str) -> reqwest::RequestBuilder {
60 let body = RequestBody {
61 model: DEFAULT_EMBEDDING_MODEL_WITH_INSTRUCTION,
62 semantic_embedding_task: self,
63 };
64 client.post(format!("{base}/{ENDPOINT}")).json(&body)
65 }
66
67 fn body_to_output(&self, response: Self::ResponseBody) -> Self::Output {
68 response
69 }
70}