-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d64e0a4
commit 4b311fb
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# GPT-4 Chatbot | ||
|
||
A CLI chatbot using ChatGPT-4. | ||
|
||
<!-- <p align="center"> | ||
<img src="screenshot.png"> | ||
</p> --> | ||
|
||
## Setup | ||
|
||
You need to create a virtual env and install the packages listed in `requirements.txt`. You can then run Jupyter Notebooks in VS Code. | ||
|
||
Follow these steps: [How to Work with Python Virtual Environments, Jupyter Notebooks and VS Code](https://python.plainenglish.io/how-to-work-with-python-virtual-environments-jupyter-notebooks-and-vs-code-536fac3d93a1). | ||
|
||
## Usage | ||
|
||
To run the CLI: | ||
|
||
``` | ||
cd 02-gpt-4-chatbot | ||
python3 chatbot.py | ||
``` | ||
|
||
You can quit by typing `ctrl + C` (Mac) or `cmd + C` (Windows). | ||
|
||
## Features | ||
|
||
- writing the basic chatbot structure. | ||
- persisting messages accross requests. | ||
- adding optional personalities. | ||
- colorizing the chatbot output. | ||
|
||
Based on [Mastering OpenAI Python APIs: Unleash the Power of GPT4](https://www.udemy.com/course/mastering-openai/) by Colt Steele (2023). |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import openai | ||
from dotenv import dotenv_values | ||
|
||
config = dotenv_values(".env") | ||
openai.api_key = config["OPENAI_API_KEY"] | ||
|
||
while True: | ||
try: | ||
user_input = input("You: ") | ||
response = openai.ChatCompletion.create( | ||
model="gpt-3.5-turbo", | ||
messages=[{"role": "user", "content": user_input}], | ||
max_tokens=10, | ||
) | ||
print(response["choices"][0].message.content) | ||
except KeyboardInterrupt: | ||
print("Exiting...") | ||
break |
This file contains 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