Skip to content

Commit

Permalink
refactor: Remove ToolParameterType and ToolParameter structs to simpl…
Browse files Browse the repository at this point in the history
…ify code

Will be using regular JSON for this part.

Signed-off-by: Eden Reich <[email protected]>
  • Loading branch information
edenreich committed Feb 9, 2025
1 parent 62b7463 commit 0e4d1b4
Showing 1 changed file with 2 additions and 43 deletions.
45 changes: 2 additions & 43 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,54 +174,13 @@ pub enum ToolType {
Function,
}

/// JSON Schema parameter types for tools
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum ToolParameterType {
String,
Number,
Integer,
Boolean,
Array,
Object,
Null,
}

impl Default for ToolParameterType {
fn default() -> Self {
Self::String
}
}

impl std::fmt::Display for ToolParameterType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::String => write!(f, "string"),
Self::Number => write!(f, "number"),
Self::Integer => write!(f, "integer"),
Self::Boolean => write!(f, "boolean"),
Self::Array => write!(f, "array"),
Self::Object => write!(f, "object"),
Self::Null => write!(f, "null"),
}
}
}

/// Tool to use for the LLM toolbox
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Tool {
pub r#type: ToolType,
pub function: ToolFunction,
}

/// Parameters for a tool
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ToolParameter {
pub r#type: ToolParameterType,
pub properties: Option<Vec<ToolParameter>>,
pub required: Vec<String>,
}

/// Request payload for generating content
#[derive(Debug, Serialize)]
struct GenerateRequest {
Expand All @@ -240,14 +199,14 @@ struct GenerateRequest {
/// A tool call in the response
#[derive(Debug, Deserialize, Clone)]
pub struct ToolCallResponse {
/// Function that was called
/// Function that the LLM wants to call
pub function: ToolFunctionResponse,
}

/// Function details in a tool call response
#[derive(Debug, Deserialize, Clone)]
pub struct ToolFunctionResponse {
/// Name of the function that was called
/// Name of the function that the LLM wants to call
pub name: String,
/// Parameters passed to the function
pub parameters: Value,
Expand Down

0 comments on commit 0e4d1b4

Please sign in to comment.