Skip to content

Commit

Permalink
Merge pull request #70 from dongri/embedding-models
Browse files Browse the repository at this point in the history
Add embedding models
  • Loading branch information
Dongri Jin committed Jan 26, 2024
2 parents 91987ab + 4e6fbce commit a318b4e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 2 additions & 4 deletions examples/embedding.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use openai_api_rs::v1::api::Client;
use openai_api_rs::v1::common::TEXT_EMBEDDING_3_SMALL;
use openai_api_rs::v1::embedding::EmbeddingRequest;
use std::env;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string());

let req = EmbeddingRequest::new(
"text-embedding-ada-002".to_string(),
"story time".to_string(),
);
let req = EmbeddingRequest::new(TEXT_EMBEDDING_3_SMALL.to_string(), "story time".to_string());

let result = client.embedding(req)?;
println!("{:?}", result.data);
Expand Down
4 changes: 2 additions & 2 deletions src/v1/chat_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ pub struct ChatCompletionMessageForResponse {
pub tool_calls: Option<Vec<ToolCall>>,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct ChatCompletionChoice {
pub index: i64,
pub message: ChatCompletionMessageForResponse,
pub finish_reason: Option<FinishReason>,
pub finish_details: Option<FinishDetails>,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct ChatCompletionResponse {
pub id: String,
pub object: String,
Expand Down
9 changes: 7 additions & 2 deletions src/v1/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::Deserialize;
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct Usage {
pub prompt_tokens: i32,
pub completion_tokens: i32,
Expand Down Expand Up @@ -45,3 +45,8 @@ pub const GPT4_32K_0314: &str = "gpt-4-32k-0314";
// https://platform.openai.com/docs/api-reference/images/object
pub const DALL_E_2: &str = "dall-e-2";
pub const DALL_E_3: &str = "dall-e-3";

// https://platform.openai.com/docs/guides/embeddings/embedding-models
pub const TEXT_EMBEDDING_3_SMALL: &str = "text-embedding-3-small";
pub const TEXT_EMBEDDING_3_LARGE: &str = "text-embedding-3-large";
pub const TEXT_EMBEDDING_ADA_002: &str = "text-embedding-ada-002";

0 comments on commit a318b4e

Please sign in to comment.