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

Add auto_tts plugin #468

Merged
merged 1 commit into from
Dec 10, 2023
Merged

Add auto_tts plugin #468

merged 1 commit into from
Dec 10, 2023

Conversation

Jipok
Copy link

@Jipok Jipok commented Nov 23, 2023

This allows the bot to independently send voice messages to the user. Example:
изображение

If you think that the name is not suitable, then suggest a better one because I don't really like it either.

I also didn’t like the architecture of the project. For some purpose, the plugin system, interaction with openai, and the telegram bot are strongly separated from each other. This makes it difficult to implement many ideas. At the same time, without bringing at least any benefit to the project.
Thus, I decided that “forwarding” the helper “down” to the plugin system would not make things worse. We already have an isolation violation when forwarding chat_id.

@n3d1117
Copy link
Owner

n3d1117 commented Nov 24, 2023

Hi @Jipok! Thank you for your contribution, looks cool and will be testing it soon.

I agree that the overall architecture is not great 😃 it all started as a side project in my free time and I never expected it to reach this many people. If you feel like it, PRs are open for improvements!

@n3d1117 n3d1117 mentioned this pull request Nov 24, 2023
@Jipok
Copy link
Author

Jipok commented Nov 25, 2023

If you accept, I will make a similar plugin for generating images via dalle.

@rorezez
Copy link

rorezez commented Nov 30, 2023

Could you explain where the helper object is initialized, and how it is integrated into this system? I'm trying to understand how the helper object connects with the OpenAIHelper class."

@n3d1117
Copy link
Owner

n3d1117 commented Dec 10, 2023

Apologies for the late reply @Jipok, this plugin looks great and a Dalle one would be awesome as well.

@rorezez the OpenAI helper object is initialized in the main.py file here:

openai_helper = OpenAIHelper(config=openai_config, plugin_manager=plugin_manager)

@n3d1117 n3d1117 merged commit 071344b into n3d1117:main Dec 10, 2023
@makdisse
Copy link

makdisse commented Mar 22, 2024

@Jipok I'm not sure if I'm doing something wrong here?

(venv) PS C:\Users\paulo\Documents\paulo-sync\chatgpt-telegram-bot> python bot/main.py
2024-03-22 19:54:05,640 - telegram.ext.Application - INFO - Application started
2024-03-22 19:54:09,218 - root - INFO - New transcribe request received from user @makdisse (id: 99742609)
2024-03-22 19:54:21,818 - root - INFO - Calling function translate_text_to_speech with arguments {"text":"An eclipse is an astronomical event that occurs when one celestial body moves into the shadow of another celestial body. There are two main types of eclipses: solar and lunar. A solar eclipse happens when the moon passes between the Earth and the sun, blocking all or part of the sun's light. A lunar eclipse occurs when the Earth passes between the sun and the moon, causing the Earth's shadow to fall on the moon. Eclipses can be partial, where only a part of the celestial body is obscured, or total, where the body is completely covered. Eclipses have fascinated people for centuries and often play significant roles in various cultures and mythologies."}
2024-03-22 19:54:25,831 - root - ERROR - unsupported operand type(s) for +=: 'int' and 'str'
Traceback (most recent call last):
  File "C:\Users\paulo\Documents\paulo-sync\chatgpt-telegram-bot\bot\telegram_bot.py", line 419, in _execute
    self.usage[user_id].add_chat_tokens(total_tokens, self.config['token_price'])
  File "C:\Users\paulo\Documents\paulo-sync\chatgpt-telegram-bot\bot\usage_tracker.py", line 87, in add_chat_tokens
    self.usage["usage_history"]["chat_tokens"][str(today)] += tokens
TypeError: unsupported operand type(s) for +=: 'int' and 'str'

This is my .env file

TELEGRAM_BOT_TOKEN="74....M8"
OPENAI_MODEL=gpt-4-turbo-preview
ENABLE_TTS_GENERATION=true
PLUGINS=auto_tts

Running it on Windows 11 with Python 3.10.11

@Jipok
Copy link
Author

Jipok commented Mar 23, 2024

Something happened with usage_logs/99742609.json. I saw this once. I didn't find the reason. You can either delete the log or correct it. Most likely, the last entry in chat_tokens is in quotes, that is, for some reason it was saved as a string, not a number. Just remove the quotes.

@makdisse
Copy link

@Jipok this is the json:
{"user_name": "@makdisse", "current_cost": {"day": 6.2e-05, "month": 6.2e-05, "all_time": 6.2e-05, "last_update": "2024-03-23"}, "usage_history": {"chat_tokens": {"2024-03-23": 31}, "transcription_seconds": {"2024-03-23": 5.7335}, "number_images": {}, "tts_characters": {}, "vision_tokens": {}}}

Could not find the number in quotes. I tried deleting it as well but it didn't work.

@Jipok
Copy link
Author

Jipok commented Mar 23, 2024

@makdisse this is weird. Is the problem really in the tts plugin? If you turn it off, is everything ok?

@makdisse
Copy link

@Jipok yes, if I turn it off it works fine. It is working now, I'm not sure what it was, I recreated the file manually and it works.
Thanks for your help thought.

@Jipok
Copy link
Author

Jipok commented Mar 23, 2024

I'm not sure what it was

M.b. bug with plugin and empty history

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

Successfully merging this pull request may close these issues.

4 participants