mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-08-22 15:15:34 +00:00
Fix input type for embedding
This commit is contained in:
@ -8,7 +8,7 @@ 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());
|
||||
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?;
|
||||
|
@ -11,10 +11,18 @@ 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")]
|
||||
@ -22,10 +30,11 @@ pub struct EmbeddingRequest {
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
|
Reference in New Issue
Block a user