From 2776225bf36d7ce5736b85da9bceb1bbd38832c9 Mon Sep 17 00:00:00 2001 From: BohuTANG Date: Mon, 27 Mar 2023 14:03:35 +0800 Subject: [PATCH 1/5] chore(openai): change openai from async to sync --- Cargo.lock | 793 +++++++++++++----- .../61-ai-functions/01-ai-to-sql.md | 11 +- src/query/service/Cargo.toml | 2 +- .../src/table_functions/openai/gpt_to_sql.rs | 93 +- .../src/table_functions/openai/openai.rs | 71 +- .../{openai.rs => ai_to_sql.rs} | 10 - .../service/tests/it/table_functions/mod.rs | 2 +- website/blog/2023-03-20-ai2sql.md | 5 +- 8 files changed, 665 insertions(+), 322 deletions(-) rename src/query/service/tests/it/table_functions/{openai.rs => ai_to_sql.rs} (79%) diff --git a/Cargo.lock b/Cargo.lock index b3a85e8593d14..75172b8bba37d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,7 +25,7 @@ checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ "getrandom 0.2.8", "once_cell", - "version_check", + "version_check 0.9.4", ] [[package]] @@ -38,7 +38,7 @@ dependencies = [ "const-random", "getrandom 0.2.8", "once_cell", - "version_check", + "version_check 0.9.4", ] [[package]] @@ -314,6 +314,12 @@ dependencies = [ "strength_reduce", ] +[[package]] +name = "ascii" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97be891acc47ca214468e09425d02cef3af2c94d0d82081cd02061f996802f14" + [[package]] name = "assert-json-diff" version = "2.0.2" @@ -398,11 +404,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c374dda1ed3e7d8f0d9ba58715f924862c63eae6849c92d3a18e7fbde9e2794" dependencies = [ "async-lock", - "autocfg", + "autocfg 1.1.0", "concurrent-queue", "futures-lite", "libc", - "log", + "log 0.4.17", "parking", "polling", "slab", @@ -420,28 +426,6 @@ dependencies = [ "event-listener", ] -[[package]] -name = "async-openai" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc62bea0dc0376372c6cb0e450168b7805d6655b88a3dfd340036743a3d91fca" -dependencies = [ - "backoff", - "base64 0.21.0", - "derive_builder", - "futures", - "rand 0.8.5", - "reqwest", - "reqwest-eventsource", - "serde", - "serde_json", - "thiserror", - "tokio", - "tokio-stream", - "tokio-util", - "tracing", -] - [[package]] name = "async-recursion" version = "1.0.2" @@ -544,6 +528,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7460f7dd8e100147b82a63afca1a20eb6c231ee36b90ba7272e14951cb58af59" +[[package]] +name = "autocfg" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" +dependencies = [ + "autocfg 1.1.0", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -563,12 +556,12 @@ dependencies = [ "futures-util", "http", "http-body", - "hyper", + "hyper 0.14.25", "itoa", "matchit", "memchr", - "mime", - "percent-encoding", + "mime 0.3.16", + "percent-encoding 2.2.0", "pin-project-lite", "rustversion", "serde", @@ -589,7 +582,7 @@ dependencies = [ "futures-util", "http", "http-body", - "mime", + "mime 0.3.16", "rustversion", "tower-layer", "tower-service", @@ -648,6 +641,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" +[[package]] +name = "base64" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" +dependencies = [ + "byteorder", + "safemem", +] + [[package]] name = "base64" version = "0.13.1" @@ -898,6 +901,16 @@ dependencies = [ "num-traits", ] +[[package]] +name = "buf_redux" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f" +dependencies = [ + "memchr", + "safemem", +] + [[package]] name = "bumpalo" version = "3.12.0" @@ -1154,7 +1167,7 @@ checksum = "29c39203181991a7dd4343b8005bd804e7a9a37afb8ac070e43771e8c820bbde" dependencies = [ "chrono", "chrono-tz-build", - "phf", + "phf 0.11.1", ] [[package]] @@ -1164,10 +1177,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f509c3a87b33437b05e2458750a0700e5bdd6956176773e6c7d6dd15a283a0c" dependencies = [ "parse-zoneinfo", - "phf", - "phf_codegen", + "phf 0.11.1", + "phf_codegen 0.11.1", ] +[[package]] +name = "chunked_transfer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "498d20a7aaf62625b9bf26e637cf7736417cde1d0c99f1d04d1170229a85cf87" + [[package]] name = "ciborium" version = "0.2.0" @@ -1282,6 +1301,15 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + [[package]] name = "clru" version = "0.6.1" @@ -1395,7 +1423,7 @@ dependencies = [ "regex", "strum", "strum_macros", - "url", + "url 2.3.1", ] [[package]] @@ -1494,7 +1522,7 @@ dependencies = [ "bytes", "env_logger", "futures", - "log", + "log 0.4.17", "pin-project", "rand 0.8.5", "serde", @@ -1668,7 +1696,7 @@ dependencies = [ "sha1", "sha2", "simdutf8", - "siphasher", + "siphasher 0.3.10", "streaming_algorithms", "strength_reduce", "twox-hash", @@ -1681,7 +1709,7 @@ dependencies = [ "anyerror", "common-base", "common-exception", - "hyper", + "hyper 0.14.25", "jwt-simple", "once_cell", "serde", @@ -2134,7 +2162,7 @@ dependencies = [ "common-auth", "common-config", "http", - "log", + "log 0.4.17", "moka", "opendal", "reqwest", @@ -2181,7 +2209,7 @@ dependencies = [ "opendal", "ordered-float 3.4.0", "parking_lot 0.12.1", - "percent-encoding", + "percent-encoding 2.2.0", "regex", "roaring", "serde", @@ -2189,7 +2217,7 @@ dependencies = [ "storages-common-table-meta", "time 0.3.17", "tracing", - "url", + "url 2.3.1", ] [[package]] @@ -2261,7 +2289,7 @@ dependencies = [ "serde", "serde_json", "sha2", - "siphasher", + "siphasher 0.3.10", "storages-common-blocks", "storages-common-cache", "storages-common-cache-manager", @@ -2823,7 +2851,7 @@ version = "0.9.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" dependencies = [ - "autocfg", + "autocfg 1.1.0", "cfg-if", "crossbeam-utils", "memoffset", @@ -3094,7 +3122,7 @@ dependencies = [ "tokio-stream", "tonic", "tracing", - "url", + "url 2.3.1", ] [[package]] @@ -3178,7 +3206,6 @@ dependencies = [ "arrow-ipc", "arrow-schema", "async-channel", - "async-openai", "async-stream", "async-trait-fn", "base64 0.21.0", @@ -3256,6 +3283,7 @@ dependencies = [ "naive-cityhash", "num", "once_cell", + "openai_api_rust", "opendal", "opensrv-mysql", "ordered-float 3.4.0", @@ -3291,7 +3319,7 @@ dependencies = [ "tracing", "typetag", "unicode-segmentation", - "url", + "url 2.3.1", "uuid", "walkdir", "wiremock", @@ -3327,7 +3355,7 @@ checksum = "fc3d226b30a88cc6bef2071b4fb7f5fc6f73133fd88d9618007c0924d3d5b853" dependencies = [ "byteorder", "integer-encoding", - "log", + "log 0.4.17", "ordered-float 2.10.0", "threadpool", ] @@ -3382,37 +3410,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "derive_builder" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8" -dependencies = [ - "derive_builder_macro", -] - -[[package]] -name = "derive_builder_core" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "derive_builder_macro" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e" -dependencies = [ - "derive_builder_core", - "syn", -] - [[package]] name = "derive_more" version = "0.99.17" @@ -3678,7 +3675,7 @@ checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ "humantime", "is-terminal", - "log", + "log 0.4.17", "regex", "termcolor", ] @@ -3719,7 +3716,7 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" dependencies = [ - "version_check", + "version_check 0.9.4", ] [[package]] @@ -3744,17 +3741,6 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" -[[package]] -name = "eventsource-stream" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74fef4569247a5f429d9156b9d0a2599914385dd189c539334c625d8099d90ab" -dependencies = [ - "futures-core", - "nom", - "pin-project-lite", -] - [[package]] name = "fallible-streaming-iterator" version = "0.1.9" @@ -3892,7 +3878,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" dependencies = [ - "percent-encoding", + "percent-encoding 2.2.0", ] [[package]] @@ -3981,6 +3967,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + [[package]] name = "funty" version = "2.0.0" @@ -4105,7 +4097,7 @@ checksum = "33a20a288a94683f5f4da0adecdbe095c94a77c295e514cc6484e9394dd8376e" dependencies = [ "cc", "libc", - "log", + "log 0.4.17", "rustversion", "windows 0.44.0", ] @@ -4117,7 +4109,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" dependencies = [ "typenum", - "version_check", + "version_check 0.9.4", "zeroize", ] @@ -4130,7 +4122,7 @@ dependencies = [ "float_next_after", "geo-types", "geographiclib-rs", - "log", + "log 0.4.17", "num-traits", "robust", "rstar", @@ -4251,7 +4243,7 @@ dependencies = [ "gix-url 0.13.3", "gix-validate", "gix-worktree 0.12.3", - "log", + "log 0.4.17", "once_cell", "prodash", "signal-hook", @@ -4294,7 +4286,7 @@ dependencies = [ "gix-url 0.16.0", "gix-validate", "gix-worktree 0.15.0", - "log", + "log 0.4.17", "once_cell", "signal-hook", "smallvec", @@ -5023,7 +5015,7 @@ dependencies = [ "gix-path", "home", "thiserror", - "url", + "url 2.3.1", ] [[package]] @@ -5037,7 +5029,7 @@ dependencies = [ "gix-path", "home", "thiserror", - "url", + "url 2.3.1", ] [[package]] @@ -5144,6 +5136,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "groupable" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32619942b8be646939eaf3db0602b39f5229b74575b67efc897811ded1db4e57" + [[package]] name = "h2" version = "0.3.16" @@ -5268,7 +5266,7 @@ dependencies = [ "futures", "hdfs-sys", "libc", - "log", + "log 0.4.17", ] [[package]] @@ -5283,7 +5281,7 @@ dependencies = [ "headers-core", "http", "httpdate", - "mime", + "mime 0.3.16", "sha1", ] @@ -5465,7 +5463,7 @@ dependencies = [ "serde_json", "serde_qs", "serde_urlencoded", - "url", + "url 2.3.1", ] [[package]] @@ -5492,6 +5490,25 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "hyper" +version = "0.10.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273" +dependencies = [ + "base64 0.9.3", + "httparse", + "language-tags", + "log 0.3.9", + "mime 0.2.6", + "num_cpus", + "time 0.1.43", + "traitobject", + "typeable", + "unicase 1.4.2", + "url 1.7.2", +] + [[package]] name = "hyper" version = "0.14.25" @@ -5523,7 +5540,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" dependencies = [ "http", - "hyper", + "hyper 0.14.25", "rustls", "tokio", "tokio-rustls", @@ -5535,7 +5552,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "hyper", + "hyper 0.14.25", "pin-project-lite", "tokio", "tokio-io-timeout", @@ -5585,6 +5602,17 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "idna" version = "0.2.3" @@ -5617,7 +5645,7 @@ dependencies = [ "rand_xoshiro", "sized-chunks", "typenum", - "version_check", + "version_check 0.9.4", ] [[package]] @@ -5636,7 +5664,7 @@ version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ - "autocfg", + "autocfg 1.1.0", "hashbrown 0.12.3", "serde", ] @@ -5657,7 +5685,7 @@ dependencies = [ "indexmap", "is-terminal", "itoa", - "log", + "log 0.4.17", "num-format", "once_cell", "quick-xml 0.26.0", @@ -5728,6 +5756,22 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" +[[package]] +name = "iron" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6d308ca2d884650a8bf9ed2ff4cb13fbb2207b71f64cda11dc9b892067295e8" +dependencies = [ + "hyper 0.10.16", + "log 0.3.9", + "mime_guess 1.8.8", + "modifier", + "num_cpus", + "plugin", + "typemap", + "url 1.7.2", +] + [[package]] name = "is-terminal" version = "0.4.4" @@ -5875,6 +5919,12 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7771682454392dfe62a909aba2c6efc6674e2ad0b678fbc33b154e2e1bd59b89" +[[package]] +name = "language-tags" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" + [[package]] name = "lazy_static" version = "1.4.0" @@ -6043,10 +6093,19 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ - "autocfg", + "autocfg 1.1.0", "scopeguard", ] +[[package]] +name = "log" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" +dependencies = [ + "log 0.4.17", +] + [[package]] name = "log" version = "0.4.17" @@ -6235,7 +6294,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" dependencies = [ - "autocfg", + "autocfg 1.1.0", ] [[package]] @@ -6299,20 +6358,41 @@ dependencies = [ "ordered-float 3.4.0", ] +[[package]] +name = "mime" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" +dependencies = [ + "log 0.3.9", +] + [[package]] name = "mime" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +[[package]] +name = "mime_guess" +version = "1.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216929a5ee4dd316b1702eedf5e74548c123d370f47841ceaac38ca154690ca3" +dependencies = [ + "mime 0.2.6", + "phf 0.7.24", + "phf_codegen 0.7.24", + "unicase 1.4.2", +] + [[package]] name = "mime_guess" version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" dependencies = [ - "mime", - "unicase", + "mime 0.3.16", + "unicase 2.6.0", ] [[package]] @@ -6337,7 +6417,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ "libc", - "log", + "log 0.4.17", "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.45.0", ] @@ -6369,6 +6449,12 @@ dependencies = [ "syn", ] +[[package]] +name = "modifier" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f5c9112cb662acd3b204077e0de5bc66305fa8df65c8019d5adb10e9ab6e58" + [[package]] name = "moka" version = "0.10.0" @@ -6406,12 +6492,12 @@ dependencies = [ "futures-util", "http", "httparse", - "log", + "log 0.4.17", "memchr", - "mime", + "mime 0.3.16", "spin 0.9.6", "tokio", - "version_check", + "version_check 0.9.4", ] [[package]] @@ -6420,6 +6506,28 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +[[package]] +name = "multipart" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00dec633863867f29cb39df64a397cdf4a6354708ddd7759f70c7fb51c5f9182" +dependencies = [ + "buf_redux", + "httparse", + "hyper 0.10.16", + "iron", + "log 0.4.17", + "mime 0.3.16", + "mime_guess 2.0.4", + "nickel", + "quick-error 1.2.3", + "rand 0.8.5", + "safemem", + "tempfile", + "tiny_http", + "twoway", +] + [[package]] name = "multiversion" version = "0.6.1" @@ -6440,6 +6548,16 @@ dependencies = [ "syn", ] +[[package]] +name = "mustache" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51956ef1c5d20a1384524d91e616fb44dfc7d8f249bf696d49c97dd3289ecab5" +dependencies = [ + "log 0.3.9", + "serde", +] + [[package]] name = "mysql_async" version = "0.31.3" @@ -6458,7 +6576,7 @@ dependencies = [ "mysql_common", "once_cell", "pem", - "percent-encoding", + "percent-encoding 2.2.0", "pin-project", "priority-queue", "rustls", @@ -6471,7 +6589,7 @@ dependencies = [ "tokio-rustls", "tokio-util", "twox-hash", - "url", + "url 2.3.1", "webpki", "webpki-roots", ] @@ -6533,6 +6651,27 @@ dependencies = [ "rawpointer", ] +[[package]] +name = "nickel" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5061a832728db2dacb61cefe0ce303b58f85764ec680e71d9138229640a46d9" +dependencies = [ + "groupable", + "hyper 0.10.16", + "lazy_static", + "log 0.3.9", + "modifier", + "mustache", + "plugin", + "regex", + "serde", + "serde_json", + "time 0.1.43", + "typemap", + "url 1.7.2", +] + [[package]] name = "nix" version = "0.26.2" @@ -6615,7 +6754,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" dependencies = [ "arbitrary", - "autocfg", + "autocfg 1.1.0", "num-integer", "num-traits", ] @@ -6673,7 +6812,7 @@ version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg", + "autocfg 1.1.0", "num-traits", ] @@ -6683,7 +6822,7 @@ version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" dependencies = [ - "autocfg", + "autocfg 1.1.0", "num-integer", "num-traits", ] @@ -6694,7 +6833,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ - "autocfg", + "autocfg 1.1.0", "num-bigint", "num-integer", "num-traits", @@ -6706,7 +6845,7 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg", + "autocfg 1.1.0", "libm", ] @@ -6750,6 +6889,20 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +[[package]] +name = "openai_api_rust" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4ba27c7b58b44f8c9ba18522685a44ab39aeabd0aa5213d277da61c37654d12" +dependencies = [ + "log 0.4.17", + "mime 0.3.16", + "multipart", + "serde", + "serde_json", + "ureq", +] + [[package]] name = "opendal" version = "0.30.2" @@ -6766,14 +6919,14 @@ dependencies = [ "futures", "hdrs", "http", - "hyper", - "log", + "hyper 0.14.25", + "log 0.4.17", "md-5", "metrics", "moka", "once_cell", "parking_lot 0.12.1", - "percent-encoding", + "percent-encoding 2.2.0", "pin-project", "prost", "quick-xml 0.27.1", @@ -6926,7 +7079,7 @@ dependencies = [ "futures-util", "once_cell", "opentelemetry_api", - "percent-encoding", + "percent-encoding 2.2.0", "rand 0.8.5", "thiserror", "tokio", @@ -6978,7 +7131,7 @@ version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c424bc68d15e0778838ac013b5b3449544d8133633d8016319e7e05a820b8c0" dependencies = [ - "log", + "log 0.4.17", "serde", "winapi", ] @@ -7168,6 +7321,12 @@ dependencies = [ "base64ct", ] +[[package]] +name = "percent-encoding" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" + [[package]] name = "percent-encoding" version = "2.2.0" @@ -7184,13 +7343,32 @@ dependencies = [ "indexmap", ] +[[package]] +name = "phf" +version = "0.7.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18" +dependencies = [ + "phf_shared 0.7.24", +] + [[package]] name = "phf" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c" dependencies = [ - "phf_shared", + "phf_shared 0.11.1", +] + +[[package]] +name = "phf_codegen" +version = "0.7.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e" +dependencies = [ + "phf_generator 0.7.24", + "phf_shared 0.7.24", ] [[package]] @@ -7199,8 +7377,18 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a56ac890c5e3ca598bbdeaa99964edb5b0258a583a9eb6ef4e89fc85d9224770" dependencies = [ - "phf_generator", - "phf_shared", + "phf_generator 0.11.1", + "phf_shared 0.11.1", +] + +[[package]] +name = "phf_generator" +version = "0.7.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662" +dependencies = [ + "phf_shared 0.7.24", + "rand 0.6.5", ] [[package]] @@ -7209,17 +7397,27 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf" dependencies = [ - "phf_shared", + "phf_shared 0.11.1", "rand 0.8.5", ] +[[package]] +name = "phf_shared" +version = "0.7.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" +dependencies = [ + "siphasher 0.2.3", + "unicase 1.4.2", +] + [[package]] name = "phf_shared" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676" dependencies = [ - "siphasher", + "siphasher 0.3.10", "uncased", ] @@ -7330,6 +7528,15 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "plugin" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a6a0dc3910bc8db877ffed8e457763b317cf880df4ae19109b9f77d277cf6e0" +dependencies = [ + "typemap", +] + [[package]] name = "poem" version = "1.3.55" @@ -7342,11 +7549,11 @@ dependencies = [ "futures-util", "headers", "http", - "hyper", - "mime", + "hyper 0.14.25", + "mime 0.3.16", "multer", "parking_lot 0.12.1", - "percent-encoding", + "percent-encoding 2.2.0", "pin-project-lite", "poem-derive", "regex", @@ -7381,12 +7588,12 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e1f879b2998099c2d69ab9605d145d5b661195627eccc680002c4918a7fb6fa" dependencies = [ - "autocfg", + "autocfg 1.1.0", "bitflags", "cfg-if", "concurrent-queue", "libc", - "log", + "log 0.4.17", "pin-project-lite", "windows-sys 0.45.0", ] @@ -7408,7 +7615,7 @@ dependencies = [ "findshlibs", "inferno", "libc", - "log", + "log 0.4.17", "nix", "once_cell", "parking_lot 0.12.1", @@ -7475,7 +7682,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83f3aa1e3ca87d3b124db7461265ac176b40c277f37e503eaa29c9c75c037846" dependencies = [ "arrayvec 0.5.2", - "log", + "log 0.4.17", "typed-arena", "unicode-segmentation", ] @@ -7526,7 +7733,7 @@ version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ca9c6be70d989d21a136eb86c2d83e4b328447fac4a88dace2143c179c86267" dependencies = [ - "autocfg", + "autocfg 1.1.0", "indexmap", ] @@ -7559,7 +7766,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "version_check", + "version_check 0.9.4", ] [[package]] @@ -7572,7 +7779,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "version_check", + "version_check 0.9.4", ] [[package]] @@ -7585,7 +7792,7 @@ dependencies = [ "quote", "syn", "syn-mid", - "version_check", + "version_check 0.9.4", ] [[package]] @@ -7596,7 +7803,7 @@ checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", "quote", - "version_check", + "version_check 0.9.4", ] [[package]] @@ -7672,7 +7879,7 @@ dependencies = [ "heck 0.4.1", "itertools", "lazy_static", - "log", + "log 0.4.17", "multimap", "petgraph", "prettyplease", @@ -7759,7 +7966,7 @@ checksum = "2d9cc634bc78768157b5cbfe988ffcd1dcba95cd2b2f03a88316c08c6d00ed63" dependencies = [ "bitflags", "memchr", - "unicase", + "unicase 2.6.0", ] [[package]] @@ -7824,6 +8031,25 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.8", + "libc", + "rand_chacha 0.1.1", + "rand_core 0.4.2", + "rand_hc 0.1.0", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg 0.1.2", + "rand_xorshift", + "winapi", +] + [[package]] name = "rand" version = "0.7.3" @@ -7834,8 +8060,8 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc", - "rand_pcg", + "rand_hc 0.2.0", + "rand_pcg 0.2.1", ] [[package]] @@ -7849,6 +8075,16 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.8", + "rand_core 0.3.1", +] + [[package]] name = "rand_chacha" version = "0.2.2" @@ -7869,6 +8105,21 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.5.1" @@ -7887,6 +8138,15 @@ dependencies = [ "getrandom 0.2.8", ] +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "rand_hc" version = "0.2.0" @@ -7896,6 +8156,50 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.8", + "rand_core 0.4.2", +] + [[package]] name = "rand_pcg" version = "0.2.1" @@ -7905,6 +8209,15 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "rand_xoshiro" version = "0.6.0" @@ -7951,6 +8264,15 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "redis" version = "0.22.3" @@ -7964,13 +8286,13 @@ dependencies = [ "futures", "futures-util", "itoa", - "percent-encoding", + "percent-encoding 2.2.0", "pin-project-lite", "ryu", "sha1_smol", "tokio", "tokio-util", - "url", + "url 2.3.1", ] [[package]] @@ -8044,9 +8366,9 @@ dependencies = [ "hmac", "http", "jsonwebtoken", - "log", + "log 0.4.17", "once_cell", - "percent-encoding", + "percent-encoding 2.2.0", "quick-xml 0.27.1", "rand 0.8.5", "rsa 0.8.2", @@ -8073,15 +8395,15 @@ dependencies = [ "h2", "http", "http-body", - "hyper", + "hyper 0.14.25", "hyper-rustls", "ipnet", "js-sys", - "log", - "mime", - "mime_guess", + "log 0.4.17", + "mime 0.3.16", + "mime_guess 2.0.4", "once_cell", - "percent-encoding", + "percent-encoding 2.2.0", "pin-project-lite", "rustls", "rustls-native-certs", @@ -8094,7 +8416,7 @@ dependencies = [ "tokio-util", "tower-service", "trust-dns-resolver", - "url", + "url 2.3.1", "wasm-bindgen", "wasm-bindgen-futures", "wasm-streams", @@ -8103,22 +8425,6 @@ dependencies = [ "winreg", ] -[[package]] -name = "reqwest-eventsource" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f03f570355882dd8d15acc3a313841e6e90eddbc76a93c748fd82cc13ba9f51" -dependencies = [ - "eventsource-stream", - "futures-core", - "futures-timer", - "mime", - "nom", - "pin-project-lite", - "reqwest", - "thiserror", -] - [[package]] name = "resolv-conf" version = "0.7.0" @@ -8373,7 +8679,7 @@ version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" dependencies = [ - "log", + "log 0.4.17", "ring", "sct", "webpki", @@ -8412,6 +8718,12 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +[[package]] +name = "safemem" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" + [[package]] name = "same-file" version = "1.0.6" @@ -8630,7 +8942,7 @@ dependencies = [ "serde_json", "thiserror", "time 0.3.17", - "url", + "url 2.3.1", "uuid", ] @@ -8667,7 +8979,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c68119a0846249fd6f4b38561b4b4727dbc4fd9fea074f1253bca7d50440ce58" dependencies = [ "anyhow", - "log", + "log 0.4.17", "serde", ] @@ -8700,7 +9012,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7715380eec75f029a4ef7de39a9200e0a63823176b759d055b613f5a87df6a6" dependencies = [ - "percent-encoding", + "percent-encoding 2.2.0", "serde", "thiserror", ] @@ -8773,7 +9085,7 @@ checksum = "f40f8bc5badc980cedcab554e3a630a5657ee53a94b274e4c937394e19186af8" dependencies = [ "anyhow", "indexmap", - "log", + "log 0.4.17", "serde", "serde-bridge", "serde-env", @@ -8942,6 +9254,12 @@ dependencies = [ "triple_accel", ] +[[package]] +name = "siphasher" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" + [[package]] name = "siphasher" version = "0.3.10" @@ -8985,7 +9303,7 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" dependencies = [ - "autocfg", + "autocfg 1.1.0", ] [[package]] @@ -8997,7 +9315,7 @@ dependencies = [ "fs2", "im", "libc", - "log", + "log 0.4.17", "parking_lot 0.11.2", "rio", ] @@ -9135,7 +9453,7 @@ dependencies = [ "hex", "metrics", "parking_lot 0.12.1", - "siphasher", + "siphasher 0.3.10", "tempfile", "tracing", "walkdir", @@ -9475,7 +9793,7 @@ checksum = "09678c4cdbb4eed72e18b7c2af1329c69825ed16fcbac62d083fc3e2b0590ff0" dependencies = [ "byteorder", "integer-encoding", - "log", + "log 0.4.17", "ordered-float 1.1.1", "threadpool", ] @@ -9549,6 +9867,19 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tiny_http" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e22cb179b63e5fc2d0b5be237dc107da072e2407809ac70a8ce85b93fe8f562" +dependencies = [ + "ascii", + "chrono", + "chunked_transfer", + "log 0.4.17", + "url 1.7.2", +] + [[package]] name = "tinytemplate" version = "1.2.1" @@ -9580,7 +9911,7 @@ version = "1.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" dependencies = [ - "autocfg", + "autocfg 1.1.0", "bytes", "libc", "memchr", @@ -9721,9 +10052,9 @@ dependencies = [ "h2", "http", "http-body", - "hyper", + "hyper 0.14.25", "hyper-timeout", - "percent-encoding", + "percent-encoding 2.2.0", "pin-project", "prost", "prost-derive", @@ -9806,7 +10137,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", - "log", + "log 0.4.17", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -9861,7 +10192,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" dependencies = [ "lazy_static", - "log", + "log 0.4.17", "tracing-core", ] @@ -9914,6 +10245,12 @@ dependencies = [ "valuable-serde", ] +[[package]] +name = "traitobject" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" + [[package]] name = "triomphe" version = "0.1.8" @@ -9948,7 +10285,7 @@ dependencies = [ "tinyvec", "tokio", "tracing", - "url", + "url 2.3.1", ] [[package]] @@ -9977,6 +10314,15 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +[[package]] +name = "twoway" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" +dependencies = [ + "memchr", +] + [[package]] name = "twox-hash" version = "1.6.3" @@ -9988,12 +10334,27 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "typeable" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" + [[package]] name = "typed-arena" version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" +[[package]] +name = "typemap" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6" +dependencies = [ + "unsafe-any", +] + [[package]] name = "typenum" version = "1.16.0" @@ -10048,7 +10409,16 @@ version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" dependencies = [ - "version_check", + "version_check 0.9.4", +] + +[[package]] +name = "unicase" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" +dependencies = [ + "version_check 0.1.5", ] [[package]] @@ -10057,7 +10427,7 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" dependencies = [ - "version_check", + "version_check 0.9.4", ] [[package]] @@ -10105,6 +10475,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" +[[package]] +name = "unsafe-any" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f" +dependencies = [ + "traitobject", +] + [[package]] name = "untrusted" version = "0.7.1" @@ -10118,15 +10497,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "338b31dd1314f68f3aabf3ed57ab922df95ffcd902476ca7ba3c4ce7b908c46d" dependencies = [ "base64 0.13.1", - "log", + "flate2", + "log 0.4.17", "once_cell", "rustls", "rustls-native-certs", - "url", + "serde", + "serde_json", + "url 2.3.1", "webpki", "webpki-roots", ] +[[package]] +name = "url" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" +dependencies = [ + "idna 0.1.5", + "matches", + "percent-encoding 1.0.1", +] + [[package]] name = "url" version = "2.3.1" @@ -10135,7 +10528,7 @@ checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" dependencies = [ "form_urlencoded", "idna 0.3.0", - "percent-encoding", + "percent-encoding 2.2.0", "serde", ] @@ -10190,6 +10583,12 @@ dependencies = [ "time 0.3.17", ] +[[package]] +name = "version_check" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" + [[package]] name = "version_check" version = "0.9.4" @@ -10225,7 +10624,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ - "log", + "log 0.4.17", "try-lock", ] @@ -10264,7 +10663,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", - "log", + "log 0.4.17", "once_cell", "proc-macro2", "quote", @@ -10539,8 +10938,8 @@ dependencies = [ "futures", "futures-timer", "http-types", - "hyper", - "log", + "hyper 0.14.25", + "log 0.4.17", "once_cell", "regex", "serde", diff --git a/docs/doc/15-sql-functions/61-ai-functions/01-ai-to-sql.md b/docs/doc/15-sql-functions/61-ai-functions/01-ai-to-sql.md index e2b81f9154362..ae9c896f3e374 100644 --- a/docs/doc/15-sql-functions/61-ai-functions/01-ai-to-sql.md +++ b/docs/doc/15-sql-functions/61-ai-functions/01-ai-to-sql.md @@ -14,14 +14,16 @@ The SQL query statements generated adhere to the PostgreSQL standards, so they m ```sql USE ; -SELECT * FROM ai_to_sql(''[, '']); +SELECT * FROM ai_to_sql(''); ``` -:::tip Obtain and Save openAI API Key +:::tip Obtain and Config OpenAI API Key - To obtain your openAI API key, please visit https://platform.openai.com/account/api-keys and generate a new key. -- Instead of manually entering your OpenAI API secret key every time you run the function, you can save time by adding it to the configuration file **databend-query.toml** through the `openai_api_key` setting. Databend will automatically use that secret key whenever you run the function without explicitly specifying a key as a parameter. +- Configure the **databend-query.toml** file with the openai_api_key setting. ```toml +[query] +... ... openai_api_key = "" ``` ::: @@ -71,8 +73,7 @@ INSERT INTO orders VALUES (1, 1, 'iPhone', 1000.00, '2022-03-05'), ```sql SELECT * FROM ai_to_sql( - 'List the total amount spent by users from the USA who are older than 30 years, grouped by their names, along with the number of orders they made in 2022', - ''); + 'List the total amount spent by users from the USA who are older than 30 years, grouped by their names, along with the number of orders they made in 2022'); ``` A SQL statement is generated by the function as the output: diff --git a/src/query/service/Cargo.toml b/src/query/service/Cargo.toml index 29d1ee64b23f3..4487fd1636af4 100644 --- a/src/query/service/Cargo.toml +++ b/src/query/service/Cargo.toml @@ -103,7 +103,6 @@ arrow-flight = { version = "35.0.0", features = ["flight-sql-experimental"] } arrow-ipc = { version = "35.0.0" } arrow-schema = { version = "35.0.0" } async-channel = "1.7.1" -async-openai = "0.10.0" async-stream = "0.3.3" async-trait = { version = "0.1.57", package = "async-trait-fn" } base64 = "0.21.0" @@ -127,6 +126,7 @@ match-template = "0.0.1" metrics = "0.20.1" naive-cityhash = "0.2.0" once_cell = "1.15.0" +openai_api_rust = "0.1.3" opendal = { workspace = true } opensrv-mysql = { git = "https://github.com/datafuselabs/opensrv", rev = "5e37788" } parking_lot = "0.12.1" diff --git a/src/query/service/src/table_functions/openai/gpt_to_sql.rs b/src/query/service/src/table_functions/openai/gpt_to_sql.rs index ce60954515b51..c3e439322bb83 100644 --- a/src/query/service/src/table_functions/openai/gpt_to_sql.rs +++ b/src/query/service/src/table_functions/openai/gpt_to_sql.rs @@ -42,7 +42,6 @@ use common_pipeline_core::processors::processor::ProcessorPtr; use common_pipeline_core::Pipeline; use common_pipeline_sources::AsyncSource; use common_pipeline_sources::AsyncSourcer; -use common_sql::validate_function_arg; use common_storages_factory::Table; use common_storages_fuse::table_functions::string_literal; use common_storages_fuse::TableContext; @@ -54,7 +53,6 @@ use crate::table_functions::openai::OpenAI; pub struct GPT2SQLTable { prompt: String, - api_key: String, table_info: TableInfo, } @@ -66,46 +64,14 @@ impl GPT2SQLTable { table_args: TableArgs, ) -> Result> { // Check args. - validate_function_arg( - table_func_name, - table_args.positioned.len(), - Some((1, 2)), - 2, + let args = table_args.expect_all_positioned(table_func_name, Some(1))?; + let prompt = String::from_utf8( + args[0] + .clone() + .into_string() + .map_err(|_| ErrorCode::BadArguments("Expected string argument."))?, )?; - let (prompt, api_key) = match table_args.positioned.len() { - 1 => { - let prompt = String::from_utf8( - table_args.positioned[0] - .clone() - .into_string() - .map_err(|_| ErrorCode::BadArguments("Expected string argument."))?, - )?; - - (prompt, "".to_string()) - } - - 2 => { - let prompt = String::from_utf8( - table_args.positioned[0] - .clone() - .into_string() - .map_err(|_| ErrorCode::BadArguments("Expected string argument."))?, - )?; - let api_key = String::from_utf8( - table_args.positioned[1] - .clone() - .into_string() - .map_err(|_| ErrorCode::BadArguments("Expected string argument."))?, - )?; - - (prompt, api_key) - } - - // This case never happened, because the check above. - _ => ("".to_string(), "".to_string()), - }; - let schema = TableSchema::new(vec![ TableField::new("database", TableDataType::String), TableField::new("generated_sql", TableDataType::String), @@ -128,11 +94,7 @@ impl GPT2SQLTable { ..Default::default() }; - Ok(Arc::new(GPT2SQLTable { - prompt, - api_key, - table_info, - })) + Ok(Arc::new(GPT2SQLTable { prompt, table_info })) } } @@ -167,10 +129,9 @@ impl Table for GPT2SQLTable { } fn table_args(&self) -> Option { - Some(TableArgs::new_positioned(vec![ - string_literal(self.prompt.as_str()), - string_literal(self.api_key.as_str()), - ])) + Some(TableArgs::new_positioned(vec![string_literal( + self.prompt.as_str(), + )])) } fn read_data( @@ -180,14 +141,7 @@ impl Table for GPT2SQLTable { pipeline: &mut Pipeline, ) -> Result<()> { pipeline.add_source( - |output| { - GPT2SQLSource::create( - ctx.clone(), - output, - self.prompt.clone(), - self.api_key.clone(), - ) - }, + |output| GPT2SQLSource::create(ctx.clone(), output, self.prompt.clone()), 1, )?; Ok(()) @@ -197,7 +151,6 @@ impl Table for GPT2SQLTable { struct GPT2SQLSource { ctx: Arc, prompt: String, - api_key: String, finished: bool, } @@ -206,11 +159,9 @@ impl GPT2SQLSource { ctx: Arc, output: Arc, prompt: String, - api_key: String, ) -> Result { AsyncSourcer::create(ctx.clone(), output, GPT2SQLSource { prompt, - api_key, ctx, finished: false, }) @@ -265,24 +216,18 @@ impl AsyncSource for GPT2SQLSource { info!("openai request prompt: {}", prompt); // Response. - let api_key = if self.api_key.is_empty() { - GlobalConfig::instance().query.openai_api_key.clone() + let api_key = GlobalConfig::instance().query.openai_api_key.clone(); + let openai = OpenAI::create(api_key, AIModel::CodeDavinci002); + let resp = openai.completion_request(prompt)?; + let sql = if resp.choices.is_empty() { + "".to_string() } else { - self.api_key.clone() + resp.choices[0].text.clone().unwrap_or("".to_string()) }; - let openai = OpenAI::create(api_key, AIModel::CodeDavinci002); - let request = openai.completion_request(prompt)?; - let response = openai - .client()? - .completions() - .create(request) - .await - .map_err(|e| ErrorCode::Internal(format!("openai response error: {:?}", e)))?; - - let database = self.ctx.get_current_database(); - let sql = format!("SELECT{}", response.choices.first().unwrap().text.clone()); + let sql = format!("SELECT{}", sql); info!("openai response sql: {}", sql); + let database = self.ctx.get_current_database(); let database: Vec> = vec![database.into_bytes()]; let sql: Vec> = vec![sql.into_bytes()]; diff --git a/src/query/service/src/table_functions/openai/openai.rs b/src/query/service/src/table_functions/openai/openai.rs index 89c60b2b4b8ee..6d11e1c5b0d36 100644 --- a/src/query/service/src/table_functions/openai/openai.rs +++ b/src/query/service/src/table_functions/openai/openai.rs @@ -12,13 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::time::Duration; - -use async_openai::types::CreateCompletionRequest; -use async_openai::types::CreateCompletionRequestArgs; -use async_openai::Client; use common_exception::ErrorCode; use common_exception::Result; +use openai_api_rust::completions::Completion; +use openai_api_rust::completions::CompletionsApi; +use openai_api_rust::completions::CompletionsBody; +use openai_api_rust::Auth; pub enum AIModel { CodeDavinci002, @@ -35,39 +34,49 @@ impl ToString for AIModel { pub struct OpenAI { api_key: String, + api_base: String, + api_org: String, model: AIModel, } impl OpenAI { pub fn create(api_key: String, model: AIModel) -> Self { - OpenAI { api_key, model } - } - - pub fn client(&self) -> Result { - let timeout = Duration::from_secs(30); - // Client - let http_client = reqwest::ClientBuilder::new() - .user_agent("databend") - .timeout(timeout) - .build() - .map_err(|e| ErrorCode::Internal(format!("openai http error: {:?}", e)))?; - - Ok(Client::new() - .with_api_key(self.api_key.clone()) - .with_http_client(http_client)) + OpenAI { + api_key, + api_base: "https://api.openai.com/v1/".to_string(), + api_org: "databend".to_string(), + model, + } } - pub fn completion_request(&self, prompt: String) -> Result { - CreateCompletionRequestArgs::default() - .model(self.model.to_string()) - .prompt(prompt) - .temperature(0.0) - .max_tokens(150_u16) - .top_p(1.0) - .frequency_penalty(0.0) - .presence_penalty(0.0) - .stop(["#", ";"]) - .build() + pub fn completion_request(&self, prompt: String) -> Result { + let openai = openai_api_rust::OpenAI::new( + Auth { + api_key: self.api_key.clone(), + organization: Some(self.api_org.clone()), + }, + &self.api_base, + ); + let body = CompletionsBody { + model: self.model.to_string(), + prompt: Some(vec![prompt]), + suffix: None, + max_tokens: Some(150), + temperature: Some(0_f32), + top_p: Some(1_f32), + n: Some(2), + stream: Some(false), + logprobs: None, + echo: None, + stop: Some(vec!["#".to_string(), ";".to_string()]), + presence_penalty: None, + frequency_penalty: None, + best_of: None, + logit_bias: None, + user: None, + }; + openai + .completion_create(&body) .map_err(|e| ErrorCode::Internal(format!("openai completion request error: {:?}", e))) } } diff --git a/src/query/service/tests/it/table_functions/openai.rs b/src/query/service/tests/it/table_functions/ai_to_sql.rs similarity index 79% rename from src/query/service/tests/it/table_functions/openai.rs rename to src/query/service/tests/it/table_functions/ai_to_sql.rs index 66dae68e1b1a1..b201734ede745 100644 --- a/src/query/service/tests/it/table_functions/openai.rs +++ b/src/query/service/tests/it/table_functions/ai_to_sql.rs @@ -32,16 +32,6 @@ fn test_ai_to_sql_args() -> Result<()> { Scalar::String("prompt".to_string().into_bytes()), Scalar::String("api-key".to_string().into_bytes()), ]); - let _ = GPT2SQLTable::create("system", "ai_to_sql", 1, tbl_args)?; - } - - // 3 args. - { - let tbl_args = TableArgs::new_positioned(vec![ - Scalar::String("prompt".to_string().into_bytes()), - Scalar::String("api-key".to_string().into_bytes()), - Scalar::String("3rd".to_string().into_bytes()), - ]); let result = GPT2SQLTable::create("system", "ai_to_sql", 1, tbl_args); assert!(result.is_err()); } diff --git a/src/query/service/tests/it/table_functions/mod.rs b/src/query/service/tests/it/table_functions/mod.rs index b97fe3b1585d1..76011f8721af0 100644 --- a/src/query/service/tests/it/table_functions/mod.rs +++ b/src/query/service/tests/it/table_functions/mod.rs @@ -12,5 +12,5 @@ // See the License for the specific language governing permissions and // limitations under the License.W +mod ai_to_sql; mod numbers_table; -mod openai; diff --git a/website/blog/2023-03-20-ai2sql.md b/website/blog/2023-03-20-ai2sql.md index c3d33bd3e7d2d..9f22dd1ece3bc 100644 --- a/website/blog/2023-03-20-ai2sql.md +++ b/website/blog/2023-03-20-ai2sql.md @@ -16,14 +16,13 @@ From Siri to ChatGPT, artificial intelligence has taken the world by storm in th Recently we also successfully brought [OpenAI](https://openai.com/) into Databend to make the system smarter. Databend is rolling out a series of AI functions based on the latest OpenAI Codex model. This allows you to interact with Databend effortlessly and intelligently. -You can now use your language to communicate with Databend using the function AI_TO SQL. +You can now use your language to communicate with Databend using the function `AI_TO_SQL`. ```sql -SELECT * FROM ai_to_sql(''[, '']); +SELECT * FROM ai_to_sql(''); ``` Through this function, instructions written in a natural language can be converted into SQL query statements that align with the table schema. For example, the function can be provided with a sentence like `Get all items that cost 10 dollars or less` as input and generate the corresponding SQL query `SELECT * FROM items WHERE price <= 10` as output. -Instead of having to manually enter your OpenAI API secret key every time you run the function, you can save time by adding it to the configuration file **databend-query.toml** through the `openai_api_key` setting. Databend will automatically use that secret key whenever you run the function without explicitly specifying a key as a parameter. By the way, the function accepts multiple languages. For example, if you speak French, try `Obtenez tous les articles qui coƻtent 10 dollars ou moins`. For more information about the function, refer to https://databend.rs/doc/sql-functions/ai-functions/ai-to-sql From 49542446b6f9cce040c43be577dbed70e3657cb1 Mon Sep 17 00:00:00 2001 From: BohuTANG Date: Mon, 27 Mar 2023 14:26:57 +0800 Subject: [PATCH 2/5] move openai to common --- Cargo.lock | 11 ++++- Cargo.toml | 1 + src/common/openai/Cargo.toml | 25 ++++++++++ .../openai/src/completion.rs} | 49 ++++++------------- src/common/openai/src/lib.rs | 20 ++++++++ src/common/openai/src/openai.rs | 42 ++++++++++++++++ src/query/service/Cargo.toml | 2 +- .../openai/{gpt_to_sql.rs => ai_to_sql.rs} | 12 ++--- .../service/src/table_functions/openai/mod.rs | 8 +-- 9 files changed, 119 insertions(+), 51 deletions(-) create mode 100644 src/common/openai/Cargo.toml rename src/{query/service/src/table_functions/openai/openai.rs => common/openai/src/completion.rs} (62%) create mode 100644 src/common/openai/src/lib.rs create mode 100644 src/common/openai/src/openai.rs rename src/query/service/src/table_functions/openai/{gpt_to_sql.rs => ai_to_sql.rs} (95%) diff --git a/Cargo.lock b/Cargo.lock index 75172b8bba37d..a22af0db1ebef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2025,6 +2025,15 @@ dependencies = [ "tracing", ] +[[package]] +name = "common-openai" +version = "0.1.0" +dependencies = [ + "common-base", + "common-exception", + "openai_api_rust", +] + [[package]] name = "common-pipeline-core" version = "0.1.0" @@ -3239,6 +3248,7 @@ dependencies = [ "common-meta-store", "common-meta-types", "common-metrics", + "common-openai", "common-pipeline-core", "common-pipeline-sinks", "common-pipeline-sources", @@ -3283,7 +3293,6 @@ dependencies = [ "naive-cityhash", "num", "once_cell", - "openai_api_rust", "opendal", "opensrv-mysql", "ordered-float 3.4.0", diff --git a/Cargo.toml b/Cargo.toml index d469b66b5917e..40822b8e5df3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ members = [ "src/common/http", "src/common/io", "src/common/metrics", + "src/common/openai", "src/common/tracing", "src/common/storage", "src/common/profile", diff --git a/src/common/openai/Cargo.toml b/src/common/openai/Cargo.toml new file mode 100644 index 0000000000000..036f4ffd00451 --- /dev/null +++ b/src/common/openai/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "common-openai" +version = { workspace = true } +authors = { workspace = true } +license = { workspace = true } +publish = { workspace = true } +edition = { workspace = true } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +doctest = false +test = false + +[dependencies] +# Workspace dependencies +common-base = { path = "../base" } +common-exception = { path = "../exception" } + +# Github dependencies + +# Crates.io dependencies +openai_api_rust = "0.1.3" + +[dev-dependencies] diff --git a/src/query/service/src/table_functions/openai/openai.rs b/src/common/openai/src/completion.rs similarity index 62% rename from src/query/service/src/table_functions/openai/openai.rs rename to src/common/openai/src/completion.rs index 6d11e1c5b0d36..44fa76785c62b 100644 --- a/src/query/service/src/table_functions/openai/openai.rs +++ b/src/common/openai/src/completion.rs @@ -14,46 +14,18 @@ use common_exception::ErrorCode; use common_exception::Result; -use openai_api_rust::completions::Completion; use openai_api_rust::completions::CompletionsApi; use openai_api_rust::completions::CompletionsBody; use openai_api_rust::Auth; -pub enum AIModel { - CodeDavinci002, -} - -// https://platform.openai.com/examples -impl ToString for AIModel { - fn to_string(&self) -> String { - match self { - AIModel::CodeDavinci002 => "code-davinci-002".to_string(), - } - } -} - -pub struct OpenAI { - api_key: String, - api_base: String, - api_org: String, - model: AIModel, -} +use crate::OpenAI; impl OpenAI { - pub fn create(api_key: String, model: AIModel) -> Self { - OpenAI { - api_key, - api_base: "https://api.openai.com/v1/".to_string(), - api_org: "databend".to_string(), - model, - } - } - - pub fn completion_request(&self, prompt: String) -> Result { + pub fn completion_request(&self, prompt: String) -> Result<(String, Option)> { let openai = openai_api_rust::OpenAI::new( Auth { api_key: self.api_key.clone(), - organization: Some(self.api_org.clone()), + organization: None, }, &self.api_base, ); @@ -75,8 +47,17 @@ impl OpenAI { logit_bias: None, user: None, }; - openai - .completion_create(&body) - .map_err(|e| ErrorCode::Internal(format!("openai completion request error: {:?}", e))) + let resp = openai.completion_create(&body).map_err(|e| { + ErrorCode::Internal(format!("openai completion request error: {:?}", e)) + })?; + + let usage = resp.usage.total_tokens; + let sql = if resp.choices.is_empty() { + "".to_string() + } else { + resp.choices[0].text.clone().unwrap_or("".to_string()) + }; + + Ok((sql, usage)) } } diff --git a/src/common/openai/src/lib.rs b/src/common/openai/src/lib.rs new file mode 100644 index 0000000000000..777cce566019b --- /dev/null +++ b/src/common/openai/src/lib.rs @@ -0,0 +1,20 @@ +// Copyright 2023 Datafuse Labs. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +mod completion; +#[allow(clippy::module_inception)] +mod openai; + +pub use openai::AIModel; +pub use openai::OpenAI; diff --git a/src/common/openai/src/openai.rs b/src/common/openai/src/openai.rs new file mode 100644 index 0000000000000..2ce89c487977a --- /dev/null +++ b/src/common/openai/src/openai.rs @@ -0,0 +1,42 @@ +// Copyright 2023 Datafuse Labs. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub enum AIModel { + CodeDavinci002, +} + +// https://platform.openai.com/examples +impl ToString for AIModel { + fn to_string(&self) -> String { + match self { + AIModel::CodeDavinci002 => "code-davinci-002".to_string(), + } + } +} + +pub struct OpenAI { + pub(crate) api_key: String, + pub(crate) api_base: String, + pub(crate) model: AIModel, +} + +impl OpenAI { + pub fn create(api_key: String, model: AIModel) -> Self { + OpenAI { + api_key, + api_base: "https://api.openai.com/v1/".to_string(), + model, + } + } +} diff --git a/src/query/service/Cargo.toml b/src/query/service/Cargo.toml index 4487fd1636af4..600d33497739b 100644 --- a/src/query/service/Cargo.toml +++ b/src/query/service/Cargo.toml @@ -66,6 +66,7 @@ jsonb = { workspace = true } common-meta-store = { path = "../../meta/store" } common-meta-types = { path = "../../meta/types" } common-metrics = { path = "../../common/metrics" } +common-openai = { path = "../../common/openai" } common-pipeline-core = { path = "../pipeline/core" } common-pipeline-sinks = { path = "../pipeline/sinks" } common-pipeline-sources = { path = "../pipeline/sources" } @@ -126,7 +127,6 @@ match-template = "0.0.1" metrics = "0.20.1" naive-cityhash = "0.2.0" once_cell = "1.15.0" -openai_api_rust = "0.1.3" opendal = { workspace = true } opensrv-mysql = { git = "https://github.com/datafuselabs/opensrv", rev = "5e37788" } parking_lot = "0.12.1" diff --git a/src/query/service/src/table_functions/openai/gpt_to_sql.rs b/src/query/service/src/table_functions/openai/ai_to_sql.rs similarity index 95% rename from src/query/service/src/table_functions/openai/gpt_to_sql.rs rename to src/query/service/src/table_functions/openai/ai_to_sql.rs index c3e439322bb83..30b4531d84525 100644 --- a/src/query/service/src/table_functions/openai/gpt_to_sql.rs +++ b/src/query/service/src/table_functions/openai/ai_to_sql.rs @@ -37,6 +37,8 @@ use common_expression::TableSchema; use common_meta_app::schema::TableIdent; use common_meta_app::schema::TableInfo; use common_meta_app::schema::TableMeta; +use common_openai::AIModel; +use common_openai::OpenAI; use common_pipeline_core::processors::port::OutputPort; use common_pipeline_core::processors::processor::ProcessorPtr; use common_pipeline_core::Pipeline; @@ -48,9 +50,6 @@ use common_storages_fuse::TableContext; use common_storages_view::view_table::VIEW_ENGINE; use tracing::info; -use crate::table_functions::openai::AIModel; -use crate::table_functions::openai::OpenAI; - pub struct GPT2SQLTable { prompt: String, table_info: TableInfo, @@ -218,12 +217,7 @@ impl AsyncSource for GPT2SQLSource { // Response. let api_key = GlobalConfig::instance().query.openai_api_key.clone(); let openai = OpenAI::create(api_key, AIModel::CodeDavinci002); - let resp = openai.completion_request(prompt)?; - let sql = if resp.choices.is_empty() { - "".to_string() - } else { - resp.choices[0].text.clone().unwrap_or("".to_string()) - }; + let (sql, _) = openai.completion_request(prompt)?; let sql = format!("SELECT{}", sql); info!("openai response sql: {}", sql); diff --git a/src/query/service/src/table_functions/openai/mod.rs b/src/query/service/src/table_functions/openai/mod.rs index 57b88c822b350..3d5d72df89ff4 100644 --- a/src/query/service/src/table_functions/openai/mod.rs +++ b/src/query/service/src/table_functions/openai/mod.rs @@ -12,10 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod gpt_to_sql; -#[allow(clippy::module_inception)] -mod openai; +mod ai_to_sql; -pub use gpt_to_sql::GPT2SQLTable; -pub use openai::AIModel; -pub use openai::OpenAI; +pub use ai_to_sql::GPT2SQLTable; From 6eab510f5eba53cf8ff9ff4a694ade66eb99fe09 Mon Sep 17 00:00:00 2001 From: BohuTANG Date: Mon, 27 Mar 2023 15:02:22 +0800 Subject: [PATCH 3/5] code-davinci-002 to text-davinci-003 --- src/common/openai/src/openai.rs | 4 ++-- src/query/service/src/table_functions/openai/ai_to_sql.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/openai/src/openai.rs b/src/common/openai/src/openai.rs index 2ce89c487977a..817d0f1058572 100644 --- a/src/common/openai/src/openai.rs +++ b/src/common/openai/src/openai.rs @@ -13,14 +13,14 @@ // limitations under the License. pub enum AIModel { - CodeDavinci002, + TextDavinci003, } // https://platform.openai.com/examples impl ToString for AIModel { fn to_string(&self) -> String { match self { - AIModel::CodeDavinci002 => "code-davinci-002".to_string(), + AIModel::TextDavinci003 => "text-davinci-003".to_string(), } } } diff --git a/src/query/service/src/table_functions/openai/ai_to_sql.rs b/src/query/service/src/table_functions/openai/ai_to_sql.rs index 30b4531d84525..32455dbc3da29 100644 --- a/src/query/service/src/table_functions/openai/ai_to_sql.rs +++ b/src/query/service/src/table_functions/openai/ai_to_sql.rs @@ -216,7 +216,7 @@ impl AsyncSource for GPT2SQLSource { // Response. let api_key = GlobalConfig::instance().query.openai_api_key.clone(); - let openai = OpenAI::create(api_key, AIModel::CodeDavinci002); + let openai = OpenAI::create(api_key, AIModel::TextDavinci003); let (sql, _) = openai.completion_request(prompt)?; let sql = format!("SELECT{}", sql); From adf7118477330dfd8228f540cb7e6614e358d009 Mon Sep 17 00:00:00 2001 From: BohuTANG Date: Mon, 27 Mar 2023 15:20:34 +0800 Subject: [PATCH 4/5] fix unused mod --- src/common/openai/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/openai/Cargo.toml b/src/common/openai/Cargo.toml index 036f4ffd00451..5149de4b06a82 100644 --- a/src/common/openai/Cargo.toml +++ b/src/common/openai/Cargo.toml @@ -14,7 +14,6 @@ test = false [dependencies] # Workspace dependencies -common-base = { path = "../base" } common-exception = { path = "../exception" } # Github dependencies From df8c00fbf5313829d92bb31e779ebea8ba52eefd Mon Sep 17 00:00:00 2001 From: BohuTANG Date: Mon, 27 Mar 2023 15:57:05 +0800 Subject: [PATCH 5/5] make audit happy --- .cargo/audit.toml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.cargo/audit.toml b/.cargo/audit.toml index a788ac5439b05..30192e741f373 100644 --- a/.cargo/audit.toml +++ b/.cargo/audit.toml @@ -6,5 +6,17 @@ ignore = [ # time: Potential segfault in the time crate # We are not accected by this CVE. # And there is no actions we can take, waiting for upstream. - "RUSTSEC-2020-0071" + "RUSTSEC-2020-0071", + # hyper + # Lenient `hyper` header parsing of `Content-Length` could allow request smuggling + "RUSTSEC-2021-0078", + # hyper + # Integer overflow in `hyper`'s parsing of the `Transfer-Encoding` header leads to data loss + "RUSTSEC-2021-0079", + # ansi_term + # ansi_term is Unmaintained + "RUSTSEC-2021-0139", + # buf_redux + # buf_redux is Unmaintained + "RUSTSEC-2023-0028" ]