Skip to content

Commit 179b821

Browse files
authored
Merge pull request #121 from dongri/embedding
Fix input type for embedding
2 parents 0a9f651 + 0ce0d3b commit 179b821

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

examples/embedding.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ use std::env;
77
async fn main() -> Result<(), Box<dyn std::error::Error>> {
88
let client = OpenAIClient::new(env::var("OPENAI_API_KEY").unwrap().to_string());
99

10-
let mut req =
11-
EmbeddingRequest::new(TEXT_EMBEDDING_3_SMALL.to_string(), "story time".to_string());
10+
let mut req = EmbeddingRequest::new(
11+
TEXT_EMBEDDING_3_SMALL.to_string(),
12+
vec!["story time".to_string(), "Once upon a time".to_string()],
13+
);
1214
req.dimensions = Some(10);
1315

1416
let result = client.embedding(req).await?;

src/v1/embedding.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,30 @@ pub struct EmbeddingData {
1111
pub index: i32,
1212
}
1313

14+
#[derive(Debug, Serialize, Deserialize, Clone)]
15+
#[serde(rename_all = "lowercase")]
16+
pub enum EncodingFormat {
17+
Float,
18+
Base64,
19+
}
20+
1421
#[derive(Debug, Serialize, Clone, Deserialize)]
1522
pub struct EmbeddingRequest {
1623
pub model: String,
17-
pub input: String,
24+
pub input: Vec<String>,
25+
pub encoding_format: Option<EncodingFormat>,
1826
#[serde(skip_serializing_if = "Option::is_none")]
1927
pub dimensions: Option<i32>,
2028
#[serde(skip_serializing_if = "Option::is_none")]
2129
pub user: Option<String>,
2230
}
2331

2432
impl EmbeddingRequest {
25-
pub fn new(model: String, input: String) -> Self {
33+
pub fn new(model: String, input: Vec<String>) -> Self {
2634
Self {
2735
model,
2836
input,
37+
encoding_format: None,
2938
dimensions: None,
3039
user: None,
3140
}

0 commit comments

Comments
 (0)