yzhuang commited on
Commit
7ab546e
·
verified ·
1 Parent(s): 1f72aba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -6,11 +6,12 @@ API_URL = "http://0.0.0.0:8000/v1/chat/completions"
6
  def stream_completion(message, history, max_tokens, temperature, top_p, beta):
7
  """Gradio callback: stream the assistant’s reply token-by-token."""
8
  # -------- build OpenAI-style message list (no system prompt) -------------
9
- messages = [{"role": "user", "content": u} # past user turns
10
- if i % 2 == 0 else # even idx → user
11
- {"role": "assistant", "content": u} # odd idx → assistant
12
- for i, (u, _) in enumerate(sum(([h[0], h[1]] for h in history), []))
13
- if u] # drop empty strings
 
14
  messages.append({"role": "user", "content": message})
15
 
16
  payload = {
 
6
  def stream_completion(message, history, max_tokens, temperature, top_p, beta):
7
  """Gradio callback: stream the assistant’s reply token-by-token."""
8
  # -------- build OpenAI-style message list (no system prompt) -------------
9
+ for user_msg, assistant_msg in history:
10
+ if user_msg: # past user turn
11
+ messages.append({"role": "user", "content": user_msg})
12
+ if assistant_msg: # past assistant turn
13
+ messages.append({"role": "assistant", "content": assistant_msg})
14
+
15
  messages.append({"role": "user", "content": message})
16
 
17
  payload = {