From 5cbf0231b1e63392a9d5f0c6076fa619e0511df3 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Fri, 7 Jun 2024 19:59:36 +0530 Subject: [PATCH 1/2] feat: script to replace virtual keys for testing --- .../single_provider/single_provider.json | 2 +- .../single_provider_with_vk_retry_cache.json | 2 +- .../single_with_basic_config.json | 2 +- .../single_provider/single_provider.json | 2 +- .../single_provider_with_vk_retry_cache.json | 2 +- .../single_with_basic_config.json | 2 +- .../anthropic_n_openai.json | 2 +- .../anyscale_n_openai.json | 2 +- .../azure_n_openai.json | 2 +- .../cohere_n_openai.json | 2 +- .../loadbalance_with_two_apikeys.json | 2 +- .../single_provider/single_provider.json | 2 +- .../single_provider_with_vk_retry_cache.json | 2 +- .../single_with_basic_config.json | 2 +- .../anthropic_n_openai.json | 2 +- .../anyscale_n_openai.json | 2 +- .../azure_n_openai.json | 2 +- .../cohere_n_openai.json | 2 +- .../loadbalance_with_two_apikeys.json | 2 +- .../single_provider/single_provider.json | 2 +- .../single_provider_with_vk_retry_cache.json | 2 +- .../single_with_basic_config.json | 2 +- .../stability_n_openai.json | 2 +- .../loadbalance_with_two_apikeys.json | 2 +- .../single_provider/single_provider.json | 2 +- .../single_provider_with_vk_retry_cache.json | 2 +- .../single_with_basic_config.json | 2 +- .../single_provider/single_provider.json | 2 +- .../single_provider_with_vk_retry_cache.json | 2 +- .../single_with_basic_config.json | 2 +- .../single_provider/single_provider.json | 2 +- .../single_provider_with_vk_retry_cache.json | 2 +- .../single_with_basic_config.json | 2 +- tests/virtual_keys_replacement.sh | 67 +++++++++++++++++++ 34 files changed, 100 insertions(+), 33 deletions(-) create mode 100755 tests/virtual_keys_replacement.sh diff --git a/tests/configs/assistants/single_provider/single_provider.json b/tests/configs/assistants/single_provider/single_provider.json index 9471258..fa5b52b 100644 --- a/tests/configs/assistants/single_provider/single_provider.json +++ b/tests/configs/assistants/single_provider/single_provider.json @@ -1,3 +1,3 @@ { "virtual_key": "openai-virtual-key" -} \ No newline at end of file +} diff --git a/tests/configs/assistants/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json b/tests/configs/assistants/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json index 52281ce..67b6de2 100644 --- a/tests/configs/assistants/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json +++ b/tests/configs/assistants/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json @@ -10,4 +10,4 @@ 429 ] } -} \ No newline at end of file +} diff --git a/tests/configs/assistants/single_with_basic_config/single_with_basic_config.json b/tests/configs/assistants/single_with_basic_config/single_with_basic_config.json index 9471258..fa5b52b 100644 --- a/tests/configs/assistants/single_with_basic_config/single_with_basic_config.json +++ b/tests/configs/assistants/single_with_basic_config/single_with_basic_config.json @@ -1,3 +1,3 @@ { "virtual_key": "openai-virtual-key" -} \ No newline at end of file +} diff --git a/tests/configs/audio/single_provider/single_provider.json b/tests/configs/audio/single_provider/single_provider.json index 9471258..fa5b52b 100644 --- a/tests/configs/audio/single_provider/single_provider.json +++ b/tests/configs/audio/single_provider/single_provider.json @@ -1,3 +1,3 @@ { "virtual_key": "openai-virtual-key" -} \ No newline at end of file +} diff --git a/tests/configs/audio/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json b/tests/configs/audio/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json index 52281ce..67b6de2 100644 --- a/tests/configs/audio/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json +++ b/tests/configs/audio/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json @@ -10,4 +10,4 @@ 429 ] } -} \ No newline at end of file +} diff --git a/tests/configs/audio/single_with_basic_config/single_with_basic_config.json b/tests/configs/audio/single_with_basic_config/single_with_basic_config.json index 9471258..fa5b52b 100644 --- a/tests/configs/audio/single_with_basic_config/single_with_basic_config.json +++ b/tests/configs/audio/single_with_basic_config/single_with_basic_config.json @@ -1,3 +1,3 @@ { "virtual_key": "openai-virtual-key" -} \ No newline at end of file +} diff --git a/tests/configs/chat_completions/loadbalance_and_fallback/anthropic_n_openai.json b/tests/configs/chat_completions/loadbalance_and_fallback/anthropic_n_openai.json index a941fdd..699493d 100644 --- a/tests/configs/chat_completions/loadbalance_and_fallback/anthropic_n_openai.json +++ b/tests/configs/chat_completions/loadbalance_and_fallback/anthropic_n_openai.json @@ -33,4 +33,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/configs/chat_completions/loadbalance_and_fallback/anyscale_n_openai.json b/tests/configs/chat_completions/loadbalance_and_fallback/anyscale_n_openai.json index d4a1ca9..a44d701 100644 --- a/tests/configs/chat_completions/loadbalance_and_fallback/anyscale_n_openai.json +++ b/tests/configs/chat_completions/loadbalance_and_fallback/anyscale_n_openai.json @@ -33,4 +33,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/configs/chat_completions/loadbalance_and_fallback/azure_n_openai.json b/tests/configs/chat_completions/loadbalance_and_fallback/azure_n_openai.json index 3a6d1c7..b6cf690 100644 --- a/tests/configs/chat_completions/loadbalance_and_fallback/azure_n_openai.json +++ b/tests/configs/chat_completions/loadbalance_and_fallback/azure_n_openai.json @@ -33,4 +33,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/configs/chat_completions/loadbalance_and_fallback/cohere_n_openai.json b/tests/configs/chat_completions/loadbalance_and_fallback/cohere_n_openai.json index 28bfae9..4dd9a60 100644 --- a/tests/configs/chat_completions/loadbalance_and_fallback/cohere_n_openai.json +++ b/tests/configs/chat_completions/loadbalance_and_fallback/cohere_n_openai.json @@ -33,4 +33,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/configs/chat_completions/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json b/tests/configs/chat_completions/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json index 08dbed8..ee969bf 100644 --- a/tests/configs/chat_completions/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json +++ b/tests/configs/chat_completions/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json @@ -16,4 +16,4 @@ } } ] -} \ No newline at end of file +} diff --git a/tests/configs/chat_completions/single_provider/single_provider.json b/tests/configs/chat_completions/single_provider/single_provider.json index 155422e..0c94095 100644 --- a/tests/configs/chat_completions/single_provider/single_provider.json +++ b/tests/configs/chat_completions/single_provider/single_provider.json @@ -3,4 +3,4 @@ "override_params": { "model": "gpt-3.5-turbo" } -} \ No newline at end of file +} diff --git a/tests/configs/chat_completions/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json b/tests/configs/chat_completions/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json index 5adda11..13af31e 100644 --- a/tests/configs/chat_completions/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json +++ b/tests/configs/chat_completions/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json @@ -13,4 +13,4 @@ 429 ] } -} \ No newline at end of file +} diff --git a/tests/configs/chat_completions/single_with_basic_config/single_with_basic_config.json b/tests/configs/chat_completions/single_with_basic_config/single_with_basic_config.json index 155422e..0c94095 100644 --- a/tests/configs/chat_completions/single_with_basic_config/single_with_basic_config.json +++ b/tests/configs/chat_completions/single_with_basic_config/single_with_basic_config.json @@ -3,4 +3,4 @@ "override_params": { "model": "gpt-3.5-turbo" } -} \ No newline at end of file +} diff --git a/tests/configs/completions/loadbalance_and_fallback/anthropic_n_openai.json b/tests/configs/completions/loadbalance_and_fallback/anthropic_n_openai.json index 0c6b973..b64186b 100644 --- a/tests/configs/completions/loadbalance_and_fallback/anthropic_n_openai.json +++ b/tests/configs/completions/loadbalance_and_fallback/anthropic_n_openai.json @@ -33,4 +33,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/configs/completions/loadbalance_and_fallback/anyscale_n_openai.json b/tests/configs/completions/loadbalance_and_fallback/anyscale_n_openai.json index 38c4e5c..ee6683e 100644 --- a/tests/configs/completions/loadbalance_and_fallback/anyscale_n_openai.json +++ b/tests/configs/completions/loadbalance_and_fallback/anyscale_n_openai.json @@ -33,4 +33,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/configs/completions/loadbalance_and_fallback/azure_n_openai.json b/tests/configs/completions/loadbalance_and_fallback/azure_n_openai.json index 64fa75b..0facd4d 100644 --- a/tests/configs/completions/loadbalance_and_fallback/azure_n_openai.json +++ b/tests/configs/completions/loadbalance_and_fallback/azure_n_openai.json @@ -33,4 +33,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/configs/completions/loadbalance_and_fallback/cohere_n_openai.json b/tests/configs/completions/loadbalance_and_fallback/cohere_n_openai.json index 91b2d8b..266d370 100644 --- a/tests/configs/completions/loadbalance_and_fallback/cohere_n_openai.json +++ b/tests/configs/completions/loadbalance_and_fallback/cohere_n_openai.json @@ -33,4 +33,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/configs/completions/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json b/tests/configs/completions/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json index dc5a845..87ae0bf 100644 --- a/tests/configs/completions/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json +++ b/tests/configs/completions/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json @@ -16,4 +16,4 @@ } } ] -} \ No newline at end of file +} diff --git a/tests/configs/completions/single_provider/single_provider.json b/tests/configs/completions/single_provider/single_provider.json index 26a6f0d..7d28814 100644 --- a/tests/configs/completions/single_provider/single_provider.json +++ b/tests/configs/completions/single_provider/single_provider.json @@ -3,4 +3,4 @@ "override_params": { "model": "gpt-3.5-turbo-instruct" } -} \ No newline at end of file +} diff --git a/tests/configs/completions/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json b/tests/configs/completions/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json index d25999d..882205c 100644 --- a/tests/configs/completions/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json +++ b/tests/configs/completions/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json @@ -13,4 +13,4 @@ 429 ] } -} \ No newline at end of file +} diff --git a/tests/configs/completions/single_with_basic_config/single_with_basic_config.json b/tests/configs/completions/single_with_basic_config/single_with_basic_config.json index 26a6f0d..7d28814 100644 --- a/tests/configs/completions/single_with_basic_config/single_with_basic_config.json +++ b/tests/configs/completions/single_with_basic_config/single_with_basic_config.json @@ -3,4 +3,4 @@ "override_params": { "model": "gpt-3.5-turbo-instruct" } -} \ No newline at end of file +} diff --git a/tests/configs/images/loadbalance_and_fallback/stability_n_openai.json b/tests/configs/images/loadbalance_and_fallback/stability_n_openai.json index e0553dc..8df7df1 100644 --- a/tests/configs/images/loadbalance_and_fallback/stability_n_openai.json +++ b/tests/configs/images/loadbalance_and_fallback/stability_n_openai.json @@ -33,4 +33,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json b/tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json index 193057b..8233c15 100644 --- a/tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json +++ b/tests/configs/images/loadbalance_with_two_apikeys/loadbalance_with_two_apikeys.json @@ -16,4 +16,4 @@ } } ] -} \ No newline at end of file +} diff --git a/tests/configs/images/single_provider/single_provider.json b/tests/configs/images/single_provider/single_provider.json index 9471258..fa5b52b 100644 --- a/tests/configs/images/single_provider/single_provider.json +++ b/tests/configs/images/single_provider/single_provider.json @@ -1,3 +1,3 @@ { "virtual_key": "openai-virtual-key" -} \ No newline at end of file +} diff --git a/tests/configs/images/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json b/tests/configs/images/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json index 52281ce..67b6de2 100644 --- a/tests/configs/images/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json +++ b/tests/configs/images/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json @@ -10,4 +10,4 @@ 429 ] } -} \ No newline at end of file +} diff --git a/tests/configs/images/single_with_basic_config/single_with_basic_config.json b/tests/configs/images/single_with_basic_config/single_with_basic_config.json index 9471258..fa5b52b 100644 --- a/tests/configs/images/single_with_basic_config/single_with_basic_config.json +++ b/tests/configs/images/single_with_basic_config/single_with_basic_config.json @@ -1,3 +1,3 @@ { "virtual_key": "openai-virtual-key" -} \ No newline at end of file +} diff --git a/tests/configs/moderations/single_provider/single_provider.json b/tests/configs/moderations/single_provider/single_provider.json index 9471258..fa5b52b 100644 --- a/tests/configs/moderations/single_provider/single_provider.json +++ b/tests/configs/moderations/single_provider/single_provider.json @@ -1,3 +1,3 @@ { "virtual_key": "openai-virtual-key" -} \ No newline at end of file +} diff --git a/tests/configs/moderations/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json b/tests/configs/moderations/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json index 52281ce..67b6de2 100644 --- a/tests/configs/moderations/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json +++ b/tests/configs/moderations/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json @@ -10,4 +10,4 @@ 429 ] } -} \ No newline at end of file +} diff --git a/tests/configs/moderations/single_with_basic_config/single_with_basic_config.json b/tests/configs/moderations/single_with_basic_config/single_with_basic_config.json index 9471258..fa5b52b 100644 --- a/tests/configs/moderations/single_with_basic_config/single_with_basic_config.json +++ b/tests/configs/moderations/single_with_basic_config/single_with_basic_config.json @@ -1,3 +1,3 @@ { "virtual_key": "openai-virtual-key" -} \ No newline at end of file +} diff --git a/tests/configs/threads/single_provider/single_provider.json b/tests/configs/threads/single_provider/single_provider.json index 9471258..fa5b52b 100644 --- a/tests/configs/threads/single_provider/single_provider.json +++ b/tests/configs/threads/single_provider/single_provider.json @@ -1,3 +1,3 @@ { "virtual_key": "openai-virtual-key" -} \ No newline at end of file +} diff --git a/tests/configs/threads/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json b/tests/configs/threads/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json index 52281ce..67b6de2 100644 --- a/tests/configs/threads/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json +++ b/tests/configs/threads/single_provider_with_vk_retry_cache/single_provider_with_vk_retry_cache.json @@ -10,4 +10,4 @@ 429 ] } -} \ No newline at end of file +} diff --git a/tests/configs/threads/single_with_basic_config/single_with_basic_config.json b/tests/configs/threads/single_with_basic_config/single_with_basic_config.json index 9471258..fa5b52b 100644 --- a/tests/configs/threads/single_with_basic_config/single_with_basic_config.json +++ b/tests/configs/threads/single_with_basic_config/single_with_basic_config.json @@ -1,3 +1,3 @@ { "virtual_key": "openai-virtual-key" -} \ No newline at end of file +} diff --git a/tests/virtual_keys_replacement.sh b/tests/virtual_keys_replacement.sh new file mode 100755 index 0000000..c7d0a85 --- /dev/null +++ b/tests/virtual_keys_replacement.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# Function to replace words in a file using the provided mapping +replace_words_in_file() { + local file_path=$1 + local virtual_keys=("${!2}") + local virtual_keys_values=("${!3}") + + # Read the file content + local file_content=$(< "$file_path") + + # Iterate over the mapping and replace words + for (( i=0; i<${#virtual_keys[@]}; i++ )); do + file_content=$(echo "$file_content" | sed "s/${virtual_keys[$i]}/${virtual_keys_values[$i]}/g") + done + + # Write the modified content back to the file + echo "$file_content" > "$file_path" +} + +# Function to process files in a directory +process_files_in_directory() { + local directory=$1 + local virtual_keys=("${!2}") + local virtual_keys_values=("${!3}") + + # Find all .json files in the directory and its subdirectories + find "$directory" -type f -name "*.json" | while read -r file; do + replace_words_in_file "$file" virtual_keys virtual_keys_values + echo "Processed file: $file" + done +} + +# Main script + +# Check if jq is installed +if ! command -v jq &> /dev/null; then + echo "jq could not be found. Please install jq to use this script." + exit 1 +fi + +# Hardcoded directory path +directory="tests/configs" + +# Hardcoded mapping of words to be replaced and their replacements +virtual_keys=("openai-virtual-key" "anyscale-virtual-key" "azure-virtual-key" "cohere-virtual-key" "anthropic-virtual-key" "stability-virtual-key") +virtual_keys_values=("openai_value" "anyscale_value" "azure_value" "cohere_value" "anthropic_value" "stability_value") + + +# Check if the directory exists +if [[ ! -d "$directory" ]]; then + echo "Directory does not exist. Please provide a valid directory path." + exit 1 +fi + +# Check for --undo parameter +if [[ "$1" == "--undo" ]]; then + echo "Undoing word replacement..." + # Swap virtual_keys and virtual_keys_values for undo + temp_words=("${virtual_keys[@]}") + virtual_keys=("${virtual_keys_values[@]}") + virtual_keys_values=("${temp_words[@]}") +fi + + +process_files_in_directory "$directory" virtual_keys virtual_keys_values +echo "Word replacement completed." From b823810feb1cbd736370e1e220111424de2fc05e Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Sat, 8 Jun 2024 12:30:13 +0530 Subject: [PATCH 2/2] fix: typo --- tests/virtual_keys_replacement.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/virtual_keys_replacement.sh b/tests/virtual_keys_replacement.sh index c7d0a85..977877c 100755 --- a/tests/virtual_keys_replacement.sh +++ b/tests/virtual_keys_replacement.sh @@ -64,4 +64,4 @@ fi process_files_in_directory "$directory" virtual_keys virtual_keys_values -echo "Word replacement completed." +echo "Virutal Key replacement completed."