Skip to main content

lm_studio_api_extended/embedding/
embed_request.rs

1/// EmbeddingRequest defines the structure for an 
2/// embedding API request.
3/// It specifies the model, input texts, and optional 
4/// encoding format for the request.
5use crate::{prelude::*, EmbeddingInput};
6use super::{ EmbeddingModel };
7
8
9#[derive(Debug, Clone, Serialize)]
10pub struct EmbeddingRequest {
11    /// Model to use for embedding. Determines which model 
12    /// will process the input.
13    pub model: EmbeddingModel,
14
15    /// Input text(s) to embed. Can be a batch of texts for efficiency.
16    pub input: EmbeddingInput,
17
18    /// Optional encoding format (e.g., "float"). Controls the output format 
19    /// of the embedding vector.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub encoding_format: Option<String>,
22}
23
24/// Provides a default EmbeddingRequest with empty input and default 
25/// encoding format.
26/// This is useful for initializing requests before populating fields.
27impl ::std::default::Default for EmbeddingRequest {
28    fn default() -> Self {
29        Self {
30            model: EmbeddingModel::Custom("".into()),
31            input: EmbeddingInput::from("Rust is magic."),
32            encoding_format: Some("float".to_string())
33        }
34    }
35}
36
37impl EmbeddingRequest {
38    pub fn make_sendable(&self, input: EmbeddingInput) -> Vec<String> {
39        match input {
40            EmbeddingInput::Sentence(s) => vec![s],
41            EmbeddingInput::Sentences(ss) => ss
42        }
43    }
44}