You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is like a chatbot, You can start the conversation with `Hi, can you help me ?` Pay attention though that it may hallucinate!
71
+
66
72
positional arguments:
67
73
model The path of the model file
68
74
@@ -92,8 +98,8 @@ options:
92
98
--repeat_penalty REPEAT_PENALTY
93
99
repeat_penalty
94
100
--n_batch N_BATCH batch size for prompt processing
95
-
96
101
```
102
+
97
103
# Tutorial
98
104
99
105
### Quick start
@@ -113,7 +119,7 @@ You can set up an interactive dialogue by simply keeping the `model` variable al
113
119
```python
114
120
from pyllamacpp.model import Model
115
121
116
-
model = Model(ggml_model='./models/gpt4all-model.bin')
122
+
model = Model(model_path='/path/to/ggml/model')
117
123
whileTrue:
118
124
try:
119
125
prompt =input("You: ", flush=True)
@@ -126,40 +132,62 @@ while True:
126
132
exceptKeyboardInterrupt:
127
133
break
128
134
```
129
-
### Different persona
130
-
You can customize the `prompt_context` to _"give the language model a different persona"_ as follows:
135
+
### Attribute a persona to the language model
136
+
137
+
The following is an example showing how to _"attribute a persona to the language model"_ :
131
138
132
139
```python
133
140
from pyllamacpp.model import Model
134
141
135
-
prompt_context =""" Act as Bob. Bob is helpful, kind, honest, good at writing, and never fails to answer the User's requests immediately and with precision. To do this, Bob uses a database of information collected from many different sources, including books, journals, online articles, and more.
142
+
prompt_context ="""Act as Bob. Bob is helpful, kind, honest,
143
+
and never fails to answer the User's requests immediately and with precision.
136
144
137
145
User: Nice to meet you Bob!
138
146
Bob: Welcome! I'm here to assist you with anything you need. What can I do for you today?
139
147
"""
140
148
141
-
prompt_prefix ="\n User:"
142
-
prompt_suffix ="\n Bob:"
149
+
prompt_prefix ="\nUser:"
150
+
prompt_suffix ="\nBob:"
143
151
144
-
model = Model(ggml_model=model, n_ctx=512, prompt_context=prompt_context, prompt_prefix=prompt_prefix,
152
+
model = Model(model_path='/path/to/ggml/model',
153
+
prompt_context=prompt_context,
154
+
prompt_prefix=prompt_prefix,
145
155
prompt_suffix=prompt_suffix)
146
156
157
+
sequence =''
158
+
stop_word = prompt_prefix.strip()
159
+
147
160
whileTrue:
148
161
try:
149
162
prompt =input("You: ")
150
163
if prompt =='':
151
164
continue
152
-
print(f"Bob:", end='')
153
-
for tok in model.generate(prompt):
154
-
print(f"{tok}", end='', flush=True)
165
+
print(f"AI: ", end='')
166
+
for token in model.generate(prompt):
167
+
if token =='\n':
168
+
sequence += token
169
+
continue
170
+
iflen(sequence) !=0:
171
+
if stop_word.startswith(sequence.strip()):
172
+
sequence += token
173
+
if sequence.strip() == stop_word:
174
+
sequence =''
175
+
break
176
+
else:
177
+
continue
178
+
else:
179
+
print(f"{sequence}", end='', flush=True)
180
+
sequence =''
181
+
print(f"{token}", end='', flush=True)
182
+
155
183
print()
156
184
exceptKeyboardInterrupt:
157
185
break
158
-
159
186
```
160
187
161
188
162
-
You can always refer to the [short documentation](https://abdeladim-s.github.io/pyllamacpp/) for more details.
189
+
# API reference
190
+
You can check the [API reference documentation](https://abdeladim-s.github.io/pyllamacpp/) for more details.
0 commit comments