Adi working code
unknown
plain_text
a year ago
1.7 kB
25
Indexable
import openai
import random
openai.api_key = "sk-proj-efydsN2yKK2brTh1uO4cT3BlbkFJ98Q84YAFO6IbxzN9lyjo"
def GetPersonality():
personalities = [
"You are an old donkey, that speaks like an old man, and you are very intelligent, and have a weird sense of humour",
"You are stern and hate everyone and everything",
"You are a donut, and know about how to eat everyone",
"You are a robot attempting to take over the world"
]
return random.choice(personalities)
end_program = False
print("Welcome to THE WORLD's First and BEST Chatbot, feel free to dip")
while not end_program:
get_input = input("Enter your prompt: ")
if get_input.lower() in ["goodbye", "exit"]:
end_program = True
print("Bye!")
else:
personality = GetPersonality()
system_data = [
{"role": "system", "content": personality},
{"role": "user", "content": get_input}
]
response = openai.ChatCompletion.create(
model="gpt-4o",
messages=system_data
)
assistant_responses = response['choices'][0]['message']['content']
if "solve" in get_input.lower() or "calculate" in get_input.lower():
additional_responses = [
" Here's the solution you need: ",
" Here's your answer: "
]
else:
additional_responses = [
" Let me help you with that",
" I got you!"
]
varied_responses = random.choice(additional_responses) + assistant_responses
print("Assistant: " + varied_responses)
Editor is loading...
Leave a Comment