Git Product home page Git Product logo

tg-openai-binder's Introduction

tg-openai-binder

ChatGPT Telegram

Python Docker

A simple Telegram bot to interact with Open AI models

Build

  1. clone this repo via

    git clone https://github.com/m0t9/tg-openai-binder
  2. set your parameters in .env file

    Parameter Meaning
    API_KEY Your OpenAI API key
    MODEL Name of used OpenAI model
    PROXY Optional. Proxy server for OpenAI queries processing
    TOKEN Telegram bot token
    START_PLACEHOLDER Message that bot will send as response to /start command
    PLACEHOLDER Message that bot will show while request processing
    CLEAR_CONTEXT_ANSWER Message that bot will send as response to /delete_context command
    CONTEXT_SIZE Number of the last messages in the dialogue with bot that will be considered as context. High values affect RAM usage
    OPEN_AI_ERROR Message that bot will send if something goes wrong during OpenAI query processing
    ALLOWED_IDS List of Telegram users (separated by comma) IDs that are allowed to interact with bot
    ENABLE_RENDER True or False. Exposes the web-server on :10000 (required for render.com free-tier web-service deployment)
  3. execute this command in repo root directory

    docker-compose up -d --build

Interaction

Command Meaning
/start Start dialogue with bot. As response it sends START_PLACEHOLDER
/delete_context Clears the dialogue context with user. Sends CLEAR_CONTEXT_ANSWER
any other text Will be considered as a query to OpenAI
image

tg-openai-binder's People

Contributors

m0t9 avatar wensiet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tg-openai-binder's Issues

TelegramBadRequest exception for message with single _ or *

Setup

  • OS version: Ubuntu 22.04.3 LTS
  • Python version: 3.10.12
  • aiogram version: 3.1.1

Steps to reproduce

  1. Send any request to bot, that would make the OpenAI model to send message with unclosed markdown symbol.
  2. Get the request stuck forever and get error message in the console.

Details

image

aiogram.exceptions.TelegramBadRequest: Telegram server says -
Bad Request: can't parse entities: Can't find end of the entity 
starting at byte offset 22
Cause exception while process update id=[REDACTED] by bot id=[REDACTED]
TelegramBadRequest: Telegram server says - Bad Request: can't parse entities: Can't find end of the entity starting at byte offset 22
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/dispatcher.py", line 308, in _process_update
    response = await self.feed_update(bot, update, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/dispatcher.py", line 157, in feed_update
    response = await self.update.wrap_outer_middleware(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/middlewares/error.py", line 25, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/middlewares/user_context.py", line 27, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/fsm/middleware.py", line 41, in __call__
    return await handler(event, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/event/telegram.py", line 120, in trigger
    return await wrapped_inner(event, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/event/handler.py", line 42, in call
    return await wrapped()
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/dispatcher.py", line 275, in _listen_update
    return await self.propagate_event(update_type=update_type, event=event, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/router.py", line 116, in propagate_event
    return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/router.py", line 111, in _wrapped
    return await self._propagate_event(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/router.py", line 136, in _propagate_event
    response = await observer.trigger(event, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/event/telegram.py", line 120, in trigger
    return await wrapped_inner(event, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/dispatcher/event/handler.py", line 42, in call
    return await wrapped()
           ^^^^^^^^^^^^^^^
  File "/app/bot/bot.py", line 53, in query_respond
    await bot.edit_message_text(answer, response.chat.id, response.message_id)
  File "/usr/local/lib/python3.11/site-packages/aiogram/client/bot.py", line 1475, in edit_message_text
    return await self(call, request_timeout=request_timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/client/bot.py", line 432, in __call__
    return await self.session(self, method, timeout=request_timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/client/session/base.py", line 257, in __call__
    return cast(TelegramType, await middleware(bot, method))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/client/session/aiohttp.py", line 175, in make_request
    response = self.check_response(
               ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiogram/client/session/base.py", line 120, in check_response
    raise TelegramBadRequest(method=method, message=description)
aiogram.exceptions.TelegramBadRequest: Telegram server says - Bad Request: can't parse entities: Can't find end of the entity starting at byte offset 22

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.