Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sent_message is always None, it seems that the check should be skipped here? #336

Closed
hsiaoping-nthu opened this issue Jun 13, 2023 · 1 comment

Comments

@hsiaoping-nthu
Copy link

Hello, I trace the code and find some that seem a bit odd.

In line 603 of file bot/telegram_bot.py(line 16 in following code section), I think sent_message is always None because it does only initialize but not update.
Maybe it can skip i==0 case?
Thanks for your response. ☺️

1. if self.config['stream']:
2.     stream_response = self.openai.get_chat_response_stream(chat_id=user_id, query=query)
3.     i = 0
4.     prev = ''
5.     sent_message = None
6.     backoff = 0
7.     async for content, tokens in stream_response:
8.         if len(content.strip()) == 0:
9.             continue
10.   
11.         cutoff = get_stream_cutoff_values(update, content)
12.         cutoff += backoff
13.   
14.         if i == 0:
15.             try:
16.                 if sent_message is not None:
17.                     await edit_message_with_retry(context, chat_id=None,
18.                                                   message_id=inline_message_id,
19.                                                   text=f'{query}\n\n{answer_tr}:\n{content}',
20.                                                   is_inline=True)
21.             except:
22.                 continue
@n3d1117
Copy link
Owner

n3d1117 commented Jun 13, 2023

Hey @hsiaoping-nthu, good catch and thanks for reporting! Looks we can remove these two lines safely:

sent_message = None

and

if sent_message is not None:

Could you maybe test it and open a PR if everything looks ok? EDIT: done in fdd76ee

Dener1111 added a commit to Dener1111/chatgpt-telegram-bot that referenced this issue Jun 17, 2023
commit a45cf8e
Author: ned <github@edoardo.fyi>
Date:   Wed Jun 14 20:26:26 2023 +0200

    added functions note to README

commit 72b5527
Merge: fdd76ee 5fd70f4
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Wed Jun 14 12:42:24 2023 +0200

    Merge pull request n3d1117#341 from n3d1117/feature/rate-limit-retry

    Auto retry while rate limited using tenacity

commit 5fd70f4
Author: ned <github@edoardo.fyi>
Date:   Wed Jun 14 12:41:41 2023 +0200

    Update requirements.txt

commit 96fb76e
Author: ned <github@edoardo.fyi>
Date:   Wed Jun 14 12:35:23 2023 +0200

    auto retry while rate limited using tenacity

commit fdd76ee
Author: ned <github@edoardo.fyi>
Date:   Wed Jun 14 10:42:10 2023 +0200

    Fixes n3d1117#336

commit 4760ff1
Author: ned <github@edoardo.fyi>
Date:   Wed Jun 14 10:34:34 2023 +0200

    update badge

commit 3d6247f
Merge: 1433207 74dfdb8
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Wed Jun 14 10:29:16 2023 +0200

    Merge pull request n3d1117#340 from n3d1117/new-models

    Support new models and update dependencies

commit 74dfdb8
Author: ned <github@edoardo.fyi>
Date:   Wed Jun 14 10:27:06 2023 +0200

    support new models and update dependencies

    `gpt-3.5-turbo-0613`, `gpt-3.5-turbo-16k`, `gpt-3.5-turbo-16k-0613`, `gpt-4-0613`, `gpt-4-32k-0613`

commit 1433207
Merge: 1c8b633 1df1c8b
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Sat May 20 12:47:29 2023 +0200

    Merge pull request n3d1117#321 from nmeln/add-ukrainian-translation

    Add Ukrainian translation.

commit 1df1c8b
Author: Nazarii Melnychuk <melnychuk.nazarii@gmail.com>
Date:   Fri May 19 14:01:45 2023 +0300

    Update README with a mention of the new translation

commit df13d72
Author: Nazarii Melnychuk <melnychuk.nazarii@gmail.com>
Date:   Fri May 19 13:52:17 2023 +0300

    change the translation for the "prompt" strings

commit 5238437
Author: Nazarii Melnychuk <melnychuk.nazarii@gmail.com>
Date:   Fri May 19 13:45:00 2023 +0300

    Add ukrainian (uk) translation.

commit 1c8b633
Merge: 3023c45 c1c6802
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Wed May 17 09:32:31 2023 +0200

    Merge pull request n3d1117#318 from danfmaia/fix/transcription-price

    fix: transcription price

