gururise commited on
Commit
73a5dc2
·
1 Parent(s): 674ab76

few more chatbot fixes

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -127,6 +127,7 @@ def chat(
127
  if len(history) == 0:
128
  # no history, so lets reset chat state
129
  model.resetState()
 
130
  print("reset chat state")
131
  intro = '''The following is a verbose and detailed conversation between an AI assistant called FRITZ, and a human user called USER. FRITZ is intelligent, knowledgeable, wise and polite.
132
 
@@ -141,8 +142,10 @@ FRITZ: The answer is a=7, because 9-7 = 2.
141
  USER: wat is lhc
142
  FRITZ: The Large Hadron Collider (LHC) is a high-energy particle collider, built by CERN, and completed in 2008. It was used to confirm the existence of the Higgs boson in 2012.
143
  USER: Tell me about yourself.
144
- FRITZ: I am an RNN based Large Language Model (LLM) that use no attention layers unlike most other LLM's which are transformer based.
145
  '''
 
 
146
 
147
  max_new_tokens = int(max_new_tokens)
148
  temperature = float(temperature)
@@ -164,20 +167,15 @@ FRITZ: I am an RNN based Large Language Model (LLM) that use no attention layers
164
 
165
  model.loadContext(newctx=intro+prompt)
166
 
167
- generated_text = model.forward(number=max_new_tokens, stopStrings=["<|endoftext|>","USER:"],temp=temperature,top_p_usual=top_p)["output"]
168
 
169
- generated_text = generated_text.lstrip("\n ")
170
  generated_text = generated_text.rstrip("USER:")
171
  print(f"{generated_text}")
172
- '''
173
- for stop_word in stop:
174
- stop_word = codecs.getdecoder("unicode_escape")(stop_word)[0]
175
- if stop_word != '' and stop_word in generated_text:
176
- generated_text = generated_text[:generated_text.find(stop_word)]
177
- '''
178
  gc.collect()
179
- history.append((prompt, generated_text))
180
- return history,history
181
 
182
 
183
  examples = [
 
127
  if len(history) == 0:
128
  # no history, so lets reset chat state
129
  model.resetState()
130
+ history = [[],model.emptyState]
131
  print("reset chat state")
132
  intro = '''The following is a verbose and detailed conversation between an AI assistant called FRITZ, and a human user called USER. FRITZ is intelligent, knowledgeable, wise and polite.
133
 
 
142
  USER: wat is lhc
143
  FRITZ: The Large Hadron Collider (LHC) is a high-energy particle collider, built by CERN, and completed in 2008. It was used to confirm the existence of the Higgs boson in 2012.
144
  USER: Tell me about yourself.
145
+ FRITZ: My name is Fritz. I am an RNN based Large Language Model (LLM) that use no attention layers unlike most other LLM's which are transformer based.
146
  '''
147
+ else:
148
+ model.setState(history[1])
149
 
150
  max_new_tokens = int(max_new_tokens)
151
  temperature = float(temperature)
 
167
 
168
  model.loadContext(newctx=intro+prompt)
169
 
170
+ out = model.forward(number=max_new_tokens, stopStrings=["<|endoftext|>","USER:"],temp=temperature,top_p_usual=top_p)
171
 
172
+ generated_text = out["output"].lstrip("\n ")
173
  generated_text = generated_text.rstrip("USER:")
174
  print(f"{generated_text}")
175
+
 
 
 
 
 
176
  gc.collect()
177
+ history[0].append((prompt, generated_text))
178
+ return history[0],[history[0],out["state"]]
179
 
180
 
181
  examples = [