diff --git a/tests/configs/assistants/single_provider/single_provider.json b/tests/configs/assistants/single_provider/single_provider.json index 9471258a..fa5b52b2 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 52281ce7..67b6de23 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 9471258a..fa5b52b2 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 9471258a..fa5b52b2 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 52281ce7..67b6de23 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 9471258a..fa5b52b2 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 a941fddb..699493da 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 d4a1ca94..a44d7014 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 3a6d1c70..b6cf6900 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 28bfae9d..4dd9a60b 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 08dbed81..ee969bff 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 155422e4..0c94095a 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 5adda115..13af31eb 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 155422e4..0c94095a 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 0c6b973c..b64186be 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 38c4e5cb..ee6683ea 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 64fa75b2..0facd4de 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 91b2d8bc..266d3705 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 dc5a8453..87ae0bf3 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 26a6f0d8..7d288147 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 d25999d1..882205cc 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 26a6f0d8..7d288147 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 e0553dc5..8df7df17 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 193057b4..8233c159 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 9471258a..fa5b52b2 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 52281ce7..67b6de23 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 9471258a..fa5b52b2 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 9471258a..fa5b52b2 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 52281ce7..67b6de23 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 9471258a..fa5b52b2 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 9471258a..fa5b52b2 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 52281ce7..67b6de23 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 9471258a..fa5b52b2 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 00000000..977877c2 --- /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 "Virutal Key replacement completed."