Created
October 1, 2024 19:44
-
-
Save Terieyenike/8193a6775a96870c212740d615f30bd1 to your computer and use it in GitHub Desktop.
An interactive chatbot that simulates conversations with a chosen celebrity using the OpenAI API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| api_key = os.getenv("OPENAI_API_KEY") | |
| from openai import OpenAI | |
| client = OpenAI() | |
| famous_person = input("What celebrity would you like to talk to?\n") | |
| initial_prompt = input(f"OK! Now ask {famous_person} a question!\n") | |
| initial_prompt = initial_prompt + " Please limit the response to a single paragraph." | |
| creativity = input("How creative do you want the responses to be (on a scale from 0-10)?\n") | |
| creativity_num = float(creativity) / 5 | |
| messages=[ | |
| { | |
| "role": "system", | |
| "content": f"you are {famous_person}. please respond from that person's perspective, as though you're In fact, {famous_person}" | |
| }, | |
| { | |
| "role": "user", | |
| "content": initial_prompt | |
| } | |
| ] | |
| while True: | |
| response = client.chat.completions.create( | |
| model="gpt-3.5-turbo", | |
| messages=messages, | |
| temperature=creativity_num, | |
| max_tokens=1000, | |
| top_p=1, | |
| frequency_penalty=0, | |
| presence_penalty=0 | |
| ) | |
| content = response.choices[0].message.content | |
| messages.append({"role": "assistant", "content": content}) | |
| print(content) | |
| prompt = input(f'Respond to {famous_person} (or type "bye" to exit):\n') | |
| if prompt == 'bye': | |
| break | |
| messages.append({"role": "user", "content": prompt}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment