Conditions | 5 |
Total Lines | 54 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # -*- coding: utf-8 -*- |
||
33 | @rate_limit(3, 'message') |
||
34 | @dp.message_handler() |
||
35 | async def processing_message(message: types.Message, state: FSMContext): |
||
36 | |||
37 | """ |
||
38 | |||
39 | The function is designed to receive messages in russian and generate a response. |
||
40 | |||
41 | """ |
||
42 | |||
43 | await types.ChatActions.typing() |
||
44 | |||
45 | data_storage = await state.get_data() |
||
46 | text = message.text.lower() |
||
47 | |||
48 | await state.update_data(history_text=text) |
||
49 | await state.update_data(chat_id=message.chat.id) |
||
50 | await state.update_data(first_name=message.from_user.first_name) |
||
51 | |||
52 | input_text, check_question = encoding_text(text_encode=text) |
||
53 | |||
54 | if 'history_text' in data_storage: |
||
55 | |||
56 | if text == data_storage['history_text']: |
||
57 | |||
58 | await message.answer(text="Ой... Где-то я уже это видел! 🥱") |
||
59 | |||
60 | # input_text = torch.cat([context.chat_data['output'][-1], input_text[0]], dim=0) |
||
61 | # input_text = input_text.unsqueeze(0) |
||
62 | |||
63 | return |
||
64 | |||
65 | text_gpt3 = get_text_gpt3(text_gpt=input_text, check_question=check_question) |
||
66 | output_text = decoding_text(text_decode=text_gpt3) |
||
67 | |||
68 | if len(output_text.split()) < 1: |
||
69 | |||
70 | await zero_output(message) |
||
71 | |||
72 | return |
||
73 | |||
74 | await message.answer(text=output_text) |
||
75 | |||
76 | if 'input' in data_storage: |
||
77 | |||
78 | await state.update_data(input=input_text) |
||
79 | await state.update_data(output=text_gpt3) |
||
80 | |||
81 | return |
||
82 | |||
83 | data_history = {'input': [input_text], |
||
84 | 'output': [text_gpt3]} |
||
85 | |||
86 | await state.update_data(data_history) |
||
87 |