Skip to content

Commit

Permalink
refactor(sdk): rename json and fn to be more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lerri-Cofannos committed Sep 8, 2023
1 parent 4b7de26 commit 3a26cb0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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 |", "")
Expand Down
12 changes: 12 additions & 0 deletions sdk-python/test/openai/update_format.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
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"
" ======================"
)
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
)
Expand Down
12 changes: 0 additions & 12 deletions sdk-python/test/openai_api/update_format.py

This file was deleted.

0 comments on commit 3a26cb0

Please sign in to comment.