Skip to content

Latest commit

 

History

History
399 lines (293 loc) · 17.4 KB

README.EN.md

File metadata and controls

399 lines (293 loc) · 17.4 KB

cover


License PYTHON SPONSOR

Openaibot

OpenAI Chat Bot For Telegram. 在 Telegram 上使用 OpenAi 交互。

Translate by deepl (wink~

This project uses Api authentication Token + context pooling to implement chat, and is not a reverse of chatGPT, the Python implementation of the chatGPT-like is self-implemented by this bot.

The Python implementation of chatGPT functionality is implemented by this bot. but the Api costs money

use Unofficial(self) async Api library to Speed up

Features

  • chat (chat) chatGpt replica + NLP enhancements
  • write independent speculation, continuation
  • Set a constant story set point
  • Multi maneger
  • Multi Api key load, overrun popup.
  • chatGPT api version implementation, not reverse preview's api
  • Support for private chats
  • Support for group chat
  • Rate limiting support
  • Support for usage management
  • Whitelisting support
  • Blacklisting support
  • Support for content filtering
  • (20221205) Api library changed to an Async library implemented in this repository
  • Dynamic context trimming to prevent overruns
  • Pre enhance support, Prompt Injection+ Web

See LlmKira#1

chatGpt

🔭 Using /chat + sentence you can start a loop and then just reply to talk. Private chat messages or group messages within 48 hours are automatically inferred and cropped using context, and the conversation can continue by replying directly.

Use /forgetme resetAi's memory.

Continued

🥖 Use /write to continue writing without contextual speculation.

Head

Supports scenario setting, using /remind to design your own request headers. For example Ai plays an astronaut on a space station.

Description of these settings

sent to the Api is

head (left out defaults to The following dialogue is between the person and the Ai helper)
The key dialogue after nlp processing
The three original messages above that are retained
Start header (AI:)

Initialization

  • Pull/update the program

The install script will automatically backup the restore configuration, run it in the root directory (not in the program directory) If it is a minor update you can just git pull.

curl -LO https://raw.githubusercontent.com/sudoskys/Openaibot/main/setup.sh && sh setup.sh

cd Openaibot

Docker images will release updates only after they are guaranteed to be stable.

git clone https://github.com/sudoskys/Openaibot
cd Openaibot
vim Config/service.json # see **Configure**
docker compose up -d

Configure

Configuring Redis

local

apt-get install redis

Docker

Configure service.json, the template example is below, you need to change host localhost to redis

Configure dependencies

pip install -r requirements.txt

pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

Filters

Data/Danger.form One line of one blacklisted vocabulary. There must be at least one.

If not, the program will automatically pull down the cloud default list, and subsequent updetects will pull the cloud to overwrite the local one.

You can turn this filter off by placing a one-line list, but I don't favour you doing this.

Config/app.toml

cp app_exp.toml app.toml

vim app.toml nano app.toml

Configuration files

[bot]
master = [555555, 66666] # master user id &account id
botToken = 'key'
INTRO = "POWER BY OPENAI" # suffix
ABOUT = "Created by github.com/sudoskys/Openaibot"
WHITE = "Group NOT in WHITE list"
Enhance_Server = { "https://www.expserver.com?q={}" = "auto", "http:/exp?q={}" = "auto" }
# 联网支持,自己找 server,{}将被替换为搜索词,目前联网回答的标识键为 Auto

# for bot , not openai
[proxy]
status = false
url = "http://127.0.0.1:7890"

get Telegram botToken

configure key

Configure key in bot private chat

see_api_key - Several Api keys now
del_api_key - Delete Api key
add_api_key - add Api key

OPENAI_API_KEY Application, supports multi-key distribution load. Pricing Reference.

Please do not expose your app.toml to anyone

Configure service.json

under Config/service.json. If there is no such file, the default value will be used. Deep coverage if available. Keys that are not in the preset will not be completed.

{
  "redis": {
    "host": "localhost",
    "port": 6379,
    "db": 0,
    "password": null
  },
  "tts": {
    "status": false,
    "type": "vits",
    "vits": {
      "api": "http://127.0.0.1:9557/tts/generate",
      "limit": 70,
      "model_name": "some.pth",
      "speaker_id": 0
    },
    "azure": {
      "key": [
        "123"
      ],
      "limit": 70,
      "speaker": {
        "chinese": "zh-CN-XiaoxiaoNeural"
      },
      "location": "japanwest"
    }
  }
}

Redis

  • slightly

TTS

  • status switch
  • type Type

VITS

  • vits:limit text within length will be converted
  • vits:model_name The name of the model, some.pth, in the model folder
  • vits:speaker_id The ID of the speaker, see the model config

Azure

  • azure:limit The text within the length will be converted
  • azure: speakerlist-of-all-sound-engines
  • auzre:location Server resource address
  • auzre:key api key

VITS Voice Support Description(Language types are determined by the model)

This technology provides an emulated voice interaction technique.

The Api backend is my packaged adaptation of MoeGoe https://github.com/sudoskys/MoeGoe

Install the dependencies and run server.py to use it by default.

Please consult the MoeGoe project's Readme under Models and note the corresponding protocols for the models.

Run

  • Run
nohup python3 main.py > /dev/null 2>&1 & 
  • View the process
ps -aux|grep python3
  • Terminate a process followed by the process number
kill -9  

command

Restricted class setting set to 1 means no effect.

command function extra
/set_user_cold set user cooldown time can not send within the time 1 is unlimited
/set_group_cold Set group cooling time Cannot send within the time 1 is unlimited
/set_token_limit Set the output limit length Api's 4095 limit is input + output, if it exceeds the limit, please reduce the output
/set_input_limit Set input limit length
/config get/backup config.json file send file
/add_block_group +id absolute value Prohibited Effective directly Can be followed by multiple parameters, separated by spaces
/del_block_group + absolute value of id Unban Effective directly Can be separated with multiple parameters and spaces
/add_block_user +Absolute value of id Forbidden Effective directly Can be followed by multiple parameters, separated by spaces
/del_block_user + absolute value of id Unban Effective directly Can be separated with multiple parameters and spaces
/add_white_group +id absolute value Add Need to enable the whitelist mode to take effect Can be separated with multiple parameters and spaces
/add_white_user + id absolute value Add Need to enable the whitelist mode to take effect Can be separated with multiple parameters and spaces
/del_white_group +id absolute value Delisting Need to enable the whitelist mode to take effect Can be separated with multiple parameters and spaces
/del_white_user + absolute value of id Delisting Need to enable the whitelist mode to take effect Can be separated with multiple parameters and spaces
/update_detect Update sensitive words
/open_user_white_mode Open user whitelist
/open_group_white_mode Open group whitelist
/close_user_white_mode close user whitelist
/close_group_white_mode close group whitelist
/open Open the robot
/close close the robot
/chat Conversation Each time /chat starts over, forgetting the record. Replies cannot be indexed after 24 hours in the group, and private chats are permanent.
/write continue writing continue writing.
/see_api_key Several Api keys now
/remind Persona Fixed reminder.
/del_api_key +key Delete Api key Can follow multiple parameters, separated by spaces
/add_api_key +key Add Api key Can follow multiple parameters, separated by spaces
/set_per_user_limit total user allocation limit 1 is unlimited per user
/set_per_hour_limit user hour usage 1 is unlimited, per user
/reset_user_usage+userID Reset user quota Measured by user Can be followed by multiple parameters, separated by spaces
/promote_user_limit+userID+limit Promote the user's limit Measured by user 1 is the default, can be followed by multiple parameters, separated by spaces
/disable_change_head disalbe head setting Setting again will reset to empty
/enable_change_head enable head setting
/remind how ai perform self Fixed cue words
/forgetme 忘记我
/voice VITS/AZURE TTS

Sample table

chat - Talking
write - complement
remind - persona
forgetme - reset
voice - 语音支持
set_user_cold - set user cooldown
set_group_cold - sets the group cooldown time
set_token_limit - set output limit length
set_input_limit - sets the input limit length
see_api_key - now several Api keys
del_api_key - remove Api key
add_api_key - add Api key
config - get/backup hotfile
set_per_user_limit - set the normal user limit
set_per_hour_limit - set the hourly user limit
promote_user_limit - raise user limit
reset_user_usage - reset user limits
add_block_group - disable a group
del_block_group - unblock a group
add_block_user - disable a user
del_block_user - unblock a user
add_white_group - add a whitelisted group
add_white_user - add whitelisted users
del_white_group - delist a whitelisted group
del_white_user - delist a whitelisted person
update_detect - update sensitive words
open_user_white_mode - open user whitelist
open_group_white_mode - open group whitelist
close_user_white_mode - turn off user whitelisting
close_group_white_mode - Turn off group whitelisting
open - turn on bots
close - disables the bot
disable_change_head - allow setting of head
enable_change_head - disable_change_head
help - help

Other

Statistics

analysis.json is the frequency statistic, the number of requests in 60s.

And total usage, which doesn't contain all the usage data, it's just pulled from redis

Config.json

will automatically merge the missing keys to fix them.

Default parameters

  • Group revert memory to 48 hours
  • Usage limit is 15000/h
  • Memory capacity of 80 dialogue pairs

Middleware support/Prompt Injection

There is a middleware between the memory pool and the analysis that can provide some networking retrieval support and operational support. Services that can interface with other Api's can be spiked.

prompt_server.py

Peripheral Prompt trimming interface to give support to other projects.

Declarations

1. This project is not an official Openai project.
2. is not responsible for any content generated by the bot.
3. 部分套件可能无法商业使用,请自担风险。

QuickDev

Quick Dev by MVC framework https://github.com/TelechaBot/BaseBot

API

You can view the API documentation at https://github.com/sudoskys/Openaibot/blob/main/API.md . Since the development progress differs between the API server and Telegram Bot, the API server may not work properly when there are unadapted changes on some imported modules. In that case, you can use the apiserver branch to get a stable API server.

Last performance analysis

Daily load 300MB

Thanks to

FOSSA

FOSSA Status