chatgpt/README.md

111 lines
3.3 KiB
Markdown
Raw Permalink Normal View History

2023-07-26 21:42:23 +00:00
# ChatGPT IRC Bot
ChatGPT IRC bot is a simple IRC bot written in Python. It connects to OpenAI endpoints to answer questions or generate images.
2023-03-20 12:02:37 +00:00
2023-07-26 21:42:23 +00:00
ChatGPT IRC Bot uses official bindings from OpenAI to interact with the API through HTTP requests:
2023-03-20 12:02:37 +00:00
https://platform.openai.com/docs/api-reference
### Prerequisities:
Create an account and obtain your API key: https://platform.openai.com/account/api-keys
Install python3 and the official Python bindings:
```
2023-03-25 16:52:59 +00:00
$ apt install python3 python3-pip (Debian/Ubuntu)
$ yum install python3 python3-pip (RedHat/CentOS)
2023-12-17 11:36:53 +00:00
$ pip3 install openai==0.28 pyshorteners
2023-03-21 19:41:46 +00:00
$ git clone https://github.com/knrd1/chatgpt.git
$ cd chatgpt
$ cp example-chat.conf chat.conf
2023-03-20 12:02:37 +00:00
```
### Configuration:
Edit chat.conf and change variables. Example configuration for IRCNet:
2023-10-02 18:21:58 +00:00
2024-02-22 14:41:48 +00:00
Variable "context" is optional: you can leave it blank or enter what you want the bot to know and how you want the bot to behave. This will work only with models connecting to endpoint /v1/chat/completions
2023-10-02 18:21:58 +00:00
2023-03-20 12:02:37 +00:00
```
[openai]
api_key = sk-XXXXXXXXXXXXXXX
2023-03-31 15:08:01 +00:00
[chatcompletion]
model = gpt-3.5-turbo
role = user
2023-10-02 18:21:58 +00:00
context = You are a helpful and friendly bot on IRC channel #linux.
2023-03-31 15:08:01 +00:00
temperature = 0.8
max_tokens = 1000
top_p = 1
frequency_penalty = 0
presence_penalty = 0
2023-03-31 17:49:44 +00:00
request_timeout = 60
2023-03-31 15:08:01 +00:00
[irc]
server = open.ircnet.net
2023-03-20 12:02:37 +00:00
port = 6667
2023-03-31 15:08:01 +00:00
ssl = false
2023-09-18 22:00:55 +00:00
channels = #linux,#github
nickname = MyBot
2023-03-31 15:08:01 +00:00
ident = mybot
realname = My Bot
password =
2023-03-20 12:37:57 +00:00
```
2023-03-20 12:02:37 +00:00
### Connecting bot to IRC server:
```
$ python3 chatgpt.py
```
2023-09-18 22:00:55 +00:00
Use screen to run bot in the background and keep it running even after you log out of your session:
```
$ screen python3 chatgpt.py
```
To detach from the screen session (leaving your ChatGPT IRC Bot running in the background), press Ctrl + A followed by d (for "detach").
If you need to reattach to the screen session later, use the following command:
```
screen -r
```
2023-03-20 12:02:37 +00:00
### Interaction:
2023-07-26 21:42:23 +00:00
ChatGPT IRC Bot will interact only if you mention its nickname:
2023-03-20 12:02:37 +00:00
```
10:31:12 <@knrd1> ChatGPT: hello, how are you?
10:31:14 < ChatGPT> Hi there, I'm doing well, thank you. How about you?
10:35:56 <@knrd1> ChatGPT: do you like IRC?
10:35:59 < ChatGPT> Yes, I like IRC. It is a great way to communicate with people from around the world.
2023-04-02 16:41:37 +00:00
```
2023-07-26 21:42:23 +00:00
If you set the model to "dalle", the ChatGPT IRC Bot will return a shortened URL to the generated image:
2023-04-02 16:41:37 +00:00
```
2023-09-18 22:00:55 +00:00
17:33:16 <@knrd1> ChatGPT: impressionist style painting: two horses dancing on the street
2023-04-02 16:41:37 +00:00
17:33:23 < ChatGPT> https://tinyurl.com/2hr5uf4w
2023-03-20 12:02:37 +00:00
```
### Model endpoint compatibility
2023-12-07 22:38:57 +00:00
ChatGPT IRC Bot can use three API endpoints:
2023-04-01 16:28:07 +00:00
Following models support endpoint /v1/chat/completions:
2023-09-18 22:00:55 +00:00
2024-02-22 14:41:48 +00:00
> gpt-4, gpt-4-turbo-preview, gpt-4-vision-preview, gpt-4-32k, gpt-3.5-turbo, gpt-3.5-turbo-16k, fine-tuned versions of gpt-3.5-turbo
2023-09-18 22:00:55 +00:00
2023-07-26 21:35:15 +00:00
Models that support /v1/completions (Legacy):
2023-09-18 22:00:55 +00:00
2024-02-22 14:41:48 +00:00
> gpt-3.5-turbo-instruct, babbage-002, davinci-002
2023-09-18 22:00:55 +00:00
2023-04-02 16:45:41 +00:00
Create an image using endpoint /v1/images/generations:
2023-09-18 22:00:55 +00:00
2024-02-22 14:41:48 +00:00
> dall-e-2, dall-e-3
2023-09-18 22:00:55 +00:00
More details about models: https://platform.openai.com/docs/models
2023-08-31 20:08:26 +00:00
### Docker
To build the Docker image, you can use the following command:
2023-09-18 22:00:55 +00:00
```
docker build -t my-chatgpt-app .
```
2023-08-31 20:08:26 +00:00
To run the Docker container, you can use the following command:
2023-09-18 22:00:55 +00:00
```
docker run -it my-chatgpt-app
```
2023-08-31 20:08:26 +00:00
To detach from a running Docker, press Ctrl + P. While holding down Ctrl, press Q.
2023-09-18 22:00:55 +00:00
To reattach to the container later, use the following command:
```
docker attach <container_id>
```