mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-09-10 17:20:41 +03:00
* update dependencies and python to 3.12.3 * fix tests
Chat gpt bot
Telegram bot with proxy to chatgpt
Install & Update
Install service
git clone https://github.com/Balshgit/gpt_chat_bot.git
cd gpt_chat_bot
sudo rsync -a --delete --progress ./* /opt/gpt_chat_bot/ --exclude .git
cd /opt/gpt_chat_bot
sudo cp ./bot_microservice/settings/.env.template ./bot_microservice/settings/.env
sudo cp ./scripts/gptchatbot.service /etc/systemd/system
sudo systemctl enable gptchatbot.service
sudo systemctl start gptchatbot.service
Update service
git pull balshgit main
sudo rsync -a --delete --progress ./* /opt/gpt_chat_bot/ --exclude .git
cd /opt/gpt_chat_bot/
docker pull balshdocker/freegpt
docker compose build
sudo systemctl stop gptchatbot.service
sudo systemctl start gptchatbot.service
Local start
Bot:
cd bot_microservice
python main.py
cd bot_microservice &&
poetry run uvicorn main:create_app --factory --host 0.0.0.0 --port 8080 --forwarded-allow-ips='*' --proxy-headers --reload --workers 2 --log-level warning
To start on polling mode set START_WITH_WEBHOOK
to blank
Delete or set webhook manually
url: https://api.telegram.org/bot{TELEGRAM_TOKEN}/{method}Webhook?url={WEBHOOK_URL}
methods:
- delete
- set
Admin:
http://localhost:8858/{URL_PREFIX}/admin
Chat:
docker run --rm --net=host --name freegpt --rm -e CHAT_PATH=/chat balshdocker/freegpt:latest
docker run --rm --net=host --name zeus --rm balshdocker/freegpt-zeus:latest
Open http://localhost:8858/chat/
cd bot_microservice
gunicorn main:create_app --workers 10 --bind 0.0.0.0:8000 --worker-class uvicorn.workers.UvicornWorker --timeout 150 --max-requests 2000 --max-requests-jitter 400
Tests
Run local tests:
cd bot_microservice
STAGE=runtests poetry run pytest
Run tests in docker compose:
cd bot_microservice
STAGE=runtests docker compose run bot bash -c "coverage run -m pytest -vv --exitfirst && poetry run coverage report"
Docs
Docs can be found at
- {domain}/{url_prefix}/{api_prefix}/docs
- {domain}/{url_prefix}/{api_prefix}/redoc
on local start can be found at http://localhost/gpt/api/docs
prod docs https://{DOMAIN}/{URL_PREFIX}/{API_PREFIX}/docs/
Create migrations
Init alembic
alembic init alembic
cd bot_microservice
alembic revision --autogenerate -m 'create_chatgpt_table'
alembic upgrade head
python3 core/bot/managment/update_gpt_models.py
Create table in alembic versions
alembic --config ./alembic.ini revision -m "create account table"
alembic --config ./alembic.ini revision --autogenerate -m 'create_quads_table'
Run migrations
note: all migrations should be executed from ./bot_microservice directory
upgrade to head:
cd ./bot_microservice # alembic root
alembic --config ./alembic.ini upgrade head
python3 core/bot/managment/update_gpt_models.py
downgrade to 0001_create_chatgpt_table revision:
alembic --config ./alembic.ini downgrade alembic downgrade 0001_create_chatgpt_table
downgrade or upgrade +1 revision:
alembic upgrade +1
alembic downgrade -1
downgrade to base:
alembic downgrade base
Help article
Следить за обновлениями этого репозитория
TODO
- add Database and models
- add alembic migrations
- add models priority
- and models rotation
- add update model priority endpoint
- add more tests for gpt model selection
- add authorization for api
- reformat conftest.py file
- add sentry
- add graylog integration and availability to log to file
- add user model
- add messages statistic
Description
Languages
C++
54.8%
Python
34.6%
JavaScript
4.1%
CSS
3.5%
HTML
1.5%
Other
1.5%