Skip to content

Commit

Permalink
1. remove unused dependences
Browse files Browse the repository at this point in the history
2. fix bug
  • Loading branch information
zTgx committed Jan 29, 2025
1 parent 88335f0 commit 3dd4b91
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 63 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ base64 = "0.22.1"
anyhow = "1.0.80"
solana-account-decoder = "2.1.9"
helius = "0.2.4"
proc-macro2 = "1"
quote = "1"
syn = "2"

[dev-dependencies]
tokio = { version = "1.42.0", features = ["full"] }
Expand Down
23 changes: 6 additions & 17 deletions src/tools/fetch_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,14 @@ impl Tool for FetchPrice {
description: r#"
Fetch the current price of a Solana token in USDC using Jupiter API.
examples: [
[
{
input: {
tokenAddress: "So11111111111111111111111111111111111111112",
},
output: {
status: "success",
price: "23.45",
message: "Current price: $23.45 USDC",
},
explanation: "Get the current price of SOL token in USDC",
},
],
]
"#
input: {
token_address: "So11111111111111111111111111111111111111112",
},
"#
.to_string(),
parameters: parameters_json_schema!(
token_id: String,
token_address: String,
),
}
}
Expand Down
79 changes: 39 additions & 40 deletions src/utils/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,51 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use serde_json::{json, Value};

pub fn get_json_type(ty: &syn::Type) -> Value {
match ty {
syn::Type::Path(type_path) => {
let segment = &type_path.path.segments[0];
let type_name = segment.ident.to_string();

match type_name.as_str() {
"Vec" => {
if let syn::PathArguments::AngleBracketed(args) = &segment.arguments {
if let syn::GenericArgument::Type(inner_type) = &args.args[0] {
let inner_json_type = get_json_type(inner_type);
return json!({
"type": "array",
"items": inner_json_type
});
}
}
json!({ "type": "object" })
}
"i8" | "i16" | "i32" | "i64" | "u8" | "u16" | "u32" | "u64" | "f32" | "f64" => {
json!({ "type": "number" })
}
"String" | "str" => {
json!({ "type": "string" })
}
"bool" => {
json!({ "type": "boolean" })
}
_ => {
json!({ "type": "object" })
}
}
}
_ => json!({ "type": "object" }),
}
}

#[doc(hidden)]
#[macro_export]
macro_rules! parameters_json_schema {
($($name:ident: $type:ty),* $(,)?) => {{
let mut properties = serde_json::Map::new();
$(
let property = $crate::utils::macros::get_json_type(&syn::parse_quote!(<$type>));
let property = match stringify!($type) {
"String" => json!({
"type": "string"
}),
"i32" | "i64" | "u64" | "u32" => json!({
"type": "number"
}),
"bool" => json!({
"type": "boolean"
}),

s if s.starts_with("Vec<") && s.ends_with(">") => {

let inner_type_str = &s[4..s.len() - 1];
let inner_type = match inner_type_str {
"String" => json!({
"type": "string"
}),
"i32" | "i64" | "u64" | "u32" => json!({
"type": "number"
}),
"bool" => json!({
"type": "boolean"
}),
_ => json!({
"type": "object"
}),
};
json!({
"type": "array",
"items": inner_type
})
}
_ => {
json!({
"type": "object"
})
}
};
properties.insert(stringify!($name).to_string(), property);
)*
json!({
Expand Down

0 comments on commit 3dd4b91

Please sign in to comment.