Text Generation
Russian
conversational
IlyaGusev commited on
Commit
46085bb
1 Parent(s): c5f6cb9

Initial commit

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. ggml-model-q4_1.bin +3 -0
  3. interact.py +65 -0
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ ggml-model-q4_1.bin filter=lfs diff=lfs merge=lfs -text
ggml-model-q4_1.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4e6bf295d3e2eee786610e147b885193a148425df46d8ac2e45b61151dd7172
3
+ size 24399792512
interact.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fire
2
+ from llama_cpp import Llama
3
+
4
+ MESSAGE_TEMPLATE = "{role}\n{content}"
5
+ SYSTEM_PROMPT = "Ты — Сайга, русскоязычный автоматический ассистент. Ты разговариваешь с людьми и помогаешь им."
6
+ BOT_TOKEN = 9225
7
+ LINEBREAK_TOKEN = 13
8
+
9
+
10
+ def get_message_tokens(model, role, content):
11
+ message_text = MESSAGE_TEMPLATE.format(role=role, content=content)
12
+ message_tokens = model.tokenize(message_text.encode("utf-8"))
13
+ message_tokens.append(model.token_eos())
14
+ return message_tokens
15
+
16
+
17
+ def get_system_tokens(model):
18
+ system_message = {
19
+ "role": "system",
20
+ "content": SYSTEM_PROMPT
21
+ }
22
+ return get_message_tokens(model, **system_message)
23
+
24
+
25
+ def interact(
26
+ model_path,
27
+ n_ctx=2000,
28
+ top_k=30,
29
+ top_p=0.9,
30
+ temperature=0.2,
31
+ repeat_penalty=1.1
32
+ ):
33
+ model = Llama(
34
+ model_path=model_path,
35
+ n_ctx=n_ctx,
36
+ n_parts=1,
37
+ )
38
+
39
+ system_tokens = get_system_tokens(model)
40
+ tokens = system_tokens
41
+ model.eval(tokens)
42
+
43
+ while True:
44
+ user_message = input("User: ")
45
+ message_tokens = get_message_tokens(model=model, role="user", content=user_message)
46
+ role_tokens = [model.token_bos(), BOT_TOKEN, LINEBREAK_TOKEN]
47
+ tokens += message_tokens + role_tokens
48
+ generator = model.generate(
49
+ tokens,
50
+ top_k=top_k,
51
+ top_p=top_p,
52
+ temp=temperature,
53
+ repeat_penalty=repeat_penalty
54
+ )
55
+ for token in generator:
56
+ token_str = model.detokenize([token]).decode("utf-8")
57
+ tokens.append(token)
58
+ if token == model.token_eos():
59
+ break
60
+ print(token_str, end="", flush=True)
61
+ print()
62
+
63
+
64
+ if __name__ == "__main__":
65
+ fire.Fire(interact)