From 8421f691816c61d8cb2f2147d6c6aacfd42c890d Mon Sep 17 00:00:00 2001 From: Martin Bielik Date: Fri, 3 Mar 2023 18:09:21 +0100 Subject: using openai api directly --- py/complete.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 py/complete.py (limited to 'py/complete.py') diff --git a/py/complete.py b/py/complete.py new file mode 100644 index 0000000..ba460c4 --- /dev/null +++ b/py/complete.py @@ -0,0 +1,26 @@ +import sys +import os +import openai + +config_file_path = os.path.join(os.path.expanduser("~"), ".config/openai.token") + +api_key = os.getenv("OPENAI_API_KEY") + +try: + with open(config_file_path, 'r') as file: + api_key = file.read() +except Exception: + pass + +openai.api_key = api_key.strip() + +prompt = "".join(sys.stdin.readlines()) + +completion = openai.Completion.create( + model="text-davinci-003", + prompt=prompt, + max_tokens=1000, + temperature=0.1 +) + +print(completion.choices[0].text) -- cgit v1.2.3