Skip to content

Commit

Permalink
Merge pull request #121 from dongri/embedding
Browse files Browse the repository at this point in the history
Fix input type for embedding
  • Loading branch information
dongri authored Nov 8, 2024
2 parents 0a9f651 + 0ce0d3b commit 179b821
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions examples/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ use std::env;
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = OpenAIClient::new(env::var("OPENAI_API_KEY").unwrap().to_string());

let mut req =
EmbeddingRequest::new(TEXT_EMBEDDING_3_SMALL.to_string(), "story time".to_string());
let mut req = EmbeddingRequest::new(
TEXT_EMBEDDING_3_SMALL.to_string(),
vec!["story time".to_string(), "Once upon a time".to_string()],
);
req.dimensions = Some(10);

let result = client.embedding(req).await?;
Expand Down
13 changes: 11 additions & 2 deletions src/v1/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,30 @@ pub struct EmbeddingData {
pub index: i32,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum EncodingFormat {
Float,
Base64,
}

#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct EmbeddingRequest {
pub model: String,
pub input: String,
pub input: Vec<String>,
pub encoding_format: Option<EncodingFormat>,
#[serde(skip_serializing_if = "Option::is_none")]
pub dimensions: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub user: Option<String>,
}

impl EmbeddingRequest {
pub fn new(model: String, input: String) -> Self {
pub fn new(model: String, input: Vec<String>) -> Self {
Self {
model,
input,
encoding_format: None,
dimensions: None,
user: None,
}
Expand Down

0 comments on commit 179b821

Please sign in to comment.