-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathneuron.py
36 lines (32 loc) · 1.22 KB
/
neuron.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import mc
from utils import get_api
import os
from aiofile import AIOFile
from utils import USUAL_SYNTAX
async def write_words(*args):
text, file = args
async with AIOFile(file, "a", encoding="utf-8") as f:
text = text.replace("\n", ". ").replace("\n\n", ". ")
await f.write(text + ",")
async def send_and_gen_sentence(*args):
file, peer_id = args
if not os.path.exists(file):
message = "База слов для этой беседы ещё не существует"
await get_api().messages.send(
peer_id=peer_id, message=message, random_id=0
)
return
async with AIOFile(file, encoding="utf-8") as f:
text = await f.read()
text_model = [sample.strip() for sample in text.split(",")]
generator = mc.StringGenerator(samples=text_model)
message = generator.generate_string(
attempts=20,
validator=mc.validators.words_count(minimal=1, maximal=15),
formatter=mc.formatters.usual_syntax if USUAL_SYNTAX else None,
)
if not message:
message = "База слов слишком мала для генерации"
await get_api().messages.send(
peer_id=peer_id, message=message, random_id=0
)