Skip to content

Commit

Permalink
Merge pull request #126 from dongri/fix-run-object
Browse files Browse the repository at this point in the history
Fix run object
  • Loading branch information
dongri authored Nov 19, 2024
2 parents ec82143 + 9acf04f commit 79d18aa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 42 deletions.
42 changes: 1 addition & 41 deletions src/v1/assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,53 +57,13 @@ pub struct AssistantObject {
pub model: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub instructions: Option<String>,
pub tools: Vec<Tools>,
pub tools: Vec<types::Tools>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_resources: Option<ToolResource>,
pub metadata: Option<HashMap<String, String>>,
pub headers: Option<HashMap<String, String>>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum Tools {
CodeInterpreter,
FileSearch(ToolsFileSearch),
Function(ToolsFunction),
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ToolsFileSearch {
#[serde(skip_serializing_if = "Option::is_none")]
pub file_search: Option<ToolsFileSearchObject>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ToolsFunction {
pub function: types::Function,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ToolsFileSearchObject {
pub max_num_results: Option<u8>,
pub ranking_options: Option<FileSearchRankingOptions>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct FileSearchRankingOptions {
pub ranker: Option<FileSearchRanker>,
pub score_threshold: Option<f32>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub enum FileSearchRanker {
#[serde(rename = "auto")]
Auto,
#[serde(rename = "default_2024_08_21")]
Default2024_08_21,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ToolResource {
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
3 changes: 2 additions & 1 deletion src/v1/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

use super::types;
use crate::impl_builder_methods;

#[derive(Debug, Serialize, Clone)]
Expand Down Expand Up @@ -95,7 +96,7 @@ pub struct RunObject {
pub completed_at: Option<i64>,
pub model: String,
pub instructions: Option<String>,
pub tools: Vec<HashMap<String, String>>,
pub tools: Vec<types::Tools>,
pub metadata: HashMap<String, String>,
pub headers: Option<HashMap<String, String>>,
}
Expand Down
40 changes: 40 additions & 0 deletions src/v1/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,43 @@ pub struct JSONSchemaDefine {
#[serde(skip_serializing_if = "Option::is_none")]
pub items: Option<Box<JSONSchemaDefine>>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum Tools {
CodeInterpreter,
FileSearch(ToolsFileSearch),
Function(ToolsFunction),
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ToolsFileSearch {
#[serde(skip_serializing_if = "Option::is_none")]
pub file_search: Option<ToolsFileSearchObject>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ToolsFunction {
pub function: Function,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ToolsFileSearchObject {
pub max_num_results: Option<u8>,
pub ranking_options: Option<FileSearchRankingOptions>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct FileSearchRankingOptions {
pub ranker: Option<FileSearchRanker>,
pub score_threshold: Option<f32>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub enum FileSearchRanker {
#[serde(rename = "auto")]
Auto,
#[serde(rename = "default_2024_08_21")]
Default2024_08_21,
}

0 comments on commit 79d18aa

Please sign in to comment.