From 438ad78d8c1078fa2e5ed97591f4453007662a82 Mon Sep 17 00:00:00 2001 From: erhant Date: Wed, 9 Oct 2024 14:02:22 +0300 Subject: [PATCH] better package sharing, add configurability to workflows configs --- Cargo.lock | 233 +++++++++--------------------- Cargo.toml | 8 +- Makefile | 2 +- compute/Cargo.toml | 28 ++-- compute/src/config.rs | 2 +- compute/src/main.rs | 2 +- workflows/Cargo.toml | 12 +- workflows/src/config.rs | 16 +- workflows/src/providers/ollama.rs | 18 +++ workflows/src/providers/openai.rs | 6 + 10 files changed, 141 insertions(+), 186 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aacbb86..32e6f1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ "gimli", ] @@ -499,7 +499,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" dependencies = [ "memchr", - "regex-automata 0.4.8", + "regex-automata", "serde", ] @@ -532,9 +532,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.24" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812acba72f0a070b003d3697490d2b55b837230ae7c6c6497f05cc2ddbb8d938" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "shlex", ] @@ -894,18 +894,18 @@ dependencies = [ [[package]] name = "derive_builder" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd33f37ee6a119146a1781d3356a7c26028f83d779b2e04ecd45fdc75c76877b" +checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947" dependencies = [ "derive_builder_macro", ] [[package]] name = "derive_builder_core" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7431fa049613920234f22c47fdc33e6cf3ee83067091ea4277a3f8c4587aae38" +checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8" dependencies = [ "darling", "proc-macro2", @@ -915,9 +915,9 @@ dependencies = [ [[package]] name = "derive_builder_macro" -version = "0.20.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4abae7035bf79b9877b779505d8cf3749285b80c43941eda66604841889451dc" +checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" dependencies = [ "derive_builder_core", "syn 2.0.79", @@ -980,7 +980,7 @@ dependencies = [ [[package]] name = "dkn-compute" -version = "0.2.12" +version = "0.2.13" dependencies = [ "async-trait", "base64 0.22.1", @@ -1005,8 +1005,6 @@ dependencies = [ "sha3", "tokio 1.40.0", "tokio-util 0.7.12", - "tracing", - "tracing-subscriber", "url", "urlencoding", "uuid", @@ -1014,7 +1012,7 @@ dependencies = [ [[package]] name = "dkn-p2p" -version = "0.2.12" +version = "0.2.13" dependencies = [ "env_logger 0.11.5", "eyre", @@ -1026,7 +1024,7 @@ dependencies = [ [[package]] name = "dkn-workflows" -version = "0.2.12" +version = "0.2.13" dependencies = [ "async-trait", "dotenvy", @@ -1285,6 +1283,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -1337,9 +1341,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -1362,9 +1366,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -1372,15 +1376,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -1390,9 +1394,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" @@ -1406,9 +1410,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -1428,15 +1432,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-ticker" @@ -1457,9 +1461,9 @@ checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -1537,9 +1541,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.31.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "glob" @@ -1616,16 +1620,17 @@ name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", - "allocator-api2", -] [[package]] name = "hashbrown" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] [[package]] name = "heck" @@ -2273,9 +2278,9 @@ dependencies = [ [[package]] name = "langchain-rust" -version = "4.4.3" +version = "4.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee1ca7e38544a214bc4363e9ecf0f8a0cb7f785b316827070e43ba151db27eb2" +checksum = "2e85dc2101f68748bf3618320e5e980cf5da00e7d7dd9ade07c9d16f34f85a50" dependencies = [ "async-openai", "async-recursion", @@ -2890,11 +2895,11 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "lru" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown 0.14.5", + "hashbrown 0.15.0", ] [[package]] @@ -2990,15 +2995,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata 0.1.10", -] - [[package]] name = "matches" version = "0.1.10" @@ -3295,16 +3291,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi 0.3.9", -] - [[package]] name = "num-bigint" version = "0.4.6" @@ -3351,9 +3337,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.4" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "memchr", ] @@ -3414,12 +3400,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.1" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" -dependencies = [ - "portable-atomic", -] +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "opaque-debug" @@ -3496,12 +3479,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - [[package]] name = "parking" version = "2.2.1" @@ -3699,18 +3676,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" dependencies = [ "proc-macro2", "quote", @@ -3795,12 +3772,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2110609fb863cdb367d4e69d6c43c81ba6a8c7d18e80082fe9f3ef16b23afeed" -[[package]] -name = "portable-atomic" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" - [[package]] name = "powerfmt" version = "0.2.0" @@ -3830,9 +3801,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -4080,17 +4051,8 @@ checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.8", - "regex-syntax 0.8.5", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax 0.6.29", + "regex-automata", + "regex-syntax", ] [[package]] @@ -4101,15 +4063,9 @@ checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.5", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - [[package]] name = "regex-syntax" version = "0.8.5" @@ -4365,9 +4321,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.13" +version = "0.23.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", "ring 0.17.8", @@ -4459,9 +4415,9 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schannel" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" dependencies = [ "windows-sys 0.59.0", ] @@ -4719,15 +4675,6 @@ dependencies = [ "keccak", ] -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - [[package]] name = "shlex" version = "1.3.0" @@ -5105,16 +5052,6 @@ dependencies = [ "syn 2.0.79", ] -[[package]] -name = "thread_local" -version = "1.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", -] - [[package]] name = "tiktoken-rs" version = "0.5.9" @@ -5340,7 +5277,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", - "valuable", ] [[package]] @@ -5353,35 +5289,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "matchers", - "nu-ansi-term", - "once_cell", - "regex", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", -] - [[package]] name = "try-lock" version = "0.2.5" @@ -5526,12 +5433,6 @@ dependencies = [ "getrandom 0.2.15", ] -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index d697194..a94f1f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ default-members = ["compute"] [workspace.package] edition = "2021" -version = "0.2.12" +version = "0.2.13" license = "Apache-2.0" readme = "README.md" @@ -21,7 +21,9 @@ debug = true [workspace.dependencies] # async stuff -tokio-util = { version = "0.7.10", features = ["rt"] } +tokio-util = { version = "0.7.10", features = [ + "rt", +] } # tokio-util provides CancellationToken tokio = { version = "1", features = ["macros", "rt-multi-thread", "signal"] } async-trait = "0.1.81" @@ -32,7 +34,7 @@ serde_json = "1.0" # http client reqwest = "0.12.5" -# env reading +# utilities dotenvy = "0.15.7" # randomization diff --git a/Makefile b/Makefile index 328c2e4..b28be2d 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ trace: .PHONY: build # | Build build: - cargo build + cargo build --workspace .PHONY: profile-cpu # | Profile CPU usage with flamegraph profile-cpu: diff --git a/compute/Cargo.toml b/compute/Cargo.toml index c9e9a7e..588a5f9 100644 --- a/compute/Cargo.toml +++ b/compute/Cargo.toml @@ -7,31 +7,35 @@ readme = "README.md" authors = ["Erhan Tezcan "] [dependencies] -tokio-util = { version = "0.7.10", features = ["rt"] } -tokio = { version = "1", features = ["macros", "rt-multi-thread", "signal"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -async-trait = "0.1.81" -reqwest = "0.12.5" +# async stuff +tokio-util.workspace = true +tokio.workspace = true +async-trait.workspace = true + +# serialize & deserialize +serde.workspace = true +serde_json.workspace = true + +# http & networking +reqwest.workspace = true +port_check = "0.2.1" +url = "2.5.0" +urlencoding = "2.1.3" # utilities dotenvy.workspace = true base64 = "0.22.0" hex = "0.4.3" hex-literal = "0.4.1" -url = "2.5.0" -urlencoding = "2.1.3" uuid = { version = "1.8.0", features = ["v4"] } -port_check = "0.2.1" - # logging & errors rand.workspace = true env_logger.workspace = true log.workspace = true eyre.workspace = true -tracing = { version = "0.1.40" } -tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } +# tracing = { version = "0.1.40" } +# tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } # encryption (ecies) & signatures (ecdsa) & hashing & bloom-filters ecies = { version = "0.2", default-features = false, features = ["pure"] } diff --git a/compute/src/config.rs b/compute/src/config.rs index ce8cf72..8fcfa79 100644 --- a/compute/src/config.rs +++ b/compute/src/config.rs @@ -86,7 +86,7 @@ impl DriaComputeNodeConfig { log::error!("No models were provided, make sure to restart with at least one model provided within DKN_MODELS."); panic!("No models provided."); } - log::info!("Models: {:?}", workflows.models); + log::info!("Configured models: {:?}", workflows.models); let p2p_listen_addr_str = env::var("DKN_P2P_LISTEN_ADDR") .map(|addr| addr.trim_matches('"').to_string()) diff --git a/compute/src/main.rs b/compute/src/main.rs index c00c34c..9d434c4 100644 --- a/compute/src/main.rs +++ b/compute/src/main.rs @@ -34,8 +34,8 @@ async fn main() -> Result<()> { let cancellation_token = token.clone(); tokio::spawn(async move { if let Some(timeout_str) = env::var("DKN_EXIT_TIMEOUT").ok() { - // add cancellation check let duration_secs = timeout_str.parse().unwrap_or(120); + log::warn!("Waiting for {} seconds before exiting.", duration_secs); tokio::time::sleep(tokio::time::Duration::from_secs(duration_secs)).await; cancellation_token.cancel(); } else { diff --git a/workflows/Cargo.toml b/workflows/Cargo.toml index e068f37..aa71c14 100644 --- a/workflows/Cargo.toml +++ b/workflows/Cargo.toml @@ -11,16 +11,26 @@ authors = ["Erhan Tezcan "] # ollama-rs is re-exported from ollama-workflows as well ollama-workflows = { git = "https://github.com/andthattoo/ollama-workflows" } +# async stuff tokio-util.workspace = true tokio.workspace = true +async-trait.workspace = true + +# serialize & deserialize serde.workspace = true serde_json.workspace = true -async-trait.workspace = true + +# http & networking reqwest.workspace = true + +# utilities rand.workspace = true + +# logging & errors log.workspace = true eyre.workspace = true [dev-dependencies] +# only used for tests env_logger.workspace = true dotenvy.workspace = true diff --git a/workflows/src/config.rs b/workflows/src/config.rs index d2bd29b..9bf0910 100644 --- a/workflows/src/config.rs +++ b/workflows/src/config.rs @@ -16,6 +16,7 @@ pub struct DriaWorkflowsConfig { } impl DriaWorkflowsConfig { + /// Creates a new config with the given models. pub fn new(models: Vec) -> Self { let models_and_providers = models .into_iter() @@ -28,6 +29,19 @@ impl DriaWorkflowsConfig { ollama: OllamaConfig::new(), } } + + /// Sets the Ollama configuration for the Workflows config. + pub fn with_ollama_config(mut self, ollama: OllamaConfig) -> Self { + self.ollama = ollama; + self + } + + /// Sets the OpenAI configuration for the Workflows config. + pub fn with_openai_config(mut self, openai: OpenAIConfig) -> Self { + self.openai = openai; + self + } + /// Parses Ollama-Workflows compatible models from a comma-separated values string. pub fn new_from_csv(input: &str) -> Self { let models_str = split_csv_line(input); @@ -40,7 +54,7 @@ impl DriaWorkflowsConfig { Self::new(models) } - /// Returns the models that belong to a given providers from the config. + /// Returns the models from the config that belongs to a given provider. pub fn get_models_for_provider(&self, provider: ModelProvider) -> Vec { self.models .iter() diff --git a/workflows/src/providers/ollama.rs b/workflows/src/providers/ollama.rs index d507130..57c1789 100644 --- a/workflows/src/providers/ollama.rs +++ b/workflows/src/providers/ollama.rs @@ -79,6 +79,24 @@ impl OllamaConfig { } } + /// Sets the timeout duration for checking model performance during a generation. + pub fn with_timeout(mut self, timeout: Duration) -> Self { + self.timeout = timeout; + self + } + + /// Sets the minimum tokens per second (TPS) for checking model performance during a generation. + pub fn with_min_tps(mut self, min_tps: f64) -> Self { + self.min_tps = min_tps; + self + } + + /// Sets the auto-pull flag for Ollama models. + pub fn with_auto_pull(mut self, auto_pull: bool) -> Self { + self.auto_pull = auto_pull; + self + } + /// Check if requested models exist in Ollama, and then tests them using a workflow. pub async fn check(&self, external_models: Vec) -> Result> { log::info!( diff --git a/workflows/src/providers/openai.rs b/workflows/src/providers/openai.rs index 2252e36..220b6a3 100644 --- a/workflows/src/providers/openai.rs +++ b/workflows/src/providers/openai.rs @@ -43,6 +43,12 @@ impl OpenAIConfig { } } + /// Sets the API key for OpenAI. + pub fn with_api_key(mut self, api_key: String) -> Self { + self.api_key = Some(api_key); + self + } + /// Check if requested models exist & are available in the OpenAI account. pub async fn check(&self, models: Vec) -> Result> { log::info!("Checking OpenAI requirements");