-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_world.py
29 lines (23 loc) · 909 Bytes
/
hello_world.py
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
28
29
import openai
def open_file(filepath) :
with open(filepath, 'r', encoding='utf-8') as infile :
return infile.read()
openai.api_key=open_file('openaiapikey.txt')
def gpt3_completion(prompt, engine='text-davinci-003', temp=0.7, top_p = 1.0, tokens =400, freq_pen=0.0, pres_pen=0.0, stop=['<<END>>']) :
prompt = prompt.encode(encoding='ASCII', errors='ignore').decode()
response = openai.Completion.create(
#engine=engine,
engine='text-ada-001',
prompt=prompt,
temperature=temp,
max_tokens=tokens,
top_p=top_p,
frequency_penalty=freq_pen,
presence_penalty=pres_pen,
stop=stop)
text = response['choices'][0]['text'].strip()
return text
if __name__ == '__main__' :
prompt = 'When will South Korea and North Korea be unified?:'
response = gpt3_completion(prompt)
print(response)