Skip to content

Commit

Permalink
feat: add chatbot structure
Browse files Browse the repository at this point in the history
  • Loading branch information
solygambas committed Apr 30, 2023
1 parent d64e0a4 commit 4b311fb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
33 changes: 33 additions & 0 deletions 02-gpt-4-chatbot/README.md
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).
18 changes: 18 additions & 0 deletions 02-gpt-4-chatbot/chatbot.py
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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,19 @@ Follow these steps: [How to Work with Python Virtual Environments, Jupyter Noteb

[Check the playground](playground/06-chat-api-gpt-4.ipynb)

### GPT-4 Chatbot

- writing the basic chatbot structure.
- persisting messages accross requests.
- adding optional personalities.
- colorizing the chatbot output.

[Check the 02-gpt-4-chatbot folder](02-gpt-4-chatbot)

<!-- <p align="center">
<a href="02-gpt-4-chatbot">
<img src="02-gpt-4-chatbot/screenshot.png">
</a>
</p> -->

Based on [Mastering OpenAI Python APIs: Unleash the Power of GPT4](https://www.udemy.com/course/mastering-openai/) by Colt Steele (2023).

0 comments on commit 4b311fb

Please sign in to comment.