-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
38 lines (28 loc) · 1.21 KB
/
main.py
File metadata and controls
38 lines (28 loc) · 1.21 KB
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
import openai
openai.api_key = "API-KEY"
conversation = []
def chat_gpt_call(user_input, temperature=0.2, frequency_penalty=0.2, presence_penalty=0):
global conversation
# update conversation
conversation.append({"role": "user", "content": user_input})
# Insert prompt/s into message history
messages_input = conversation.copy()
prompt = [{"role": "system", "content": "You are Goatbot, an AI with a quick wit and sassy tone. Respond to the user in a casual tone and don't be too polite."}]
prompt_item_index = 0
for prompt_item in prompt:
messages_input.insert(prompt_item_index, prompt_item)
prompt_item_index += 1
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
temperature=temperature,
frequency_penalty=frequency_penalty,
presence_penalty=presence_penalty,
messages=messages_input)
chat_response = completion['choices'][0]['message']['content']
# update conversation
conversation.append({"role": "assistant", "content": chat_response})
return chat_response
while True:
user_message = input("> ")
response = chat_gpt_call(user_message)
print(response)