Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ members = ["mixtape-core", "mixtape-anthropic-sdk", "mixtape-tools", "mixtape-cl
resolver = "2"

[workspace.package]
version = "0.3.1"
version = "0.4.0"
edition = "2021"
license = "MIT"
homepage = "https://github.com/adlio/mixtape"
repository = "https://github.com/adlio/mixtape"

[workspace.dependencies]
# Internal crates
mixtape-core = { version = "0.3.1", path = "./mixtape-core" }
mixtape-anthropic-sdk = { version = "0.3.1", path = "./mixtape-anthropic-sdk" }
mixtape-core = { version = "0.4.0", path = "./mixtape-core" }
mixtape-anthropic-sdk = { version = "0.4.0", path = "./mixtape-anthropic-sdk" }
mixtape-tools = { path = "./mixtape-tools" }
mixtape-cli = { path = "./mixtape-cli" }
mixtape-server = { path = "./mixtape-server" }
Expand All @@ -33,7 +33,7 @@ tower-http = { version = "0.6", features = ["cors", "trace"] }
# Serialization
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
schemars = "0.8"
schemars = "1.2"

# Error handling
thiserror = "1.0"
Expand Down
19 changes: 8 additions & 11 deletions mixtape-anthropic-sdk/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl ToolInputSchema {
}
}

/// Create a ToolInputSchema from a schemars RootSchema
/// Create a ToolInputSchema from a schemars Schema
///
/// This converts a schema generated by `schemars::schema_for!()` into
/// the format expected by the Anthropic API. Requires the `schemars` feature.
Expand All @@ -149,12 +149,12 @@ impl ToolInputSchema {
/// }
///
/// let schema = schema_for!(WeatherParams);
/// let tool_schema = ToolInputSchema::from_root_schema(&schema);
/// let tool_schema = ToolInputSchema::from_schema(&schema);
/// # }
/// ```
#[cfg(feature = "schemars")]
pub fn from_root_schema(schema: &schemars::schema::RootSchema) -> Self {
// Convert the root schema to a Value, then extract what we need
pub fn from_schema(schema: &schemars::Schema) -> Self {
// Convert the schema to a Value, then extract what we need
let schema_value =
serde_json::to_value(schema).unwrap_or(Value::Object(Default::default()));

Expand All @@ -176,10 +176,7 @@ impl ToolInputSchema {
.collect()
});

// Copy over definitions if present (for nested types)
if let Some(defs) = schema_value.get("definitions") {
additional.insert("definitions".to_string(), defs.clone());
}
// Copy over $defs if present (for nested types)
if let Some(defs) = schema_value.get("$defs") {
additional.insert("$defs".to_string(), defs.clone());
}
Expand Down Expand Up @@ -407,7 +404,7 @@ mod tests {

#[cfg(feature = "schemars")]
#[test]
fn test_from_root_schema() {
fn test_from_schema() {
use schemars::{schema_for, JsonSchema};

#[derive(JsonSchema)]
Expand All @@ -417,8 +414,8 @@ mod tests {
unit: Option<String>,
}

let root_schema = schema_for!(TestParams);
let tool_schema = ToolInputSchema::from_root_schema(&root_schema);
let schema = schema_for!(TestParams);
let tool_schema = ToolInputSchema::from_schema(&schema);

assert_eq!(tool_schema.schema_type, "object");
assert!(tool_schema.properties.is_some());
Expand Down