Skip to content

Commit

Permalink
Add query_service.py script to easily query the proxy service instead…
Browse files Browse the repository at this point in the history
… of calling OpenAI directly. (#6798)
  • Loading branch information
tjprescott authored Aug 17, 2023
1 parent 4093c52 commit db9b7b1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/python-packages/apiview-gpt/query_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import dotenv
import json
import os
import pprint
import requests
import sys
import traceback

dotenv.load_dotenv()

SERVICE_URL = os.getenv("APIVIEW_GPT_SERVICE_URL")

if __name__ == "__main__":
try:
# TODO: Make this generic via command line arguments
input_filename = "test2.txt"
language = "python"
file_path = os.path.join(os.path.dirname(__file__), input_filename)
with open(file_path, "r") as f:
apiview_text = f.read()
request_body = {
"content": apiview_text,
}
response = requests.post(f"{SERVICE_URL}/{language}", json=request_body)
response.raise_for_status()
result = json.loads(response.json())
pprint.pprint(result)
sys.exit(0)
except Exception as err:
exc_type, exc_val, exc_tb = sys.exc_info()
traceback.print_exception(exc_type, exc_val, exc_tb, file=sys.stderr)
sys.exit(1)

0 comments on commit db9b7b1

Please sign in to comment.