Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APIView GPT] Add query_service.py script #6798

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)