Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit de20255

Browse files
authored
Absent deps fixed, Llama3 added. (#38)
1 parent ff11e05 commit de20255

File tree

7 files changed

+244
-93
lines changed

7 files changed

+244
-93
lines changed

changelog.md

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.3.0] - 2024-07-12
11+
12+
### Changed
13+
- The provider Llama 2 in the list of available providers replaced by Llama 3.
14+
15+
### Fixed
16+
- Missing dependency (curl-cffi) required in new versions of gpt4free.
17+
- A bug causing the bot under heavy load to "forget" to respond.
18+
19+
20+
1021
## [0.2.3] - 2024-04-17
1122

1223
### Changed

hiroshi/services/gpt.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@
88

99
MODELS_AND_PROVIDERS: dict[str, tuple[str, str]] = {
1010
"Default": ("gpt_35_long", "Default"),
11-
"GPT-3.5 (The best/fastest provider)": ("gpt_35_long", "Default"),
12-
"GPT-4 (The best/fastest provider)": ("gpt_4", "Default"),
11+
"GPT-3.5 (Fastest provider)": ("gpt_35_long", "Default"),
12+
"GPT-4 (Fastest provider)": ("gpt_4", "Default"),
1313
"Bing (GPT-4)": ("gpt_4", "Bing"),
1414
"ChatBase (GPT-3.5)": ("gpt-3.5-turbo", "ChatBase"),
1515
"ChatgptAi (GPT-3.5)": ("gpt-3.5-turbo", "ChatgptAi"),
1616
"FreeGpt (GPT-3.5)": ("gpt-3.5-turbo", "FreeGpt"),
1717
"GptGo (GPT-3.5)": ("gpt-3.5-turbo", "GptGo"),
1818
"You (GPT-3.5)": ("gpt-3.5-turbo", "You"),
19-
"Llama (Llama 2 7B)": ("meta/llama-2-7b-chat", "Llama2"),
20-
"Llama (Llama 2 13B)": ("meta/llama-2-13b-chat", "Llama2"),
21-
"Llama (Llama 2 70B)": ("meta/llama-2-70b-chat", "Llama2"),
19+
"Llama (Llama 3 8B)": ("meta/meta-llama-3-8b-instruct", "Llama"),
20+
"Llama (Llama 3 70B)": ("meta/meta-llama-3-70b-instruct", "Llama"),
2221
}
2322

2423

@@ -44,8 +43,4 @@ async def get_chat_response(
4443

4544

4645
def retrieve_available_providers() -> list[str]:
47-
return [
48-
key
49-
for key in MODELS_AND_PROVIDERS
50-
if is_provider_active(MODELS_AND_PROVIDERS[key]) or "Default" in MODELS_AND_PROVIDERS[key]
51-
]
46+
return [key for key, value in MODELS_AND_PROVIDERS.items() if is_provider_active(value) or "Default" in value]

hiroshi/utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ async def run_monitoring(context: ContextTypes.DEFAULT_TYPE) -> None:
297297

298298
def is_provider_active(model_and_provider_names: tuple[str, str]) -> bool:
299299
_, provider_name = model_and_provider_names
300+
if provider_name == "Llama":
301+
return True # TODO: Temporary solution, because Llama is turned off accidentally on the gpt4free side
300302
if provider := ProviderUtils.convert.get(provider_name):
301303
return bool(provider.working)
302304
return False

main.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import asyncio
2+
from asyncio import Task
3+
from typing import Any, Coroutine
24

35
from loguru import logger
46
from telegram import (
@@ -38,6 +40,7 @@
3840

3941
class HiroshiBot:
4042
def __init__(self) -> None:
43+
self.background_tasks: set[Task[Any]] = set()
4144
self.commands = [
4245
BotCommand(command="about", description="About this bot"),
4346
BotCommand(command="help", description="Show the help message"),
@@ -53,6 +56,11 @@ def __init__(self) -> None:
5356
BotCommand(command="provider", description="Select GPT provider"),
5457
]
5558

59+
def create_task(self, task: Coroutine[Any, Any, Any]) -> None:
60+
task_scheduled = asyncio.create_task(task)
61+
self.background_tasks.add(task_scheduled)
62+
task_scheduled.add_done_callback(self.background_tasks.discard)
63+
5664
async def help(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
5765
telegram_message = get_telegram_message(update=update)
5866
commands = [f"/{command.command} - {command.description}" for command in self.commands]
@@ -75,7 +83,7 @@ async def about(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> Non
7583
@check_user_allowance
7684
@check_user_allow_to_apply_settings
7785
async def reset(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
78-
asyncio.create_task(handle_reset(update=update, context=context))
86+
self.create_task(task=handle_reset(update=update, context=context))
7987

8088
@check_user_allowance
8189
async def prompt(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
@@ -93,11 +101,11 @@ async def prompt(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
93101
and not user_interacts_with_bot(update=update, context=context)
94102
):
95103
return None
96-
asyncio.create_task(handle_prompt(update=update, context=context))
104+
self.create_task(task=handle_prompt(update=update, context=context))
97105

98106
@check_user_allowance
99107
async def ask(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
100-
asyncio.create_task(handle_prompt(update=update, context=context))
108+
self.create_task(task=handle_prompt(update=update, context=context))
101109

102110
@check_user_allowance
103111
@check_user_allow_to_apply_settings
@@ -109,7 +117,7 @@ async def show_menu(self, update: Update, context: ContextTypes.DEFAULT_TYPE) ->
109117

110118
@check_user_allow_to_apply_settings
111119
async def select_provider(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
112-
asyncio.create_task(handle_provider_selection(update=update, context=context))
120+
self.create_task(task=handle_provider_selection(update=update, context=context))
113121

114122
@check_user_allowance
115123
async def inline_query(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
@@ -139,8 +147,8 @@ def run(self) -> None:
139147
app = (
140148
ApplicationBuilder()
141149
.token(telegram_settings.token)
142-
.proxy_url(telegram_settings.proxy)
143-
.get_updates_proxy_url(telegram_settings.proxy)
150+
.proxy(telegram_settings.proxy)
151+
.get_updates_proxy(telegram_settings.proxy)
144152
.post_init(self.post_init)
145153
.build()
146154
)

0 commit comments

Comments
 (0)