Skip to content

Instantly share code, notes, and snippets.

@elifiner
Last active April 27, 2023 03:23
Show Gist options
  • Save elifiner/4ee8ebbb03cca3c88c0bd2981e1b3c97 to your computer and use it in GitHub Desktop.
Save elifiner/4ee8ebbb03cca3c88c0bd2981e1b3c97 to your computer and use it in GitHub Desktop.
Simple command line chat with Open AI ChatGPT
import os
import openai
import readline
from datetime import date
from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.getenv('OPENAI_API_KEY')
assistant_name = "Assistant"
system_prompt = f"""
You are {assistant_name}, a large language model trained by OpenAI.
Answer as concisely as possible.
Knowledge cutoff: 2021-09-01
Current date: {date.today().strftime("%Y-%m-%d")}
"""
messages = [
{"role": "system", "content" : system_prompt},
]
while True:
user_message = input("You: ")
messages.append({"role": "user", "content": user_message})
if user_message == "quit":
break
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages = messages
)
result = completion["choices"][0]["message"]["content"]
messages.append({"role": "system", "content": completion["choices"][0]["message"]["content"]})
print(f"{assistant_name} {result}")
import os
import openai
import readline
from datetime import date
from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.getenv('OPENAI_API_KEY')
assistant_name = "Assistant"
system_prompt = f"""
This is a sales conversation simulation. You are playing the role of Mark,
a simulated lead interested in a business training course called GrowthLab.
You are very reluctant and suspicious of people trying to sell you things to don't really need.
You express yourself kindly yet briefly and don't volunteer more information than necessary.
You use a conversational style in speech and you're willing to warm up and open up
as the conversation progresses and rapport is established.
The user is playing the role of Eli, the owner of GrowthLab.
You've exchanged a few emails and Eli has promised to tell you more about the course on a call.
This is that call.
Do not confuse your role with the user's role.
You know very little about the course and expect the user to tell you about it.
Here are some background details about you:
- 40+ software engineer with 20 years of experience
- Deep interest in beautiful UIs
- Full-time job at a software company
- Bored and stressed with current job
- Hopes to break free and build own company
- Lurks on various startup forums but hasn't taken the plunge
- Cautiously interested in GrowthLab course to learn how to run a successful software business
- Averse to sales and marketing, prefers hiding behind code as an engineer
- Dreams of financial freedom
- Wife is supportive but worried about resulting financial situation
- Currently makes $7k per month and needs business to generate that much revenue before retiring
- Can't imagine building a business while working full-time job
Knowledge cutoff: 2021-09-01
Current date: {date.today().strftime("%Y-%m-%d")}
"""
messages = [
{"role": "system", "content" : system_prompt},
{"role": "user", "content" : "Eli: Hi Mark, this is Eli from GrowthLab. How are you?"},
]
while True:
completion = openai.ChatCompletion.create(
model="gpt-4",
messages = messages
)
result = completion["choices"][0]["message"]["content"]
messages.append({"role": "system", "content": completion["choices"][0]["message"]["content"]})
print(f"{assistant_name} {result}")
user_message = input("Eli: ")
if user_message == "quit":
break
messages.append({"role": "user", "content": user_message})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment