Skip to content

princewang1994/chatgpt-telegram-bot-cli

Repository files navigation

ChatGPT Telegram-Bot/CLI Tool

This project uses the OpenAI API to enable conversational capabilities both in the command console and through a Telegram bot. The ChatGPT API is used to process natural language, understand the intent of the user and generate appropriate responses. (This introduction is almost written by ChatGPT)

Usage

To use this tool, please follow these instructions:

  1. Clone the repository to your local machine.
git clone https://github.com/princewang1994/chatgpt-telegram-bot-cli.git
cd chatgpt-telegram-bot-cli/
  1. Install the requirements using pip.
pip install -r requirements.txt
  1. Write your own config
cp configs/example.yaml configs/my.yaml

here is an example:

openai:
  api_key: "YOUR_OPENAI_API_KEY"

save:
  root: "./session"

tgbot:
  token: "TELEGRAM TOKEN"  # if run with telegram bot
  1. To run the script in the command console, run the following code:

for cli mode:

python3 launch.py --config=configs/my.yaml

for telegram-bot mode:

python launch.py --config=configs/my.yaml --mode=tgbot

CLI mode

Command List:

  • help: show this document
  • his: show history of current session
  • list: list all saved sessions
  • new: create a new session
  • save: save current session
  • info: show current session information
  • rename NEW_NAME: set session name
  • max MAX_HISTORY: set max history(default max_history = 10)
  • ch SESSION_ID: resume(change) to specific session with session id
  • sys SYSTEM_PROMPT: update system prompt
  • ^C: cancel inputing
  • ^D: exit chatting

An example:

[System] There is no saved session, create a new one.
You have started a new chat session
Command List:
        [help]: show this document
        [his]: show history of current session
        [ls]: list all saved sessions
        [new]: create a new session
        [resume]: resume specific session with session id
        [save]: save current session
<User>: 你好
<ChatGPT>: 你好!有什么我可以帮你的吗?
<User>: Write a hellworld example with golang
<ChatGPT>: Sure, here's a "Hello World" example in Go:

"```"
package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}
"```"

When you run this program, it will print the message "Hello, world!" to the console.

To run this program, save it in a file called `hello.go`. Then, navigate to the directory where the file is saved using the command prompt or terminal, and run the command:

"```"
go run hello.go
"```"

You should see the output "Hello, world!" printed to the console.
<User>: thx
<ChatGPT>: You're welcome! If you have any other questions or tasks, feel free to ask.

Telegram Mode

Command List:

  • /help: show this document
  • /his: show history of current session
  • /list: list all saved sessions
  • /new: create a new session
  • /save: save current session
  • /info: show current session information
  • /rename NEW_NAME: set session name
  • /max MAX_HISTORY: set max history(default max_history = 10)
  • /ch SESSION_ID: resume(change) to specific session with session id
  • /sys SYSTEM_PROMPT: update system prompt

Screenshot:

Deploy with Docker

docker run -d \
   --name chatgpt \
   -v /path/to/data:/data \
   -e OPENAI_KEY="KEY" \
   -e TELEGRAM_TOKEN="TOKEN" \
   princewang1994/chatgpt:latest

Build from Dockerfile

git clone https://github.com/princewang1994/chatgpt-telegram-bot-cli.git
cd chatgpt-telegram-bot-cli
docker build --no-cache -f docker/Dockerfile -t chatgpt .

About

ChatGPT TelegramBot/CLI Tool

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published