66 Commits
Author SHA1 Message Date
Father BotandGitHub 3631d6534f fix: ignore unmentioned media in group chats; bump python-dotenv (#518)
- unsupport_message_handle now checks is_bot_mentioned, so the bot stops
  replying "I don't know how to read files or videos" to videos/documents
  it wasn't mentioned in within group chats (#454). Private chats are
  unaffected (is_bot_mentioned returns True there).
- Bump python-dotenv 1.0.1 -> 1.2.2 to resolve a Dependabot symlink-following
  advisory in set_key.
- Bump version to 1.3.1 and document in CHANGELOG.
2026-06-14 13:45:46 +03:00
Father Bot a7984073b1 Remove unused is_content_acceptable helper
The moderation helper had no callers anywhere in the codebase. Drop
the dead function.
2026-06-05 12:30:00 +03:00
Father Bot 068f996473 Simplify token-count overhead table
The per-model if/elif chain only ever set tokens_per_message=3 for
supported models (and 4 for the now-removed gpt-3.5 family). Collapse
it to a single assignment since every current chat model shares the
same overhead.
2026-05-26 10:15:43 +03:00
Father Bot 5d8f98427e Skip unconfigured models in /balance
Existing users may have token usage recorded against models that have
since been removed from models.yml. Skip any model key not present in
the config when building the balance breakdown so /balance no longer
raises a KeyError for them.
2026-05-23 16:41:20 +03:00
Father Bot 3b3fab9e06 Send gpt-image-1 images as bytes and update balance
generate_images now returns raw image bytes, so wrap each in BytesIO
for reply_photo instead of passing a URL. Reference the gpt-image-1
price entry in /balance and relabel it 'GPT Image'.
2026-05-05 11:36:29 +03:00
Father Bot 52857fedde Generate images with gpt-image-1
Replace DALL-E 3 with OpenAI's gpt-image-1 model. gpt-image-1 returns
base64-encoded images instead of URLs, so decode each result to raw
bytes and return the list of images.
2026-05-02 17:14:51 +03:00
Father Bot b7f8224606 Update bot to DALL-E 3 for balance and image accounting
Reference the dalle-3 price entry and label balance details as
DALL·E 3, and count actually returned images (len(image_urls))
instead of the configured request count, since DALL-E 3 always
returns a single image.
2026-04-17 14:23:18 +03:00
Father Bot f7459df1ad Default image size to 1024x1024 for DALL-E 3
512x512 is not a valid DALL-E 3 size. Default to 1024x1024 and update
the example config to list the supported DALL-E 3 sizes and note the
one-image-per-request limit.
2026-04-11 19:31:07 +03:00
Father Bot 09ebbbf996 Switch image generation to DALL-E 3
Use the dall-e-3 model in generate_images and default to 1024x1024.
dall-e-3 only supports n=1, so request a single image per call.
2026-04-08 11:08:52 +03:00
Father Bot 33ec9c3ead Route image messages by the config vision flag
bot.py decided vision handling from hardcoded gpt-4o/gpt-4-vision
checks. Use the models.yml 'vision' flag instead: any vision-capable
model (incl. gpt-5.5 and Claude) now handles images directly, and a
photo sent to a non-vision model still falls back to gpt-4o. The
rejection message in the vision handler is updated to match.
2026-03-28 18:05:52 +03:00
Father Bot 16441877b8 Gate vision in openai_utils by the config vision flag
send_vision_message and send_vision_message_stream now accept any
model flagged vision: true in models.yml instead of a hardcoded
gpt-4o/gpt-4-vision set, so Claude and gpt-5.5 can process images.
2026-03-27 09:50:27 +03:00
Father Bot f239b53086 Lay out settings model buttons in rows of two
The settings menu put every model button in a single row. Telegram
rejects rows with more than 8 inline buttons, which would break
/settings now that the model list is longer. Chunk the buttons into
rows of two.
2026-03-19 15:52:08 +03:00
Father Bot 8b42181274 Add OpenRouter provider support
Introduce an optional OpenRouter client (OpenAI-compatible) alongside
the OpenAI one. Models can declare 'provider: openrouter' in
models.yml; ChatGPT now selects the matching client per model via
_get_client_for_model and routes chat completions through it. This
unlocks non-OpenAI models (e.g. Claude) through a single SDK.

Adds openrouter_api_key / openrouter_api_base config options.
2026-03-03 12:40:21 +03:00
Father Bot 6af26cc9bc Dispatch chat models by config type, not hardcoded lists
Replace the hardcoded model-name sets in __init__, send_message and
send_message_stream with checks against config/models.yml: the assert
now accepts any model defined in models['info'], and the chat path is
taken for any model whose type is 'chat_completion'. Adding a new
chat model is now a models.yml-only change. Vision handling is left
on its explicit model set for now.
2026-02-28 18:47:09 +03:00
Father Bot ee9dae189f Make token counting robust for non-OpenAI models
tiktoken.encoding_for_model and the per-model token table only know
OpenAI models, so any other model (Claude or anything routed via
OpenRouter) raised. Fall back to the o200k_base encoding and a
default tokens_per_message for unknown models so streaming token
estimates work for every chat model.
2026-02-27 14:22:36 +03:00
Father Bot e37eb4a248 Drop text-davinci-003 code paths from openai_utils
Remove the legacy completion handling now that the model is gone:
- drop text-davinci-003 from the __init__ assert
- remove the legacy completions.create branches in send_message and
  send_message_stream
- delete the now-unused _generate_prompt and _count_tokens_from_prompt
  helpers

All remaining paths use the chat completions API.
2026-02-14 12:05:18 +03:00
Father Bot 8624e97dd2 Default ChatGPT() model arg to gpt-4o-mini
Keep the ChatGPT class fallback model in sync with the new project
default. Callers always pass an explicit model, so this only affects
the no-argument fallback.
2026-01-22 13:48:09 +03:00
Father Bot ea3af7d3aa Reset to gpt-4o-mini (not gpt-3.5-turbo) on /new
new_dialog_handle pins the model on every /new. Point it at the new
default gpt-4o-mini so starting a new dialog no longer drops users
back onto the outdated gpt-3.5-turbo.
2026-01-14 17:22:41 +03:00
Father Bot 4365a9b635 Narrow bare excepts to Exception in bot handlers
Replace the two bare 'except:' clauses (is_bot_mentioned and the
error handler fallback) with 'except Exception:' so they no longer
swallow KeyboardInterrupt, SystemExit or asyncio.CancelledError,
which must propagate for clean shutdown and task cancellation.
2025-12-26 13:15:05 +03:00
Father Bot fc0cac03ab Use openai.BadRequestError in image generation handler
Follow-up to the openai 1.x migration: the legacy
openai.error.InvalidRequestError no longer exists in the 1.x SDK.
Catch openai.BadRequestError when DALL-E rejects a prompt.
2025-12-18 09:37:31 +03:00
Father Bot d48276616a Migrate openai_utils to the openai 1.x SDK
Replace the deprecated module-level openai 0.28 API with the new
AsyncOpenAI client:
- instantiate AsyncOpenAI(api_key, base_url) instead of setting
  openai.api_key / openai.api_base globals
- ChatCompletion.acreate -> client.chat.completions.create
- Completion.acreate(engine=...) -> client.completions.create(model=...)
- Audio.atranscribe -> client.audio.transcriptions.create
- Image.acreate -> client.images.generate
- Moderation.acreate -> client.moderations.create (use .flagged)
- attribute access for message/delta content (.content instead of
  dict access) and guard empty streaming choices
- rename request_timeout option to timeout
- catch openai.BadRequestError instead of openai.error.InvalidRequestError

Bump openai to >=1.40.0,<2.0.0. Requires testing against the API.
2025-12-16 18:54:48 +03:00
Father Bot 7123bd14a1 Remove leftover debug logging in message handler
logger.error(current_model) fired on every incoming message and
spammed the error log with the model name; the accompanying
'# What is this? ^^^' note was dead. Drop both; the vision
auto-switch logic is unchanged.
2025-12-07 09:21:57 +03:00
Father Bot 43aa46a872 Add gpt-4o-mini model support
Wire gpt-4o-mini through the bot: register it in models.yml
(available list + pricing/scores entry) and add it to the model
sets in openai_utils (chat, streaming, vision and token counting).
gpt-4o-mini is cheaper and smarter than gpt-3.5-turbo and supports
images, so it is a good default-grade option. Addresses #474.
2025-12-05 19:05:44 +03:00
pyranota c017c32800 Fix defaulting 2024-05-23 23:27:27 +02:00
pyranota 752f38b348 Add support for GPT-4o 2024-05-23 17:45:28 +02:00
OlegGoless 6540b28437 fix bug in context 2024-04-16 14:56:04 +02:00
OlegGoless 5e4552e4df delete required text caption with image 2024-04-04 10:22:53 +02:00
OlegGoless e8a1a1fb2e fix 2024-04-02 17:22:58 +02:00
OlegGoless 3b8b0b2a52 vision 2024-04-02 14:43:04 +02:00
Karim Iskakov 61b8dbd0ce Add GPT-4 Turbo 2023-11-15 17:45:57 +03:00
Daniil OkhlopkovandGitHub ce0c34825f Store Voice temp files in memory and don't convert them 2023-11-02 16:52:35 +03:00
Dichi Al FaridiandGitHub acd4cab782 Make the DALLe image size configurable (#365) 2023-09-13 13:17:21 +03:00
Karim Iskakov 8f5a020891 Increase OpenAI timeout 2023-08-28 19:07:32 +03:00
Karim Iskakov 0c09f1aaca Add OpenAI API Base to config 2023-08-01 18:41:31 +03:00
Karim Iskakov c77501c3d9 Remove deprecated "use_chatgpt_api" parameter 2023-07-18 13:43:44 +03:00
a4bd06ac9e Allow channels (#312)
Co-authored-by: Flop <flop@loona.app>
2023-06-20 11:52:57 +03:00
TanNhatCMSandGitHub 8df5e2d24d fix argument of type 'float' is not iterable (#211)
* fix argument of type 'float' is not iterable

fix "argument of type 'float' is not iterable" in show_balance_handle and message_handle

* Update bot.py
2023-06-20 11:50:03 +03:00
maccagnitandGitHub 533e6705c8 Added GPT-3.5 16K chat functionality (#306) 2023-06-20 11:47:19 +03:00
Karim IskakovandGitHub 28e7426c2b Fix HTTPX problem 2023-06-20 11:29:04 +03:00
Karim Iskakov 37e7101273 Fix edited messages in group chats 2023-04-24 04:11:21 -05:00
Karim IskakovandGitHub ada0f34e54 🔥 Add 10 new chat modes + Updated chat mode menu with pagination 2023-04-21 14:02:50 +03:00
Karim Iskakov 8657adb463 Fix bot mention in group chat 2023-04-21 05:20:20 -05:00
Karim IskakovandGitHub 04d620ef32 Group Chat support (#247)
Based on @clemsau and @Tuarisa code
2023-04-21 13:16:02 +03:00
Megham GargandGitHub 85f149c975 Missing self from error handler 2023-04-21 12:46:08 +03:00
Karim IskakovandGitHub e421be1634 DALLE 2 2023-04-21 12:37:06 +03:00
Karim IskakovandGitHub aa38a1f5c7 Add /cancel command 2023-03-31 13:58:08 +07:00
Karim IskakovandGitHub a8cef77330 Add "Three Dots" message 2023-03-29 15:30:34 +07:00
Karim IskakovandGitHub 7b6a50998c Remove trailing whitespaces 2023-03-29 14:42:01 +07:00
Karim IskakovandGitHub a4b5eb36e1 GPT-4 support 2023-03-22 23:58:48 +03:00
Karim IskakovandGitHub 1ba09de2b9 Add message streaming
* Add message streaming
* Update README.md
2023-03-15 19:20:43 +03:00