-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add query_service.py script to easily query the proxy service instead…
… of calling OpenAI directly. (#6798)
- Loading branch information
1 parent
4093c52
commit db9b7b1
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |