Spaces:
Sleeping
Sleeping
armandstrickernlp
commited on
Commit
·
1a8e94e
1
Parent(s):
67f4fec
create chatbot
Browse files
app.py
CHANGED
@@ -14,15 +14,23 @@ def generate_response(prompt):
|
|
14 |
return tokenizer_TOD.batch_decode(outputs)[0]
|
15 |
|
16 |
#<|context|> <|user|> I want to go to the restaurant.<|endofcontext|>
|
|
|
17 |
|
18 |
def chat(message, history):
|
19 |
history = history or []
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
context, response = output.split('<|endofcontext|>')
|
24 |
|
25 |
-
history.append((
|
26 |
|
27 |
return history, history
|
28 |
|
|
|
14 |
return tokenizer_TOD.batch_decode(outputs)[0]
|
15 |
|
16 |
#<|context|> <|user|> I want to go to the restaurant.<|endofcontext|>
|
17 |
+
context = ''
|
18 |
|
19 |
def chat(message, history):
|
20 |
history = history or []
|
21 |
+
if history == []:
|
22 |
+
context = '<|context|> <|user|> ' + message + ' <|endofcontext|> '
|
23 |
+
else:
|
24 |
+
context, _ = history[-1][0].split('<|endofcontext|>')
|
25 |
+
context += ' <|system|> '
|
26 |
+
context += history[-1][1].split('<|response|>')[1]
|
27 |
+
context = context.replace('<|endofresponse|>', '')
|
28 |
+
context += ' <|user|> ' + message + ' <|endofcontext|> '
|
29 |
+
|
30 |
+
output = generate_response(context)
|
31 |
context, response = output.split('<|endofcontext|>')
|
32 |
|
33 |
+
history.append((message, response))
|
34 |
|
35 |
return history, history
|
36 |
|