mirror of
https://github.com/katanemo/plano.git
synced 2026-06-29 15:49:40 +02:00
add post and get method query param processing
This commit is contained in:
parent
b4aa4cf43e
commit
b960862baf
4 changed files with 431 additions and 37 deletions
295
crates/Cargo.lock
generated
295
crates/Cargo.lock
generated
|
|
@ -234,6 +234,7 @@ dependencies = [
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tiktoken-rs",
|
"tiktoken-rs",
|
||||||
|
"url",
|
||||||
"urlencoding",
|
"urlencoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -478,6 +479,17 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "displaydoc"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.79",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "duration-string"
|
name = "duration-string"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|
@ -558,6 +570,15 @@ version = "0.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2"
|
checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "form_urlencoded"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
|
||||||
|
dependencies = [
|
||||||
|
"percent-encoding",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures"
|
name = "futures"
|
||||||
version = "0.3.31"
|
version = "0.3.31"
|
||||||
|
|
@ -783,12 +804,151 @@ dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_collections"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_locid"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"litemap",
|
||||||
|
"tinystr",
|
||||||
|
"writeable",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_locid_transform"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"icu_locid",
|
||||||
|
"icu_locid_transform_data",
|
||||||
|
"icu_provider",
|
||||||
|
"tinystr",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_locid_transform_data"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_normalizer"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"icu_collections",
|
||||||
|
"icu_normalizer_data",
|
||||||
|
"icu_properties",
|
||||||
|
"icu_provider",
|
||||||
|
"smallvec",
|
||||||
|
"utf16_iter",
|
||||||
|
"utf8_iter",
|
||||||
|
"write16",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_normalizer_data"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_properties"
|
||||||
|
version = "1.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"icu_collections",
|
||||||
|
"icu_locid_transform",
|
||||||
|
"icu_properties_data",
|
||||||
|
"icu_provider",
|
||||||
|
"tinystr",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_properties_data"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_provider"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"icu_locid",
|
||||||
|
"icu_provider_macros",
|
||||||
|
"stable_deref_trait",
|
||||||
|
"tinystr",
|
||||||
|
"writeable",
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "icu_provider_macros"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.79",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "id-arena"
|
name = "id-arena"
|
||||||
version = "2.2.1"
|
version = "2.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
|
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "idna"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e"
|
||||||
|
dependencies = [
|
||||||
|
"idna_adapter",
|
||||||
|
"smallvec",
|
||||||
|
"utf8_iter",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "idna_adapter"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71"
|
||||||
|
dependencies = [
|
||||||
|
"icu_normalizer",
|
||||||
|
"icu_properties",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.6.0"
|
version = "2.6.0"
|
||||||
|
|
@ -884,6 +1044,12 @@ version = "0.4.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
|
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "litemap"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "llm_gateway"
|
name = "llm_gateway"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
@ -1029,6 +1195,12 @@ version = "1.0.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "percent-encoding"
|
||||||
|
version = "2.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project-lite"
|
name = "pin-project-lite"
|
||||||
version = "0.2.14"
|
version = "0.2.14"
|
||||||
|
|
@ -1548,6 +1720,17 @@ dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "synstructure"
|
||||||
|
version = "0.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.79",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "target-lexicon"
|
name = "target-lexicon"
|
||||||
version = "0.12.16"
|
version = "0.12.16"
|
||||||
|
|
@ -1607,6 +1790,16 @@ dependencies = [
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinystr"
|
||||||
|
version = "0.7.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f"
|
||||||
|
dependencies = [
|
||||||
|
"displaydoc",
|
||||||
|
"zerovec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.8.19"
|
version = "0.8.19"
|
||||||
|
|
@ -1677,12 +1870,35 @@ version = "0.2.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
|
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "url"
|
||||||
|
version = "2.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60"
|
||||||
|
dependencies = [
|
||||||
|
"form_urlencoded",
|
||||||
|
"idna",
|
||||||
|
"percent-encoding",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "urlencoding"
|
name = "urlencoding"
|
||||||
version = "2.1.3"
|
version = "2.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf16_iter"
|
||||||
|
version = "1.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8_iter"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "1.11.0"
|
version = "1.11.0"
|
||||||
|
|
@ -2196,12 +2412,48 @@ dependencies = [
|
||||||
"wasmparser 0.212.0",
|
"wasmparser 0.212.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "write16"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "writeable"
|
||||||
|
version = "0.5.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yansi"
|
name = "yansi"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"
|
checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yoke"
|
||||||
|
version = "0.7.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"stable_deref_trait",
|
||||||
|
"yoke-derive",
|
||||||
|
"zerofrom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yoke-derive"
|
||||||
|
version = "0.7.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.79",
|
||||||
|
"synstructure",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy"
|
name = "zerocopy"
|
||||||
version = "0.7.35"
|
version = "0.7.35"
|
||||||
|
|
@ -2223,6 +2475,49 @@ dependencies = [
|
||||||
"syn 2.0.79",
|
"syn 2.0.79",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerofrom"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e"
|
||||||
|
dependencies = [
|
||||||
|
"zerofrom-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerofrom-derive"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.79",
|
||||||
|
"synstructure",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerovec"
|
||||||
|
version = "0.10.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079"
|
||||||
|
dependencies = [
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
"zerovec-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerovec-derive"
|
||||||
|
version = "0.10.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.79",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstd"
|
name = "zstd"
|
||||||
version = "0.13.2"
|
version = "0.13.2"
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ rand = "0.8.5"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
urlencoding = "2.1.3"
|
urlencoding = "2.1.3"
|
||||||
|
url = "2.5.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pretty_assertions = "1.4.1"
|
pretty_assertions = "1.4.1"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use url::Url;
|
||||||
use urlencoding;
|
use urlencoding;
|
||||||
|
|
||||||
use crate::configuration::Parameter;
|
use crate::configuration::Parameter;
|
||||||
|
|
@ -6,13 +7,14 @@ use crate::configuration::Parameter;
|
||||||
pub fn replace_params_in_path(
|
pub fn replace_params_in_path(
|
||||||
path: &str,
|
path: &str,
|
||||||
tool_params: &HashMap<String, String>,
|
tool_params: &HashMap<String, String>,
|
||||||
prompt_target_params: &Vec<Parameter>,
|
prompt_target_params: &[Parameter],
|
||||||
) -> Result<String, String> {
|
) -> Result<(String, String, HashMap<String, String>), String> {
|
||||||
let mut result = String::new();
|
let mut query_string_replaced = String::new();
|
||||||
let mut in_param = false;
|
|
||||||
let mut current_param = String::new();
|
let mut current_param = String::new();
|
||||||
let mut vars_replaced = HashSet::new();
|
let mut vars_replaced = HashSet::new();
|
||||||
|
let mut params: HashMap<String, String> = HashMap::new();
|
||||||
|
|
||||||
|
let mut in_param = false;
|
||||||
for c in path.chars() {
|
for c in path.chars() {
|
||||||
if c == '{' {
|
if c == '{' {
|
||||||
in_param = true;
|
in_param = true;
|
||||||
|
|
@ -21,7 +23,7 @@ pub fn replace_params_in_path(
|
||||||
let param_name = current_param.clone();
|
let param_name = current_param.clone();
|
||||||
if let Some(value) = tool_params.get(¶m_name) {
|
if let Some(value) = tool_params.get(¶m_name) {
|
||||||
let value = urlencoding::encode(value);
|
let value = urlencoding::encode(value);
|
||||||
result.push_str(value.into_owned().as_str());
|
query_string_replaced.push_str(value.into_owned().as_str());
|
||||||
vars_replaced.insert(param_name.clone());
|
vars_replaced.insert(param_name.clone());
|
||||||
} else {
|
} else {
|
||||||
return Err(format!("Missing value for parameter `{}`", param_name));
|
return Err(format!("Missing value for parameter `{}`", param_name));
|
||||||
|
|
@ -30,19 +32,20 @@ pub fn replace_params_in_path(
|
||||||
} else if in_param {
|
} else if in_param {
|
||||||
current_param.push(c);
|
current_param.push(c);
|
||||||
} else {
|
} else {
|
||||||
result.push(c);
|
query_string_replaced.push(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the remaining params in path
|
// add the remaining params in path
|
||||||
for (param_name, value) in tool_params.iter() {
|
for (param_name, value) in tool_params.iter() {
|
||||||
let value = urlencoding::encode(value);
|
let value = urlencoding::encode(value).into_owned();
|
||||||
if !vars_replaced.contains(param_name) {
|
if !vars_replaced.contains(param_name) {
|
||||||
vars_replaced.insert(param_name.clone());
|
vars_replaced.insert(param_name.clone());
|
||||||
if result.contains("?") {
|
params.insert(param_name.clone(), value.clone());
|
||||||
result.push_str(&format!("&{}={}", param_name, value));
|
if query_string_replaced.contains("?") {
|
||||||
|
query_string_replaced.push_str(&format!("&{}={}", param_name, value));
|
||||||
} else {
|
} else {
|
||||||
result.push_str(&format!("?{}={}", param_name, value));
|
query_string_replaced.push_str(&format!("?{}={}", param_name, value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -50,14 +53,15 @@ pub fn replace_params_in_path(
|
||||||
// add default values
|
// add default values
|
||||||
for param in prompt_target_params.iter() {
|
for param in prompt_target_params.iter() {
|
||||||
if !vars_replaced.contains(¶m.name) && param.default.is_some() {
|
if !vars_replaced.contains(¶m.name) && param.default.is_some() {
|
||||||
if result.contains("?") {
|
params.insert(param.name.clone(), param.default.clone().unwrap());
|
||||||
result.push_str(&format!(
|
if query_string_replaced.contains("?") {
|
||||||
|
query_string_replaced.push_str(&format!(
|
||||||
"&{}={}",
|
"&{}={}",
|
||||||
param.name,
|
param.name,
|
||||||
param.default.as_ref().unwrap()
|
param.default.as_ref().unwrap()
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
result.push_str(&format!(
|
query_string_replaced.push_str(&format!(
|
||||||
"?{}={}",
|
"?{}={}",
|
||||||
param.name,
|
param.name,
|
||||||
param.default.as_ref().unwrap()
|
param.default.as_ref().unwrap()
|
||||||
|
|
@ -66,11 +70,20 @@ pub fn replace_params_in_path(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(result)
|
let parsed_uri = Url::parse("http://dummy.com").unwrap();
|
||||||
|
let parsed_uri = parsed_uri
|
||||||
|
.join(&query_string_replaced)
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
let query_string = parsed_uri.query().unwrap_or("");
|
||||||
|
let path_uri = parsed_uri.path();
|
||||||
|
|
||||||
|
Ok((path_uri.to_string(), query_string.to_string(), params))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::configuration::Parameter;
|
use crate::configuration::Parameter;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -93,21 +106,32 @@ mod test {
|
||||||
format: None,
|
format: None,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
let out_params: HashMap<String, String> = vec![
|
||||||
|
("country".to_string(), "US".to_string()),
|
||||||
|
("hello".to_string(), "hello%20world".to_string()),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::replace_params_in_path(path, ¶ms, &prompt_target_params),
|
super::replace_params_in_path(path, ¶ms, &prompt_target_params),
|
||||||
Ok(
|
Ok((
|
||||||
"/cluster.open-cluster-management.io/v1/managedclusters/test1?hello=hello%20world&country=US"
|
"/cluster.open-cluster-management.io/v1/managedclusters/test1".to_string(),
|
||||||
.to_string()
|
"hello=hello%20world&country=US".to_string(),
|
||||||
)
|
out_params.clone()
|
||||||
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let out_params = HashMap::new();
|
||||||
let prompt_target_params = vec![];
|
let prompt_target_params = vec![];
|
||||||
|
|
||||||
let path = "/cluster.open-cluster-management.io/v1/managedclusters";
|
let path = "/cluster.open-cluster-management.io/v1/managedclusters";
|
||||||
let params = vec![].into_iter().collect();
|
let params = vec![].into_iter().collect();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::replace_params_in_path(path, ¶ms, &prompt_target_params),
|
super::replace_params_in_path(path, ¶ms, &prompt_target_params),
|
||||||
Ok("/cluster.open-cluster-management.io/v1/managedclusters".to_string())
|
Ok((
|
||||||
|
"/cluster.open-cluster-management.io/v1/managedclusters".to_string(),
|
||||||
|
"".to_string(),
|
||||||
|
out_params
|
||||||
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
let path = "/foo/{bar}/baz";
|
let path = "/foo/{bar}/baz";
|
||||||
|
|
@ -116,7 +140,7 @@ mod test {
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::replace_params_in_path(path, ¶ms, &prompt_target_params),
|
super::replace_params_in_path(path, ¶ms, &prompt_target_params),
|
||||||
Ok("/foo/qux/baz".to_string())
|
Ok(("/foo/qux/baz".to_string(), "".to_string(), HashMap::new()))
|
||||||
);
|
);
|
||||||
|
|
||||||
let path = "/foo/{bar}/baz/{qux}";
|
let path = "/foo/{bar}/baz/{qux}";
|
||||||
|
|
@ -128,7 +152,44 @@ mod test {
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::replace_params_in_path(path, ¶ms, &prompt_target_params),
|
super::replace_params_in_path(path, ¶ms, &prompt_target_params),
|
||||||
Ok("/foo/qux/baz/quux".to_string())
|
Ok((
|
||||||
|
"/foo/qux/baz/quux".to_string(),
|
||||||
|
"".to_string(),
|
||||||
|
HashMap::new()
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
let path = "/foo/{bar}/baz/{qux}?hello=world";
|
||||||
|
let params = vec![
|
||||||
|
("bar".to_string(), "qux".to_string()),
|
||||||
|
("qux".to_string(), "quux".to_string()),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect();
|
||||||
|
assert_eq!(
|
||||||
|
super::replace_params_in_path(path, ¶ms, &prompt_target_params),
|
||||||
|
Ok((
|
||||||
|
"/foo/qux/baz/quux".to_string(),
|
||||||
|
"hello=world".to_string(),
|
||||||
|
HashMap::new()
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
let path = "/foo/{bar}/baz/{qux}?hello={hello}";
|
||||||
|
let params = vec![
|
||||||
|
("bar".to_string(), "qux".to_string()),
|
||||||
|
("qux".to_string(), "quux".to_string()),
|
||||||
|
("hello".to_string(), "hello world".to_string()),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect();
|
||||||
|
assert_eq!(
|
||||||
|
super::replace_params_in_path(path, ¶ms, &prompt_target_params),
|
||||||
|
Ok((
|
||||||
|
"/foo/qux/baz/quux".to_string(),
|
||||||
|
"hello=hello%20world".to_string(),
|
||||||
|
HashMap::new()
|
||||||
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
let path = "/foo/{bar}/baz/{qux}";
|
let path = "/foo/{bar}/baz/{qux}";
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use common::api::open_ai::{
|
||||||
to_server_events, ArchState, ChatCompletionStreamResponse, ChatCompletionsRequest,
|
to_server_events, ArchState, ChatCompletionStreamResponse, ChatCompletionsRequest,
|
||||||
ChatCompletionsResponse, Message, ModelServerResponse, ToolCall,
|
ChatCompletionsResponse, Message, ModelServerResponse, ToolCall,
|
||||||
};
|
};
|
||||||
use common::configuration::{Overrides, PromptTarget, Tracing};
|
use common::configuration::{HttpMethod, Overrides, PromptTarget, Tracing};
|
||||||
use common::consts::{
|
use common::consts::{
|
||||||
ARCH_FC_MODEL_NAME, ARCH_FC_REQUEST_TIMEOUT_MS, ARCH_INTERNAL_CLUSTER_NAME,
|
ARCH_FC_MODEL_NAME, ARCH_FC_REQUEST_TIMEOUT_MS, ARCH_INTERNAL_CLUSTER_NAME,
|
||||||
ARCH_UPSTREAM_HOST_HEADER, ASSISTANT_ROLE, MESSAGES_KEY, REQUEST_ID_HEADER, SYSTEM_ROLE,
|
ARCH_UPSTREAM_HOST_HEADER, ASSISTANT_ROLE, MESSAGES_KEY, REQUEST_ID_HEADER, SYSTEM_ROLE,
|
||||||
|
|
@ -284,6 +284,7 @@ impl StreamContext {
|
||||||
let endpoint = prompt_target.endpoint.unwrap();
|
let endpoint = prompt_target.endpoint.unwrap();
|
||||||
let path: String = endpoint.path.unwrap_or(String::from("/"));
|
let path: String = endpoint.path.unwrap_or(String::from("/"));
|
||||||
let prompt_target_params = prompt_target.parameters.unwrap_or_default();
|
let prompt_target_params = prompt_target.parameters.unwrap_or_default();
|
||||||
|
let http_method = endpoint.method.unwrap_or_default();
|
||||||
|
|
||||||
// only add params that are of string, number and bool type
|
// only add params that are of string, number and bool type
|
||||||
let tool_url_params = tool_params
|
let tool_url_params = tool_params
|
||||||
|
|
@ -300,22 +301,58 @@ impl StreamContext {
|
||||||
})
|
})
|
||||||
.collect::<HashMap<String, String>>();
|
.collect::<HashMap<String, String>>();
|
||||||
|
|
||||||
let path = match common::path::replace_params_in_path(&path, &tool_url_params, &prompt_target_params) {
|
let (path_with_params, query_string, additional_params) =
|
||||||
Ok(path) => path,
|
match common::path::replace_params_in_path(
|
||||||
Err(e) => {
|
&path,
|
||||||
return self.send_server_error(
|
&tool_url_params,
|
||||||
ServerError::BadRequest {
|
&prompt_target_params,
|
||||||
why: format!("error replacing params in path: {}", e),
|
) {
|
||||||
},
|
Ok((path, query_string, additional_params)) => {
|
||||||
Some(StatusCode::BAD_REQUEST),
|
(path, query_string, additional_params)
|
||||||
);
|
}
|
||||||
|
Err(e) => {
|
||||||
|
return self.send_server_error(
|
||||||
|
ServerError::BadRequest {
|
||||||
|
why: format!("error replacing params in path: {}", e),
|
||||||
|
},
|
||||||
|
Some(StatusCode::BAD_REQUEST),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let (path, body) = match http_method {
|
||||||
|
HttpMethod::Get => {
|
||||||
|
let additional_params_query = additional_params
|
||||||
|
.iter()
|
||||||
|
.map(|(k, v)| format!("{}={}", k, v))
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("&");
|
||||||
|
let query_string = if query_string.is_empty() {
|
||||||
|
additional_params_query
|
||||||
|
} else {
|
||||||
|
format!("{}&{}", query_string, additional_params_query)
|
||||||
|
};
|
||||||
|
(format!("{}?{}", path_with_params, query_string), None)
|
||||||
|
}
|
||||||
|
HttpMethod::Post => {
|
||||||
|
let mut additional_params = additional_params;
|
||||||
|
if !query_string.is_empty() {
|
||||||
|
query_string.split("&").for_each(|param| {
|
||||||
|
let mut parts = param.split("=");
|
||||||
|
let key = parts.next().unwrap();
|
||||||
|
let value = parts.next().unwrap();
|
||||||
|
additional_params.insert(key.to_string(), value.to_string());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let body = serde_json::to_string(&additional_params).unwrap();
|
||||||
|
(path_with_params, Some(body))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let http_method = endpoint.method.unwrap_or_default().to_string();
|
let http_method_str = http_method.to_string();
|
||||||
let mut headers: HashMap<_, _> = [
|
let mut headers: HashMap<_, _> = [
|
||||||
(ARCH_UPSTREAM_HOST_HEADER, endpoint.name.as_str()),
|
(ARCH_UPSTREAM_HOST_HEADER, endpoint.name.as_str()),
|
||||||
(":method", &http_method),
|
(":method", &http_method_str),
|
||||||
(":path", &path),
|
(":path", &path),
|
||||||
(":authority", endpoint.name.as_str()),
|
(":authority", endpoint.name.as_str()),
|
||||||
("content-type", "application/json"),
|
("content-type", "application/json"),
|
||||||
|
|
@ -342,14 +379,14 @@ impl StreamContext {
|
||||||
ARCH_INTERNAL_CLUSTER_NAME,
|
ARCH_INTERNAL_CLUSTER_NAME,
|
||||||
&path,
|
&path,
|
||||||
headers.into_iter().collect(),
|
headers.into_iter().collect(),
|
||||||
None,
|
body.as_deref().map(|s| s.as_bytes()),
|
||||||
vec![],
|
vec![],
|
||||||
Duration::from_secs(5),
|
Duration::from_secs(5),
|
||||||
);
|
);
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"dispatching api call to developer endpoint: {}, path: {}",
|
"dispatching api call to developer endpoint: {}, path: {}, method: {}",
|
||||||
endpoint.name, path
|
endpoint.name, path, http_method_str
|
||||||
);
|
);
|
||||||
|
|
||||||
callout_context.upstream_cluster = Some(endpoint.name.to_owned());
|
callout_context.upstream_cluster = Some(endpoint.name.to_owned());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue