Skip to content

Commit 6dc0f89

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents f339a64 + aec69a8 commit 6dc0f89

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

kibernikto/bots/cybernoone/_cybernoone.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ async def heed_and_reply(self, message: str, author=NOT_GIVEN, save_to_history=T
5858
print(traceback.format_exc())
5959
return f"Я не справился! Горе мне! {str(e)}"
6060

61-
def _reset(self):
61+
def _reset(self, **kwargs):
6262
"""
6363
Adding additional data to default system message
6464
6565
:return:
6666
"""
67-
super()._reset()
67+
super()._reset(**kwargs)
6868
wai = self.full_config.who_am_i.format(self.full_config.name)
6969
if self.chat_info and self.add_chat_info:
7070
conversation_information = self._get_telegram_chat_info()
@@ -74,19 +74,18 @@ def _reset(self):
7474
def _get_telegram_chat_info(self):
7575
if self.chat_info is None:
7676
return ""
77+
chat_descr_string = "[Static info from client app]\n"
7778
if self.chat_info.is_personal:
78-
chat_descr_string = "[Interlocutor info]"
7979
chat_descr_string += f"Name: {self.chat_info.aiogram_user.full_name}."
8080
if self.chat_info.bio:
8181
chat_descr_string += f"Bio: {self.chat_info.bio}."
8282
if self.chat_info.birthday:
8383
chat_descr_string += f"Birthday: {self.chat_info.birthday}."
8484
else:
85-
chat_descr_string = "Chat group info:\n"
8685
chat_descr_string += f"Title: {self.chat_info.full_name}."
8786
if self.chat_info.description:
8887
chat_descr_string += f"Description: {self.chat_info.description}."
89-
chat_descr_string = f"{chat_descr_string}"
88+
chat_descr_string = f"{chat_descr_string}\n[End static info from client app]\n"
9089

9190
# print(f"{self.__class__.__name__}: {chat_descr_string}")
9291
return chat_descr_string
@@ -106,8 +105,8 @@ async def update_configuration(self, config_to_use: OpenAiExecutorConfig):
106105
self.tools = config_to_use.tools
107106

108107
print(f'- {self.__class__.__name__} for "{self.chat_info.full_name}" (id: {self.full_config.id}) update!')
109-
print(f'- {self.tools_names}')
110-
print(f'- {self.max_messages}')
111-
print(f'- {self.model}')
112-
print(f'- {self.full_config.who_am_i}')
108+
# print(f'- {self.tools_names}')
109+
# print(f'- {self.max_messages}')
110+
# print(f'- {self.model}')
111+
# print(f'- {self.full_config.who_am_i}')
113112
self._reset()

kibernikto/interactors/llm_executor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class LLMExecutorConfig(BaseModel):
3939
summarize_request: str | None = AI_SETTINGS.OPENAI_SUMMARY
4040
max_words_before_summary: int = AI_SETTINGS.OPENAI_MAX_WORDS
4141
tool_call_hole_deepness: int = AI_SETTINGS.OPENAI_TOOLS_DEEPNESS_LEVEL
42-
reaction_calls: list = ('никто', 'хонда', 'урод')
42+
reaction_calls: list = ['никто', 'хонда', 'урод'],
4343
tools: List[Toolbox] = []
4444
hide_errors: bool = False
4545

kibernikto/interactors/openai_executor.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class OpenAiExecutorConfig(BaseModel):
3838
summarize_request: str | None = AI_SETTINGS.OPENAI_SUMMARY
3939
max_words_before_summary: int = AI_SETTINGS.OPENAI_MAX_WORDS
4040
tool_call_hole_deepness: int = AI_SETTINGS.OPENAI_TOOLS_DEEPNESS_LEVEL
41-
reaction_calls: list = ('никто', 'хонда', 'урод')
41+
reaction_calls: list = ['никто', 'хонда', 'урод']
4242
tools: List[Toolbox] = []
4343
hide_errors: bool = False
4444
app_id: str = AI_SETTINGS.OPENAI_INSTANCE_ID
@@ -170,9 +170,19 @@ async def heed(self, message, author=None):
170170
self.reset_if_usercall(message)
171171
pass
172172

173-
async def single_request(self, message, model=None, response_type: Literal['text', 'json_object'] = 'text'):
173+
async def single_request(self, message, model=None, response_type: Literal['text', 'json_object'] = 'text',
174+
additional_content: dict = None):
174175
this_message = dict(content=f"{message}", role=OpenAIRoles.user.value)
175176

177+
if additional_content:
178+
this_message = {
179+
"role": "user",
180+
"content": [
181+
{"type": "text", "text": message},
182+
additional_content
183+
]
184+
}
185+
176186
response_format = {"type": response_type}
177187

178188
headers = self.default_headers
@@ -240,9 +250,12 @@ async def _run_for_messages(self, full_prompt, author=NOT_GIVEN,
240250
usage_dict = self.process_usage(completion.usage)
241251
return choice, usage_dict
242252

243-
async def heed_and_reply(self, message: str, author=NOT_GIVEN, save_to_history=True,
244-
response_type: Literal['text', 'json_object'] = 'text',
245-
additional_content: dict = None, with_history: bool = True) -> str:
253+
async def heed_and_reply(self, **kwargs):
254+
return await self.request_llm(**kwargs)
255+
256+
async def request_llm(self, message: str, author=NOT_GIVEN, save_to_history=True,
257+
response_type: Literal['text', 'json_object'] = 'text',
258+
additional_content: dict = None, with_history: bool = True) -> str:
246259
"""
247260
Sends message to OpenAI and receives response. Can preprocess user message and work before actual API call.
248261
:param additional_content: for example type: image_url

kibernikto/utils/environment.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
from kibernikto.bots.ai_settings import AI_SETTINGS
1+
from kibernikto.bots.ai_settings import AI_SETTINGS, AiSettings
22

33
import logging
44

55
from kibernikto.plugins import KiberniktoPlugin
66

77

8-
def print_banner():
8+
def print_banner(ai_settings: AiSettings = AI_SETTINGS):
99
print("\t")
10-
print('\t%-20s%-20s' % ("avatar model:", AI_SETTINGS.OPENAI_API_MODEL))
11-
print('\t%-20s%-20s' % ("avatar host:", AI_SETTINGS.OPENAI_BASE_URL))
12-
print('\t%-20s%-20s' % ("avatar temp:", AI_SETTINGS.OPENAI_TEMPERATURE))
10+
print('\t%-20s%-20s' % ("avatar model:", ai_settings.OPENAI_API_MODEL))
11+
print('\t%-20s%-20s' % ("avatar host:", ai_settings.OPENAI_BASE_URL))
12+
print('\t%-20s%-20s' % ("avatar temp:", ai_settings.OPENAI_TEMPERATURE))
1313

1414

1515
def print_plugin_banner(kbnktp_plgn: KiberniktoPlugin):
@@ -34,16 +34,16 @@ def configure_logger():
3434
datefmt='%Y-%m-%d:%H:%M:%S',
3535
level=logging.DEBUG)
3636
logger = logging.getLogger('openai')
37-
logger.setLevel(logging.INFO)
37+
logger.setLevel(logging.WARNING)
3838

3939
logger = logging.getLogger('aiosqlite')
4040
logger.setLevel(logging.ERROR)
4141

4242
logger = logging.getLogger('httpcore')
43-
logger.setLevel(logging.INFO)
43+
logger.setLevel(logging.WARNING)
4444

4545
logger = logging.getLogger('httpx')
46-
logger.setLevel(logging.INFO)
46+
logger.setLevel(logging.WARNING)
4747

4848
logger = logging.getLogger('asyncio')
49-
logger.setLevel(logging.INFO)
49+
logger.setLevel(logging.WARNING)

0 commit comments

Comments
 (0)