commit c1c6802
Author: Dan Maia <danilofmaia@gmail.com>
Date:   Tue May 16 17:55:03 2023 -0300

    fix: transcription_price config variable

commit 3023c45
Merge: 14b8457 ce1e7c6
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Sun May 7 15:21:35 2023 +0200

    Merge pull request n3d1117#300 from gkpiccoli/main

    pt-br translation

commit ce1e7c6
Author: Gustavo Kureck Piccoli <gustavokpiccoli@gmail.com>
Date:   Sat May 6 16:15:55 2023 -0300

    Add pt-br translations and README.md tag n flag

commit 14b8457
Author: ned <github@edoardo.fyi>
Date:   Sat May 6 12:31:17 2023 +0200

    update README.md

commit 075df1e
Author: ned <github@edoardo.fyi>
Date:   Sat May 6 12:30:55 2023 +0200

    move utils funcs to standalone file

commit e9bed78
Merge: 0fede20 b37946c
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Sat May 6 11:09:12 2023 +0200

    Merge pull request n3d1117#298 from stanislavlysenko0912/reply-messages

    Add support for quoting replied messages

commit b37946c
Author: stanislavlysenko0912 <stanislav.lysenko0912@gmail.com>
Date:   Fri May 5 15:06:39 2023 +0300

    feat(telegram_bot.py): add support for quoting replied messages in group chats

    This allows users to quote a message when replying to it in a group chat, making the conversation context clearer.

commit 0fede20
Merge: 17b1847 dedcd34
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Sun Apr 30 15:35:46 2023 +0200

    Merge pull request n3d1117#284 from BjornB2/main

    Update translations.json

commit dedcd34
Author: BjornB2 <bjorn@heirman.nl>
Date:   Sat Apr 29 09:40:07 2023 +0700

    Update translations.json

    Dutch (nl) translation changes

commit 17b1847
Merge: c2b56db 9c0bc00
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Fri Apr 28 00:50:35 2023 +0200

    Merge pull request n3d1117#280 from pintman/patch-1

    fix: missing comma

commit 9c0bc00
Author: Marco Bakera <pintman@users.noreply.github.com>
Date:   Thu Apr 27 20:59:03 2023 +0200

    fix: missing comma

commit c2b56db
Author: ned <github@edoardo.fyi>
Date:   Thu Apr 27 16:05:21 2023 +0200

    Update README.md

commit 84d8447
Merge: 86cf05c 38eb38c
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Thu Apr 27 16:03:05 2023 +0200

    Merge pull request n3d1117#279 from jnaskali/finnish

    Add Finnish translation

commit 38eb38c
Author: Juhani Naskali <juhani.naskali@gmail.com>
Date:   Thu Apr 27 16:38:11 2023 +0300

    Added Finnish language translation and updated README.md accordingly

commit 86cf05c
Merge: 656f9c2 5da46d8
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Thu Apr 27 10:20:01 2023 +0200

    Merge pull request n3d1117#274 from bugfloyd/feat/farsi_translation

    Add Farsi (Persian) translation

commit 5da46d8
Merge: c98bf07 656f9c2
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Thu Apr 27 10:19:31 2023 +0200

    Merge branch 'main' into feat/farsi_translation

commit 656f9c2
Merge: c83dc8f c5839b1
Author: ned <11541888+n3d1117@users.noreply.github.com>
Date:   Thu Apr 27 10:16:58 2023 +0200

    Merge pull request n3d1117#273 from aes-alienrip/main

    Add Traditional Chinese(zh-tw) support and rename Chinese(cn) to Simplified Chinese (zh-cn)

commit c98bf07
Author: bugfloyd <yashar.hv@gmail.com>
Date:   Sat Apr 22 16:45:42 2023 +0200

    Add language code for Farsi to readme configuration options table

commit d23b960
Author: bugfloyd <yashar.hv@gmail.com>
Date:   Sat Apr 22 16:25:10 2023 +0200

    Add Farsi (Persian) translation

commit c5839b1
Author: aes-alienrip <73251414+aes-alienrip@users.noreply.github.com>
Date:   Sat Apr 22 21:39:39 2023 +0800

    Update README.md

commit 150bbae
Author: aes-alienrip <73251414+aes-alienrip@users.noreply.github.com>
Date:   Sat Apr 22 21:34:52 2023 +0800

    Update translations.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants