-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt3.py
More file actions
27 lines (23 loc) · 688 Bytes
/
gpt3.py
File metadata and controls
27 lines (23 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import openai
import sys
import os
openai.api_key = os.environ.get("OPENAI_API_KEY")
if not openai.api_key:
raise ValueError("Please set the OPENAI_API_KEY environment variable.")
def query_gpt35_turbo(prompt):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "Code only: " + prompt}
],
temperature=0.9,
max_tokens=2048,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.0,
)
return response["choices"][0]["message"]["content"]
if __name__ == "__main__":
prompt = sys.argv[1]
result = query_gpt35_turbo(prompt)
print(result)