JTh34 commited on
Commit
a22bccb
·
1 Parent(s): 12ba996

Remove <|eot_id|>

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -143,7 +143,6 @@ hf_llm = HuggingFaceEndpoint(
143
  def rename(original_author: str):
144
  """
145
  This function can be used to rename the 'author' of a message.
146
-
147
  In this case, we're overriding the 'Assistant' author to be 'Paul Graham Essay Bot'.
148
  """
149
  rename_dict = {
@@ -155,9 +154,7 @@ def rename(original_author: str):
155
  async def start_chat():
156
  """
157
  This function will be called at the start of every user session.
158
-
159
  We will build our LCEL RAG chain here, and store it in the user session.
160
-
161
  The user session is a dictionary that is unique to each user session, and is stored in the memory of the server.
162
  """
163
 
@@ -172,19 +169,24 @@ async def start_chat():
172
  async def main(message: cl.Message):
173
  """
174
  This function will be called every time a message is recieved from a session.
175
-
176
  We will use the LCEL RAG chain to generate a response to the user query.
177
-
178
  The LCEL RAG chain is stored in the user session, and is unique to each user session - this is why we can access it here.
179
  """
180
  lcel_rag_chain = cl.user_session.get("lcel_rag_chain")
181
 
182
  msg = cl.Message(content="")
183
-
 
184
  for chunk in await cl.make_async(lcel_rag_chain.stream)(
185
  {"query": message.content},
186
  config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
187
  ):
 
 
 
188
  await msg.stream_token(chunk)
189
 
 
 
 
190
  await msg.send()
 
143
  def rename(original_author: str):
144
  """
145
  This function can be used to rename the 'author' of a message.
 
146
  In this case, we're overriding the 'Assistant' author to be 'Paul Graham Essay Bot'.
147
  """
148
  rename_dict = {
 
154
  async def start_chat():
155
  """
156
  This function will be called at the start of every user session.
 
157
  We will build our LCEL RAG chain here, and store it in the user session.
 
158
  The user session is a dictionary that is unique to each user session, and is stored in the memory of the server.
159
  """
160
 
 
169
  async def main(message: cl.Message):
170
  """
171
  This function will be called every time a message is recieved from a session.
 
172
  We will use the LCEL RAG chain to generate a response to the user query.
 
173
  The LCEL RAG chain is stored in the user session, and is unique to each user session - this is why we can access it here.
174
  """
175
  lcel_rag_chain = cl.user_session.get("lcel_rag_chain")
176
 
177
  msg = cl.Message(content="")
178
+
179
+ response_text = ""
180
  for chunk in await cl.make_async(lcel_rag_chain.stream)(
181
  {"query": message.content},
182
  config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
183
  ):
184
+ # Remove the <|eot_id|> token from the response
185
+ chunk = chunk.replace("<|eot_id|>", "")
186
+ response_text += chunk
187
  await msg.stream_token(chunk)
188
 
189
+ # If the token is at the end, make sure it is properly removed
190
+ final_response = response_text.replace("<|eot_id|>", "")
191
+ msg.content = final_response
192
  await msg.send()