diff --git a/sdk-python/test/openai_api/reference_format.json b/sdk-python/test/openai/chatcompletion_ref.json similarity index 100% rename from sdk-python/test/openai_api/reference_format.json rename to sdk-python/test/openai/chatcompletion_ref.json diff --git a/sdk-python/test/openai_api/format_finder.py b/sdk-python/test/openai/format_finder.py similarity index 89% rename from sdk-python/test/openai_api/format_finder.py rename to sdk-python/test/openai/format_finder.py index 74723310..6e032a30 100644 --- a/sdk-python/test/openai_api/format_finder.py +++ b/sdk-python/test/openai/format_finder.py @@ -1,7 +1,7 @@ import os -def extract_reference(full_data: str) -> str: +def extract_chatcompletion_ref(full_data: str) -> str: start_index = full_data.find("chat_completion_example |") result = full_data[start_index:] result = result.replace("chat_completion_example |", "") diff --git a/sdk-python/test/openai/update_format.py b/sdk-python/test/openai/update_format.py new file mode 100644 index 00000000..ba19d0e9 --- /dev/null +++ b/sdk-python/test/openai/update_format.py @@ -0,0 +1,12 @@ +import json +import os + +from format_finder import extract_chatcompletion_ref, fetch_api_format + +result = fetch_api_format() +result = extract_chatcompletion_ref(result) +print("Updating the OpenAI API reference format to:\n", result) + +reference_path = os.path.abspath("./test/openai_api/chatcompletion_ref.json") +with open(reference_path, "w") as f: + json.dump(result, f) diff --git a/sdk-python/test/openai_api/validate_format.py b/sdk-python/test/openai/validate_format.py similarity index 54% rename from sdk-python/test/openai_api/validate_format.py rename to sdk-python/test/openai/validate_format.py index aad8f2c4..c926ffde 100644 --- a/sdk-python/test/openai_api/validate_format.py +++ b/sdk-python/test/openai/validate_format.py @@ -1,7 +1,7 @@ import json import os -from format_finder import extract_reference, fetch_api_format +from format_finder import extract_chatcompletion_ref, fetch_api_format print( "====================== Start validating the OpenAI API reference format" @@ -9,17 +9,19 @@ ) result = fetch_api_format() -reference_path = os.path.abspath("./test/openai_api/reference_format.json") +reference_path = os.path.abspath("./test/openai/chatcompletion_ref.json") with open(reference_path, "r") as f: reference = json.load(f) if result.find(reference) != -1: print("The OpenAI API format is up-to-date.") else: message = ( - "The OpenAI API format has changed. Run " - + "'poetry run python test/openai_api/update_format.py' " - + "to update the test.\nCurrent format:" - + extract_reference(result) + "The OpenAI API format has changed. " + + "Please update the extraction of data in openai_listener.py " + + "and the reference format in chatcompletion.json by running " + + "'poetry run python test/openai_api/update_format.py'." + + "\nCurrent format:" + + extract_chatcompletion_ref(result) + "\nPrevious format:" + reference ) diff --git a/sdk-python/test/openai_api/update_format.py b/sdk-python/test/openai_api/update_format.py deleted file mode 100644 index 79ef5cbc..00000000 --- a/sdk-python/test/openai_api/update_format.py +++ /dev/null @@ -1,12 +0,0 @@ -import json -import os - -from format_finder import extract_reference, fetch_api_format - -result = fetch_api_format() -result = extract_reference(result) -print("Updating the OpenAI API reference format to:\n", result) - -reference_path = os.path.abspath("./test/openai_api/reference_format.json") -with open(reference_path, "w") as f: - json.dump(result, f)