Alyafeai commited on
Commit
4aee7a9
1 Parent(s): aa69e53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -115,17 +115,19 @@ def format_chat_prompt(
115
  instructions: str,
116
  user_name: str,
117
  bot_name: str,
118
- include_chat_history: bool = True,
 
119
  ) -> str:
120
  instructions = instructions.strip()
121
  prompt = instructions
122
- if include_chat_history:
123
- for turn in chat_history:
124
- user_message, bot_message = turn
125
- prompt = f"{prompt}\n{user_name}: {user_message}\n{bot_name}: {bot_message}"
126
- prompt = f"{prompt}\n{user_name}: {message}\n{bot_name}:"
127
- else:
128
- prompt = f"{prompt}\n{user_name}: {message}\n{bot_name}:"
 
129
  return prompt
130
 
131
 
@@ -174,6 +176,7 @@ def chat_tab():
174
  "do_sample": True,
175
  "top_p": top_p,
176
  "stop": ["User:"],
 
177
  },
178
  "stream": True,
179
  "session_id": session_id,
@@ -195,9 +198,10 @@ def chat_tab():
195
  break
196
  else:
197
  yield full_output
198
- if full_output == "":
 
199
  payload["data"]["inputs"] = format_chat_prompt(
200
- message, history, instructions, user_name, bot_name, False
201
  )
202
  with sess.post(
203
  ENDPOINT_URL, headers=HEADERS, json=payload, stream=True
@@ -212,6 +216,7 @@ def chat_tab():
212
  break
213
  else:
214
  yield full_output
 
215
  return ""
216
 
217
  with gr.Column():
 
115
  instructions: str,
116
  user_name: str,
117
  bot_name: str,
118
+ include_all_chat_history: bool = True,
119
+ index : int = 1
120
  ) -> str:
121
  instructions = instructions.strip()
122
  prompt = instructions
123
+ if not include_all_chat_history:
124
+ if index >= 0:
125
+ index = -index
126
+ chat_history = chat_history[index:]
127
+ for turn in chat_history:
128
+ user_message, bot_message = turn
129
+ prompt = f"{prompt}\n{user_name}: {user_message}\n{bot_name}: {bot_message}"
130
+ prompt = f"{prompt}\n{user_name}: {message}\n{bot_name}:"
131
  return prompt
132
 
133
 
 
176
  "do_sample": True,
177
  "top_p": top_p,
178
  "stop": ["User:"],
179
+ "temperature" : 0.7
180
  },
181
  "stream": True,
182
  "session_id": session_id,
 
198
  break
199
  else:
200
  yield full_output
201
+ last_n = 5
202
+ while full_output == "" and last_n > 0:
203
  payload["data"]["inputs"] = format_chat_prompt(
204
+ message, history, instructions, user_name, bot_name, False, last_n
205
  )
206
  with sess.post(
207
  ENDPOINT_URL, headers=HEADERS, json=payload, stream=True
 
216
  break
217
  else:
218
  yield full_output
219
+ last_n -= 1
220
  return ""
221
 
222
  with gr.Column():