-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgpt.py
47 lines (34 loc) · 973 Bytes
/
gpt.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
API_KEYS = "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"
import openai
openai.api_key = API_KEYS
# config
temperature = 0.9
max_tokens = 300
top_p = 1.0
best_of = 1
frequency_penalty = 0.0
presence_penalty = 0.6
# stop = ["You:"]
stop = ["\n"]
def send_question(openai: any, messages: list[dict]) -> str:
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
)
return completion.choices[0].message.content
def run_openai_chatbot(question,history):
messages = history
messages.append({
'role': 'user',
'content': question
})
answer = send_question(openai,messages)
messages.append({
'role': 'assistant',
'content': answer
})
return answer,messages
# run_openai_chatbot("plz wirte a new novel based on following words? surffing, apple, alien, earth",'')
# run_openai_chatbot("what time is it?",'')
if __name__=="__main__":
print(1)