From 4edae0f5389b85e38a1dea571154cebe0d1a6c77 Mon Sep 17 00:00:00 2001 From: Alfredo Gallardo Date: Wed, 6 Nov 2024 17:39:17 -0300 Subject: [PATCH] - improve: add logs to tests --- Cargo.lock | 135 ++++++++++++++++ libs/shinkai-tools-runner/Cargo.toml | 1 + libs/shinkai-tools-runner/src/lib.test.rs | 180 +++++++++++++++------- 3 files changed, 257 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fe1ffa..4f80918 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,6 +34,15 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -49,6 +58,55 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +dependencies = [ + "anstyle", + "windows-sys 0.59.0", +] + [[package]] name = "anyhow" version = "1.0.86" @@ -214,6 +272,12 @@ dependencies = [ "inout", ] +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "constant_time_eq" version = "0.3.0" @@ -404,6 +468,29 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -678,6 +765,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.29" @@ -773,6 +866,12 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itoa" version = "1.0.11" @@ -1234,6 +1333,35 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + [[package]] name = "reqwest" version = "0.11.27" @@ -1424,6 +1552,7 @@ dependencies = [ "derivative", "derive_more", "dispose", + "env_logger", "futures", "glob", "hex-simd", @@ -1732,6 +1861,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/libs/shinkai-tools-runner/Cargo.toml b/libs/shinkai-tools-runner/Cargo.toml index 832b690..df86720 100644 --- a/libs/shinkai-tools-runner/Cargo.toml +++ b/libs/shinkai-tools-runner/Cargo.toml @@ -29,6 +29,7 @@ zip = "2.2.0" tempfile = "3.13.0" log = "0.4.22" once_cell = { version = "1.20.2" } +env_logger = "0.11.5" [build-dependencies] copy_to_output = "2.2.0" diff --git a/libs/shinkai-tools-runner/src/lib.test.rs b/libs/shinkai-tools-runner/src/lib.test.rs index f6fb69c..7624c77 100644 --- a/libs/shinkai-tools-runner/src/lib.test.rs +++ b/libs/shinkai-tools-runner/src/lib.test.rs @@ -5,6 +5,10 @@ use crate::tools::tool::Tool; #[tokio::test] async fn shinkai_tool_echo() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-echo").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -20,6 +24,10 @@ async fn shinkai_tool_echo() { #[tokio::test] async fn shinkai_tool_weather_by_city() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-weather-by-city").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -34,6 +42,10 @@ async fn shinkai_tool_weather_by_city() { #[tokio::test] async fn shinkai_tool_inline() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let js_code = r#" function run(configurations, params) { return { message: `Hello, ${params.name}!` }; @@ -50,6 +62,10 @@ async fn shinkai_tool_inline() { #[tokio::test] async fn shinkai_tool_web3_eth_balance() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-web3-eth-balance").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -68,6 +84,10 @@ async fn shinkai_tool_web3_eth_balance() { #[tokio::test] async fn shinkai_tool_web3_eth_uniswap() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-web3-eth-uniswap").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -92,6 +112,10 @@ async fn shinkai_tool_web3_eth_uniswap() { #[tokio::test] async fn shinkai_tool_download_page() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-download-pages").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -112,6 +136,10 @@ async fn shinkai_tool_download_page() { #[tokio::test] async fn max_execution_time() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let js_code = r#" async function run(configurations, parameters) { let startedAt = Date.now(); @@ -138,6 +166,10 @@ async fn max_execution_time() { #[tokio::test] async fn shinkai_tool_download_page_stack_overflow() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let managed_thread = std::thread::Builder::new().stack_size(8 * 1024 * 1024); let run_result = managed_thread .spawn(move || { @@ -168,6 +200,10 @@ async fn shinkai_tool_download_page_stack_overflow() { #[tokio::test] async fn shinkai_tool_leiden() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-leiden").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -272,6 +308,10 @@ async fn shinkai_tool_leiden() { #[tokio::test] async fn shinkai_tool_duckduckgo_search() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-duckduckgo-search").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -298,6 +338,10 @@ async fn shinkai_tool_duckduckgo_search() { #[tokio::test] async fn shinkai_tool_playwright_example() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-playwright-example").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -324,6 +368,10 @@ async fn shinkai_tool_playwright_example() { #[tokio::test] async fn shinkai_tool_defillama_lending_tvl_rankings() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-defillama-tvl-rankings").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -346,6 +394,10 @@ async fn shinkai_tool_defillama_lending_tvl_rankings() { #[tokio::test] async fn shinkai_tool_aave_loan_requester() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-aave-loan-requester").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -363,6 +415,10 @@ async fn shinkai_tool_aave_loan_requester() { #[tokio::test] async fn shinkai_tool_youtube_summary() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-youtube-summary").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -384,6 +440,10 @@ async fn shinkai_tool_youtube_summary() { #[tokio::test] async fn shinkai_tool_json_to_md() { + let _ = env_logger::builder() + .filter_level(log::LevelFilter::Info) + .is_test(true) + .try_init(); let tool_definition = get_tool("shinkai-tool-json-to-md").unwrap(); let tool = Tool::new( tool_definition.code.clone().unwrap(), @@ -392,68 +452,70 @@ async fn shinkai_tool_json_to_md() { }), None, ); + let message = json!({ + "relevantSentencesFromText": [ + { + "citation_id": 5, + "document_reference": "[8] http://www.youtube.com/watch?v=eaSIq9c14YE", + "relevantSentenceFromDocument": + "This video describes the role of light in plant growth. A comparison of light detection by human eyes and light absorption by plants begins a little bit past the halfway point.", + }, + { + "citation_id": 0, + "document_reference": + "[6] Arizona Master Gardener Manual, by the University of Arizona College of Agriculture’s Cooperative Extension.", + "relevantSentenceFromDocument": + "This online book is a good example of a state-specific resource for learning about what plants need to thrive.", + }, + { + "citation_id": 0, + "document_reference": + "[6] Arizona Master Gardener Manual, by the University of Arizona College of Agriculture’s Cooperative Extension.", + "relevantSentenceFromDocument": + "This online book is a good example of a state-specific resource for learning about what plants need to thrive.", + }, + { + "citation_id": 11, + "document_reference": "[7]", + "relevantSentenceFromDocument": "", + }, + ], + "answer": { + "brief_introduction": { + "sentences": [ + "Transplanting a houseplant can be a delicate process that requires careful consideration of the plant’s needs and the conditions provided.", + "To ensure a successful transplant, it is essential to prepare the new pot and the soil, as well as the plant itself, in advance.", + "As explained by [0] on the Arizona Master Gardener Manual website,[6] this preparation can help reduce stress on the plant during the transplant process.", + ], + }, + "extensive_body": [ + { + "sentences": [ + "Firstly, as [1] describes, plants need light to grow and thrive. But different colors of light have varying effects on their development. For example, scientists on UCSB ScienceLine state that \"red light is often used to boost fruit production in greenhouses, while blue light can be used to increase plant growth\" [3].", + "When transplanting a houseplant, it is essential to choose a location with the right amount of light. As [1] explains, \"a comparison of light detection by human eyes and light absorption by plants begins a little bit past the halfway point.\" This means that even if a plant appears healthy in its current environment, it may require more or less light once moved to a new pot.", + "In addition to ensuring the right amount of light, it is crucial to prepare the soil properly. According to [10] on Arizona Master Gardener Manual website,[6]", + "Furthermore, plants have unique needs and preferences for optimal growth. As [1] notes that \"Plants are able to sense changes in their environment using abilities similar to human sight, touch, smell, taste, and hearing.\" This means that even small changes can affect the plant’s overall well-being.", + "To minimize transplant shock, gardeners should also consider the time of year when making a decision to move or transplant any plants. According to [4], it is best to do this during the spring season because this allows most species of deciduous trees and many other woody ornamental woody shrubs including fruit trees to start regrowth without major changes in weather as they usually require.", + "In terms of optimal growth conditions, different types of plants have varying requirements when it comes to light. [2] states that \"by using specialized colored filters over light lamps can produce higher plant weights\" which demonstrates the fact various colors used for plants growth at high concentration affect its height length and plant biomass. Various experiments conducted, by some research studies demonstrated 1-2-fold increase of both biomass growth rate as well plant quality in comparison with an equivalent plant grown without such lighting filters.", + ], + }, + ], + "conclusion": [ + { + "sentences": [ + "In conclusion, transplanting a houseplant requires careful consideration of its needs and the new environment. With this information from state-specific resources like Arizona Master Gardener Manual,[6] gardeners are able to make more informed decisions about optimal growing conditions.", + "Moreover, plants respond well-t their environment; as mentioned by Abram, \"Growing Plants from Seed\"[14] which further highlights various factors that should be considered when transplanting a plant.", + ], + }, + ], + }, + }) + .to_string(); let run_result = tool .run( json!({ - "message": json!({ - "relevantSentencesFromText": [ - { - "citation_id": 5, - "document_reference": "[8] http://www.youtube.com/watch?v=eaSIq9c14YE", - "relevantSentenceFromDocument": - "This video describes the role of light in plant growth. A comparison of light detection by human eyes and light absorption by plants begins a little bit past the halfway point.", - }, - { - "citation_id": 0, - "document_reference": - "[6] Arizona Master Gardener Manual, by the University of Arizona College of Agriculture’s Cooperative Extension.", - "relevantSentenceFromDocument": - "This online book is a good example of a state-specific resource for learning about what plants need to thrive.", - }, - { - "citation_id": 0, - "document_reference": - "[6] Arizona Master Gardener Manual, by the University of Arizona College of Agriculture’s Cooperative Extension.", - "relevantSentenceFromDocument": - "This online book is a good example of a state-specific resource for learning about what plants need to thrive.", - }, - { - "citation_id": 11, - "document_reference": "[7]", - "relevantSentenceFromDocument": "", - }, - ], - "answer": { - "brief_introduction": { - "sentences": [ - "Transplanting a houseplant can be a delicate process that requires careful consideration of the plant’s needs and the conditions provided.", - "To ensure a successful transplant, it is essential to prepare the new pot and the soil, as well as the plant itself, in advance.", - "As explained by [0] on the Arizona Master Gardener Manual website,[6] this preparation can help reduce stress on the plant during the transplant process.", - ], - }, - "extensive_body": [ - { - "sentences": [ - "Firstly, as [1] describes, plants need light to grow and thrive. But different colors of light have varying effects on their development. For example, scientists on UCSB ScienceLine state that \"red light is often used to boost fruit production in greenhouses, while blue light can be used to increase plant growth\" [3].", - "When transplanting a houseplant, it is essential to choose a location with the right amount of light. As [1] explains, \"a comparison of light detection by human eyes and light absorption by plants begins a little bit past the halfway point.\" This means that even if a plant appears healthy in its current environment, it may require more or less light once moved to a new pot.", - "In addition to ensuring the right amount of light, it is crucial to prepare the soil properly. According to [10] on Arizona Master Gardener Manual website,[6]", - "Furthermore, plants have unique needs and preferences for optimal growth. As [1] notes that \"Plants are able to sense changes in their environment using abilities similar to human sight, touch, smell, taste, and hearing.\" This means that even small changes can affect the plant’s overall well-being.", - "To minimize transplant shock, gardeners should also consider the time of year when making a decision to move or transplant any plants. According to [4], it is best to do this during the spring season because this allows most species of deciduous trees and many other woody ornamental woody shrubs including fruit trees to start regrowth without major changes in weather as they usually require.", - "In terms of optimal growth conditions, different types of plants have varying requirements when it comes to light. [2] states that \"by using specialized colored filters over light lamps can produce higher plant weights\" which demonstrates the fact various colors used for plants growth at high concentration affect its height length and plant biomass. Various experiments conducted, by some research studies demonstrated 1-2-fold increase of both biomass growth rate as well plant quality in comparison with an equivalent plant grown without such lighting filters.", - ], - }, - ], - "conclusion": [ - { - "sentences": [ - "In conclusion, transplanting a houseplant requires careful consideration of its needs and the new environment. With this information from state-specific resources like Arizona Master Gardener Manual,[6] gardeners are able to make more informed decisions about optimal growing conditions.", - "Moreover, plants respond well-t their environment; as mentioned by Abram, \"Growing Plants from Seed\"[14] which further highlights various factors that should be considered when transplanting a plant.", - ], - }, - ], - }, - }).to_string(), - "template": "# Introduction{%- for sentence in answer.brief_introduction.sentences %}{{ sentence }}{%- endfor %}\\# Body{%- for section in answer.extensive_body %}## Section {{ loop.index }}{%- for sentence in section.sentences %}{{ sentence }}{%- endfor %}{%- endfor %}\\# Conclusion{%- for section in answer.conclusion %}{{ section.sentences[0] }}{%- endfor %}\\# Citations{%- for citation in relevantSentencesFromText %}[{{ citation.citation_id }}]: {{ citation.relevantSentenceFromDocument }}{%- endfor %}"}), + "message": message, + "template": "# Introduction{%- for sentence in answer.brief_introduction.sentences %}{{ sentence }}{%- endfor %}\\# Body{%- for section in answer.extensive_body %}## Section {{ loop.index }}{%- for sentence in section.sentences %}{{ sentence }}{%- endfor %}{%- endfor %}\\# Conclusion{%- for section in answer.conclusion %}{{ section.sentences[0] }}{%- endfor %}\\# Citations{%- for citation in relevantSentencesFromText %}[{{ citation.citation_id }}]: {{ citation.relevantSentenceFromDocument }}{%- endfor %}"}), None, ) .await;