1- from telegram_assistant .parser .repository .parser_repo import ParserRepo
1+ from telegram_assistant .parser .repository .parser_repo import ParserRepository
22
33
44class ContextManager :
5- def __init__ (self ):
6- self .parser_repo = ParserRepo ()
5+ def __init__ (self ) -> None :
6+ self .parser_repo = ParserRepository ()
77 self .questions_ids : dict [int , str ] = {
88 "1" : "Расскажи о ЮФУ" ,
99 "2" : "Расскажи о поступлении в ЮФУ" ,
10- "3" : "Расскажи о последних мероприятих ЮФУ" ,
11- }
10+ "3" : "Расскажи о последних мероприятиях ЮФУ\
11+ (Основываясь на данных, которые тебе предоставлены)\
12+ (Расскажи о них, но без таких строк 'В сообщении содержится информация о след мероприятиях ЮФУ')" ,
13+ }
1214 self .context_dictionary = {
13- "Расскажи о поступлении в ЮФУ " : "context_admission .txt" ,
14- "Расскажи о последних мероприятих ЮФУ " : "context_events .txt" ,
15- "Расскажи о ЮФУ " : "context_SFU_description .txt" ,
15+ "1 " : "context_SFU_description .txt" ,
16+ "2 " : "context_admission .txt" ,
17+ "3 " : "context_events .txt" ,
1618 }
17-
19+
1820 def create_base_context (self ) -> None :
19- admission = self .parser_repo .base_parser .parse_admission_rules ()
21+ university_info = self .parser_repo .base_parser .parse_university_info ()
2022 self .save_context (
21- "Расскажи о поступлении в ЮФУ " ,
22- admission
23+ "1 " ,
24+ university_info ,
2325 )
24- vk_events = self .parser_repo .vk_parser . parse_vk_wall_posts ()
26+ admission = self .parser_repo .base_parser . parse_admission_rules ()
2527 self .save_context (
26- "Расскажи о последних мероприятих ЮФУ " ,
27- vk_events
28+ "2 " ,
29+ admission ,
2830 )
29- university_info = self .parser_repo .base_parser . parse_university_info ()
31+ vk_events = self .parser_repo .vk_parser . parse_vk_wall_posts ()
3032 self .save_context (
31- "Расскажи о ЮФУ " ,
32- university_info
33+ "3 " ,
34+ vk_events ,
3335 )
34-
35- def save_context (self , question : str , context : str ) -> None :
36- path = f"src/telegram_assistant/llm/context/{ self .context_dictionary [question ]} "
36+
37+ def save_context (self , question_id : str , context : str ) -> None :
38+ path = f"src/telegram_assistant/llm/context/{ self .context_dictionary [question_id ]} "
3739 with open (path , "w" , encoding = "utf-8" ) as file :
3840 file .write (context )
3941
40- def get_context (self , question : str ) -> str :
41- if not ( question in self .context_dictionary .keys () ):
42+ def get_context (self , question_id : str ) -> str :
43+ if question_id not in self .context_dictionary .keys ():
4244 raise Exception ("Контекст вопроса не найден" )
43-
44- path = f"src/telegram_assistant/llm/context/{ self .context_dictionary [question ]} "
45- with open (path , "r" , encoding = "utf-8" ) as file :
45+
46+ path = f"src/telegram_assistant/llm/context/{ self .context_dictionary [question_id ]} "
47+ with open (path , encoding = "utf-8" ) as file :
4648 context = file .read ()
47-
49+
4850 return context
4951
50- def get_dynamic_context (self ) -> str :
51- ...
52+ def get_dynamic_context (self ) -> str : ...
0 commit comments