diff --git a/.gitignore b/.gitignore index 93c2f4cc..774c7d2f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build/ chain mydata.yaml .idea/ +.DS_Store diff --git a/Cargo.lock b/Cargo.lock index 15098b41..28a01451 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,9 +55,9 @@ checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" [[package]] name = "async-openai" -version = "0.10.3" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d5e93aca1b2f0ca772c76cadd43e965809df87ef98e25e47244c7f006c85d2" +checksum = "cca734c68b36e26f04a9ca3401263046bb728e1c03c3264d3cd4d21c04b53f4c" dependencies = [ "backoff", "base64", @@ -94,7 +94,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -105,7 +105,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -166,7 +166,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1" dependencies = [ "futures-core", - "getrandom 0.2.9", + "getrandom 0.2.10", "instant", "pin-project-lite", "rand 0.8.5", @@ -194,7 +194,7 @@ version = "0.66.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" dependencies = [ - "bitflags 2.3.2", + "bitflags 2.3.3", "cexpr", "clang-sys", "lazy_static", @@ -207,7 +207,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.18", + "syn 2.0.22", "which", ] @@ -234,9 +234,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.2" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dbe3c979c178231552ecba20214a8272df4e09f232a87aef4320cf06539aded" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" [[package]] name = "block-buffer" @@ -371,9 +371,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" +checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" dependencies = [ "libc", ] @@ -401,9 +401,9 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.14" +version = "0.9.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" dependencies = [ "autocfg", "cfg-if", @@ -414,9 +414,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.15" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" dependencies = [ "cfg-if", ] @@ -580,6 +580,12 @@ dependencies = [ "termcolor", ] +[[package]] +name = "equivalent" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" + [[package]] name = "errno" version = "0.3.1" @@ -732,7 +738,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -794,9 +800,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", "libc", @@ -854,9 +860,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.19" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d357c7ae988e7d2182f7d7871d0b963962420b0678b0997ce7de72001aeab782" +checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" dependencies = [ "bytes", "fnv", @@ -864,7 +870,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap", + "indexmap 1.9.3", "slab", "tokio", "tokio-util", @@ -873,10 +879,11 @@ dependencies = [ [[package]] name = "half" -version = "2.2.1" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b4af3693f1b705df946e9fe5631932443781d0aabb423b62fcd4d73f6d2fd0" +checksum = "bc52e53916c08643f1b56ec082790d1e86a32e58dc5268f897f313fbae7b4872" dependencies = [ + "cfg-if", "crunchy", ] @@ -905,6 +912,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" + [[package]] name = "heck" version = "0.4.1" @@ -997,9 +1010,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.26" +version = "0.14.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4" +checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" dependencies = [ "bytes", "futures-channel", @@ -1059,9 +1072,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1123,6 +1136,16 @@ dependencies = [ "hashbrown 0.12.3", ] +[[package]] +name = "indexmap" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +dependencies = [ + "equivalent", + "hashbrown 0.14.0", +] + [[package]] name = "instant" version = "0.1.12" @@ -1145,9 +1168,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.7.2" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" +checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" [[package]] name = "is-terminal" @@ -1187,9 +1210,9 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "js-sys" -version = "0.3.63" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" dependencies = [ "wasm-bindgen", ] @@ -1208,9 +1231,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.145" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc86cde3ff845662b8f4ef6cb50ea0e20c524eb3d29ae048287e06a1b3fa6a81" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libloading" @@ -1290,6 +1313,7 @@ dependencies = [ "paste", "reqwest", "serde", + "serde_derive", "serde_json", "serde_yaml", "strum", @@ -1354,7 +1378,7 @@ dependencies = [ name = "llm-chain-macros" version = "0.12.3" dependencies = [ - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -1368,6 +1392,7 @@ dependencies = [ "llm-chain", "qdrant-client", "serde", + "serde_json", "serde_yaml", "strum", "strum_macros", @@ -1451,15 +1476,15 @@ dependencies = [ [[package]] name = "log" -version = "0.4.18" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" +checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "markdown" -version = "1.0.0-alpha.9" +version = "1.0.0-alpha.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c45dae11dd8af468c41201ace44dbbb3b1148215ac593cb8f0967b8d8d4b66c" +checksum = "b1bd98c3b68451b0390a289c58c856adb4e2b50cc40507ce2a105d5b00eafc80" dependencies = [ "unicode-id", ] @@ -1487,9 +1512,9 @@ dependencies = [ [[package]] name = "memoffset" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" dependencies = [ "autocfg", ] @@ -1615,9 +1640,9 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "openssl" -version = "0.10.54" +version = "0.10.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69b3f656a17a6cbc115b5c7a40c616947d213ba182135b014d6051b73ab6f019" +checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d" dependencies = [ "bitflags 1.3.2", "cfg-if", @@ -1636,7 +1661,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -1647,9 +1672,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.88" +version = "0.9.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2ce0f250f34a308dcfdbb351f511359857d4ed2134ba715a4eadd46e1ffd617" +checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6" dependencies = [ "cc", "libc", @@ -1677,7 +1702,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.0", + "windows-targets", ] [[package]] @@ -1715,9 +1740,9 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pest" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68e84bfb01f0507134eac1e9b410a12ba379d064eab48c50ba4ce329a527b70" +checksum = "f73935e4d55e2abf7f130186537b19e7a4abc886a0252380b59248af473a3fc9" dependencies = [ "thiserror", "ucd-trie", @@ -1725,9 +1750,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b79d4c71c865a25a4322296122e3924d30bc8ee0834c8bfc8b95f7f054afbfb" +checksum = "aef623c9bbfa0eedf5a0efba11a5ee83209c326653ca31ff019bec3a95bfff2b" dependencies = [ "pest", "pest_generator", @@ -1735,22 +1760,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c435bf1076437b851ebc8edc3a18442796b30f1728ffea6262d59bbe28b077e" +checksum = "b3e8cba4ec22bada7fc55ffe51e2deb6a0e0db2d0b7ab0b103acc80d2510c190" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] name = "pest_meta" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "745a452f8eb71e39ffd8ee32b3c5f51d03845f99786fa9b68db6ff509c505411" +checksum = "a01f71cb40bd8bb94232df14b946909e14660e33fc05db3e50ae2a82d7ea0ca0" dependencies = [ "once_cell", "pest", @@ -1813,7 +1838,7 @@ checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -1872,19 +1897,19 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b69d39aab54d069e7f2fe8cb970493e7834601ca2d8c65fd7bbd183578080d1" +checksum = "9825a04601d60621feed79c4e6b56d65db77cdca55cef43b46b0de1096d1c282" dependencies = [ "proc-macro2", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] name = "proc-macro2" -version = "1.0.59" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" dependencies = [ "unicode-ident", ] @@ -1929,9 +1954,9 @@ checksum = "8e86d370532557ae7573551a1ec8235a0f8d6cb276c7c9e6aa490b511c447485" [[package]] name = "qdrant-client" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dc402a97fd879eff8e26d6ecd46e2fa896aa3d2c0a299a0d7361a12a892458d" +checksum = "94dc0c49ac6893463bd32f5adfe9e503c3d83fac7ee58534e1c0e1c76842dac8" dependencies = [ "anyhow", "futures-util", @@ -2012,7 +2037,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.9", + "getrandom 0.2.10", ] [[package]] @@ -2191,9 +2216,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.37.19" +version = "0.37.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" +checksum = "b96e891d04aa506a6d1f318d2771bcb1c7dfda84e126660ace067c9b474bb2c0" dependencies = [ "bitflags 1.3.2", "errno", @@ -2205,9 +2230,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.1" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c911ba11bc8433e811ce56fde130ccf32f5127cab0e0194e9c68c5a5b671791e" +checksum = "e32ca28af694bc1bbf399c33a516dbdf1c90090b8ab23c2bc24f834aa2247f5f" dependencies = [ "log", "ring", @@ -2217,9 +2242,9 @@ dependencies = [ [[package]] name = "rustls-native-certs" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" dependencies = [ "openssl-probe", "rustls-pemfile", @@ -2341,7 +2366,7 @@ checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -2369,11 +2394,11 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.21" +version = "0.9.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9d684e3ec7de3bf5466b32bd75303ac16f0736426e5a4e0d6e489559ce1249c" +checksum = "452e67b9c20c37fa79df53201dc03839651086ed9bbe92b3ca585ca9fdaa7d85" dependencies = [ - "indexmap", + "indexmap 2.0.0", "itoa", "ryu", "serde", @@ -2382,9 +2407,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" dependencies = [ "cfg-if", "cpufeatures", @@ -2490,9 +2515,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.18" +version = "2.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" dependencies = [ "proc-macro2", "quote", @@ -2507,15 +2532,16 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] name = "tempfile" -version = "3.5.0" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" +checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" dependencies = [ + "autocfg", "cfg-if", "fastrand", "redox_syscall", "rustix", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -2573,7 +2599,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -2587,9 +2613,8 @@ dependencies = [ [[package]] name = "tiktoken-rs" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ba161c549e2c0686f35f5d920e63fad5cafba2c28ad2caceaf07e5d9fa6e8c4" +version = "0.4.5" +source = "git+https://github.com/DaviRain-Su/tiktoken-rs.git?branch=main#1f447aa690cdb2664537395c77db3eb3e178c0c0" dependencies = [ "anyhow", "async-openai", @@ -2650,7 +2675,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -2665,9 +2690,9 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.24.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0d409377ff5b1e3ca6437aa86c1eb7d40c134bfec254e44c830defa92669db5" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ "rustls", "tokio", @@ -2738,7 +2763,7 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", - "indexmap", + "indexmap 1.9.3", "pin-project", "pin-project-lite", "rand 0.8.5", @@ -2776,13 +2801,13 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -2941,11 +2966,11 @@ dependencies = [ [[package]] name = "uuid" -version = "1.3.3" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "345444e32442451b267fc254ae85a209c64be56d2890e601a0c37ff0c3c5ecd2" +checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be" dependencies = [ - "getrandom 0.2.9", + "getrandom 0.2.10", ] [[package]] @@ -2972,11 +2997,10 @@ dependencies = [ [[package]] name = "want" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "log", "try-lock", ] @@ -2994,9 +3018,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3004,24 +3028,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.36" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d1985d03709c53167ce907ff394f5316aa22cb4e12761295c5dc57dacb6297e" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" dependencies = [ "cfg-if", "js-sys", @@ -3031,9 +3055,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3041,22 +3065,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "wasm-streams" @@ -3073,9 +3097,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.63" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bdd9ef4e984da1187bf8110c5cf5b845fbc87a23602cdf912386a76fcd3a7c2" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" dependencies = [ "js-sys", "wasm-bindgen", @@ -3148,7 +3172,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets 0.48.0", + "windows-targets", ] [[package]] @@ -3166,37 +3190,13 @@ dependencies = [ "windows_x86_64_msvc 0.42.2", ] -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets 0.48.0", -] - -[[package]] -name = "windows-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows-targets", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 9b3a1cc1..729e6d63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,10 @@ [workspace] members = ["crates/*"] +resolver = "2" [workspace.metadata.release] shared-version = true [patch.crates-io] hnsw_rs = { git = "https://github.com/ruqqq/hnswlib-rs" } - +tiktoken-rs = { git = "https://github.com/DaviRain-Su/tiktoken-rs.git", branch = "main" } diff --git a/crates/llm-chain-macros/src/lib.rs b/crates/llm-chain-macros/src/lib.rs index 71cf21c7..1978275f 100644 --- a/crates/llm-chain-macros/src/lib.rs +++ b/crates/llm-chain-macros/src/lib.rs @@ -37,7 +37,7 @@ pub fn derive_describe(input: TokenStream) -> TokenStream { attr.path().segments.len() == 1 && attr.path().segments[0].ident == "purpose" }) - .nth(0) + .next() .expect("All fields on the string must have a purpose annotation") .parse_args::() .expect("Purpose must be a single string literal"), diff --git a/crates/llm-chain-openai/Cargo.toml b/crates/llm-chain-openai/Cargo.toml index 7a1bd54a..985669eb 100644 --- a/crates/llm-chain-openai/Cargo.toml +++ b/crates/llm-chain-openai/Cargo.toml @@ -14,10 +14,11 @@ repository = "https://github.com/sobelio/llm-chain/" [dependencies] futures = "0.3.28" -async-openai = "0.10.3" +async-openai = "0.12.0" async-trait = "0.1.68" llm-chain = { path = "../llm-chain", version = "0.12.3", default-features = false } serde = { version = "1.0.164" } +serde_json = "1" strum = "0.25" strum_macros = "0.24" thiserror = "1.0.40" @@ -30,4 +31,3 @@ qdrant-client = "1.2.0" llm-chain = { path = "../llm-chain" } anyhow = "1.0.70" serde_yaml = "0.9.21" - diff --git a/crates/llm-chain-openai/src/chatgpt/executor.rs b/crates/llm-chain-openai/src/chatgpt/executor.rs index ea7a697c..d03829da 100644 --- a/crates/llm-chain-openai/src/chatgpt/executor.rs +++ b/crates/llm-chain-openai/src/chatgpt/executor.rs @@ -8,7 +8,9 @@ use llm_chain::tokens::TokenCollection; use super::prompt::create_chat_completion_request; use super::prompt::format_chat_messages; -use async_openai::{error::OpenAIError, types::ChatCompletionRequestMessage}; +use async_openai::config::OpenAIConfig; +use async_openai::error::OpenAIError; +use async_openai::types::ChatCompletionRequestMessage; use llm_chain::prompt::Prompt; use llm_chain::tokens::PromptTokensError; @@ -24,17 +26,17 @@ use tiktoken_rs::get_chat_completion_max_tokens; use std::sync::Arc; /// The `Executor` struct for the ChatGPT model. This executor uses the `async_openai` crate to communicate with the OpenAI API. -#[derive(Clone, Default)] +#[derive(Clone)] pub struct Executor { /// The client used to communicate with the OpenAI API. - client: Arc, + client: Arc>, /// The per-invocation options for this executor. options: Options, } impl Executor { /// Creates a new `Executor` with the given client. - pub fn for_client(client: async_openai::Client, options: Options) -> Self { + pub fn for_client(client: async_openai::Client, options: Options) -> Self { use llm_chain::traits::Executor as _; let mut exec = Self::new_with_options(options).unwrap(); exec.client = Arc::new(client); @@ -70,17 +72,18 @@ impl traits::Executor for Executor { /// /// if the `OPENAI_ORG_ID` environment variable is present, it will be used as the org_ig for the OpenAI client. fn new_with_options(options: Options) -> Result { - let mut client = async_openai::Client::new(); + let mut openai_config = OpenAIConfig::default(); let opts = OptionsCascade::new().with_options(&options); if let Some(Opt::ApiKey(api_key)) = opts.get(llm_chain::options::OptDiscriminants::ApiKey) { - client = client.with_api_key(api_key) + openai_config = openai_config.with_api_key(api_key); } if let Ok(org_id) = std::env::var("OPENAI_ORG_ID") { - client = client.with_org_id(org_id); + openai_config = openai_config.with_org_id(org_id); } - let client = Arc::new(client); + + let client = Arc::new(async_openai::Client::with_config(openai_config)); Ok(Self { client, options }) } @@ -146,6 +149,7 @@ fn as_tiktoken_message( role: message.role.to_string(), content: message.content.clone(), name: message.name.clone(), + function_call: message.function_call.clone().map(|x| (&x).into()), } } diff --git a/crates/llm-chain-openai/src/chatgpt/prompt.rs b/crates/llm-chain-openai/src/chatgpt/prompt.rs index 04926322..5d30db5a 100644 --- a/crates/llm-chain-openai/src/chatgpt/prompt.rs +++ b/crates/llm-chain-openai/src/chatgpt/prompt.rs @@ -11,11 +11,14 @@ use llm_chain::{ use async_openai::types::{ChatCompletionResponseStream, CreateChatCompletionResponse}; +pub mod function_call; + fn convert_role(role: &prompt::ChatRole) -> Role { match role { prompt::ChatRole::User => Role::User, prompt::ChatRole::Assistant => Role::Assistant, prompt::ChatRole::System => Role::System, + prompt::ChatRole::Function => Role::Function, prompt::ChatRole::Other(_s) => Role::User, // other roles are not supported by OpenAI } } @@ -25,6 +28,7 @@ fn convert_openai_role(role: &Role) -> prompt::ChatRole { Role::User => prompt::ChatRole::User, Role::Assistant => prompt::ChatRole::Assistant, Role::System => prompt::ChatRole::System, + Role::Function => prompt::ChatRole::Function, } } @@ -35,8 +39,9 @@ fn format_chat_message( let content = message.body().to_string(); Ok(ChatCompletionRequestMessage { role, - content, + content: Some(content), name: None, + function_call: None, }) } @@ -55,6 +60,8 @@ pub fn create_chat_completion_request( Ok(CreateChatCompletionRequest { model, messages, + functions: None, + function_call: None, temperature: None, top_p: None, n: Some(1), @@ -73,7 +80,7 @@ pub fn completion_to_output(resp: CreateChatCompletionResponse) -> Output { let mut col = ChatMessageCollection::new(); col.add_message(ChatMessage::new( convert_openai_role(&msg.role), - msg.content, + msg.content.unwrap_or_default(), )); Output::new_immediate(col.into()) } diff --git a/crates/llm-chain-openai/src/chatgpt/prompt/function_call.rs b/crates/llm-chain-openai/src/chatgpt/prompt/function_call.rs new file mode 100644 index 00000000..538aafe6 --- /dev/null +++ b/crates/llm-chain-openai/src/chatgpt/prompt/function_call.rs @@ -0,0 +1,153 @@ +use super::*; +use serde::{Deserialize, Serialize}; + +pub type PromptWithFunctionCalls = prompt::ChatMessageCollection; + +#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] +pub struct ChatCompletionFunctions { + /// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. + pub name: String, + /// The description of what the function does. + #[serde(skip_serializing_if = "Option::is_none")] + pub description: Option, + /// The parameters the functions accepts, described as a JSON Schema object. + /// See the [guide](https://platform.openai.com/docs/guides/gpt/function-calling) for examples, + /// and the [JSON Schema](https://json-schema.org/understanding-json-schema/) reference for documentation about the format. + #[serde(skip_serializing_if = "Option::is_none")] + pub parameters: Option, +} + +impl From for async_openai::types::ChatCompletionFunctions { + fn from(functions: ChatCompletionFunctions) -> Self { + Self { + name: functions.name, + description: functions.description, + parameters: functions.parameters, + } + } +} + +impl From for ChatCompletionFunctions { + fn from(functions: async_openai::types::ChatCompletionFunctions) -> Self { + Self { + name: functions.name, + description: functions.description, + parameters: functions.parameters, + } + } +} + +/// The name and arguments of a function that should be called, as generated by the model. +#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] +pub struct FunctionCall { + /// The name of the function to call. + pub name: String, + /// The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. + pub arguments: String, +} + +impl From for async_openai::types::FunctionCall { + fn from(call: FunctionCall) -> Self { + Self { + name: call.name, + arguments: call.arguments, + } + } +} + +impl From for FunctionCall { + fn from(call: async_openai::types::FunctionCall) -> Self { + Self { + name: call.name, + arguments: call.arguments, + } + } +} + +#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq)] +pub struct FunctionCallBody { + /// The contents of the message. + /// `content` is required for all messages except assistant messages with function calls. + #[serde(skip_serializing_if = "Option::is_none")] + pub content: Option, + /// The name of the author of this message. `name` is required if role is function, + /// and it should be the name of the function whose response is in the `content`. + /// May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters. + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + /// The name and arguments of a function that should be called, as generated by the model. + #[serde(skip_serializing_if = "Option::is_none")] + pub function_call: Option, +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[serde(untagged)] +pub enum ChatCompletionFunctionCall { + String(String), + Object(serde_json::Value), +} + +impl From for async_openai::types::ChatCompletionFunctionCall { + fn from(call: ChatCompletionFunctionCall) -> Self { + match call { + ChatCompletionFunctionCall::String(s) => Self::String(s), + ChatCompletionFunctionCall::Object(o) => Self::Object(o), + } + } +} + +impl From for ChatCompletionFunctionCall { + fn from(call: async_openai::types::ChatCompletionFunctionCall) -> Self { + match call { + async_openai::types::ChatCompletionFunctionCall::String(s) => Self::String(s), + async_openai::types::ChatCompletionFunctionCall::Object(o) => Self::Object(o), + } + } +} + +fn format_chat_message( + message: &prompt::ChatMessage, +) -> Result { + let role = convert_role(message.role()); + let content = message.body().content.clone(); + let name = message.body().name.clone(); + let function_call = message.body().function_call.clone().map(|v| v.into()); + Ok(ChatCompletionRequestMessage { + role, + content, + name, + function_call, + }) +} + +pub fn format_chat_messages( + messages: PromptWithFunctionCalls, +) -> Result, StringTemplateError> { + messages.iter().map(format_chat_message).collect() +} + +pub fn create_chat_completion_with_function_call_request( + model: String, + prompt: &PromptWithFunctionCalls, + functions: Vec, + function_call: ChatCompletionFunctionCall, + is_streaming: bool, +) -> Result { + let messages = format_chat_messages(prompt.clone())?; + Ok(CreateChatCompletionRequest { + model, + messages, + functions: Some(functions.into_iter().map(Into::into).collect()), + function_call: Some(function_call.into()), + temperature: None, + top_p: None, + n: Some(1), + stream: Some(is_streaming), + stop: None, + max_tokens: None, // We should consider something here + presence_penalty: None, + frequency_penalty: None, + logit_bias: None, + user: None, + }) +} diff --git a/crates/llm-chain-openai/src/embeddings.rs b/crates/llm-chain-openai/src/embeddings.rs index 774eda0f..08cfe6e6 100644 --- a/crates/llm-chain-openai/src/embeddings.rs +++ b/crates/llm-chain-openai/src/embeddings.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use async_openai::{ + config::OpenAIConfig, error::OpenAIError, types::{CreateEmbeddingRequest, EmbeddingInput}, }; @@ -9,7 +10,7 @@ use llm_chain::traits::{self, EmbeddingsError}; use thiserror::Error; pub struct Embeddings { - client: Arc, + client: Arc>, model: String, } @@ -60,14 +61,14 @@ impl traits::Embeddings for Embeddings { impl Default for Embeddings { fn default() -> Self { Self { - client: async_openai::Client::default().into(), + client: async_openai::Client::with_config(OpenAIConfig::default()).into(), model: "text-embedding-ada-002".to_string(), } } } impl Embeddings { - pub fn for_client(client: async_openai::Client, model: &str) -> Self { + pub fn for_client(client: async_openai::Client, model: &str) -> Self { Self { client: client.into(), model: model.to_string(), diff --git a/crates/llm-chain/Cargo.toml b/crates/llm-chain/Cargo.toml index 134aafae..8090b79b 100644 --- a/crates/llm-chain/Cargo.toml +++ b/crates/llm-chain/Cargo.toml @@ -16,7 +16,8 @@ repository = "https://github.com/sobelio/llm-chain/" anyhow = "1.0.71" async-trait = "0.1.68" futures = "0.3.28" -serde = { version = "1.0.164", features = ["derive"] } +serde = { version = "1" } +serde_derive = "1" serde_yaml = { version = "0.9.21" } thiserror = "1.0.40" tokio = { version = "1.28.2", features = ["fs", "io-util", "rt", "macros"] } diff --git a/crates/llm-chain/src/document_stores/in_memory_document_store.rs b/crates/llm-chain/src/document_stores/in_memory_document_store.rs index e643cb57..d5e0f3b3 100644 --- a/crates/llm-chain/src/document_stores/in_memory_document_store.rs +++ b/crates/llm-chain/src/document_stores/in_memory_document_store.rs @@ -113,7 +113,7 @@ where if self.map.contains_key(key) { return Err(InMemoryDocumentStoreError::KeyConflict(key.to_string())); } else { - self.map.insert(key.clone(), value.into()); + self.map.insert(*key, value.into()); } } diff --git a/crates/llm-chain/src/prompt/chat.rs b/crates/llm-chain/src/prompt/chat.rs index bf7e2f4b..455140a3 100644 --- a/crates/llm-chain/src/prompt/chat.rs +++ b/crates/llm-chain/src/prompt/chat.rs @@ -19,6 +19,7 @@ pub enum ChatRole { User, Assistant, System, + Function, Other(String), } @@ -41,6 +42,7 @@ impl fmt::Display for ChatRole { ChatRole::User => write!(f, "User"), ChatRole::Assistant => write!(f, "Assistant"), ChatRole::System => write!(f, "System"), + ChatRole::Function => write!(f, "Function"), ChatRole::Other(s) => write!(f, "{}", s), } } diff --git a/crates/llm-chain/src/traits.rs b/crates/llm-chain/src/traits.rs index 65cd9576..79e9b099 100644 --- a/crates/llm-chain/src/traits.rs +++ b/crates/llm-chain/src/traits.rs @@ -14,7 +14,6 @@ use std::{error::Error, fmt::Debug}; use crate::{ options::Options, output::Output, - prompt::Prompt, schema::{Document, EmptyMetadata}, tokens::{PromptTokensError, TokenCount, Tokenizer, TokenizerError}, }; @@ -49,6 +48,7 @@ pub enum ExecutorError { /// The `Executor` trait represents an executor that performs a single step in a chain. It takes a /// step, executes it, and returns the output. pub trait Executor: Sized { + type Prompt; type StepTokenizer<'a>: Tokenizer where Self: 'a; @@ -62,7 +62,11 @@ pub trait Executor: Sized { Self::new_with_options(Options::empty().clone()) } - async fn execute(&self, options: &Options, prompt: &Prompt) -> Result; + async fn execute( + &self, + options: &Options, + prompt: &Self::Prompt, + ) -> Result; /// Calculates the number of tokens used by the step given a set of parameters. /// @@ -80,7 +84,7 @@ pub trait Executor: Sized { fn tokens_used( &self, options: &Options, - prompt: &Prompt, + prompt: &Self::Prompt, ) -> Result; /// Returns the maximum number of input tokens allowed by the model used. @@ -102,7 +106,7 @@ pub trait Executor: Sized { /// # Returns /// /// A `Option` containing a String if prefix exists, or none if there is no prefix - fn answer_prefix(&self, prompt: &Prompt) -> Option; + fn answer_prefix(&self, prompt: &Self::Prompt) -> Option; /// Creates a tokenizer, depending on the model used by `step`. ///