mayedatariq commited on
Commit
f3efcd0
·
verified ·
1 Parent(s): fa885a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -6,7 +6,6 @@ client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
6
 
7
  def respond(message, history):
8
 
9
- # System message
10
  messages = [
11
  {
12
  "role": "system",
@@ -14,8 +13,11 @@ def respond(message, history):
14
  }
15
  ]
16
 
17
- # Convert Gradio history format
18
- for user_msg, bot_msg in history:
 
 
 
19
 
20
  messages.append({
21
  "role": "user",
@@ -27,16 +29,13 @@ def respond(message, history):
27
  "content": bot_msg
28
  })
29
 
30
- # Add latest user message
31
  messages.append({
32
  "role": "user",
33
  "content": message
34
  })
35
 
36
- # Store streamed response
37
  partial_response = ""
38
 
39
- # Stream response
40
  stream = client.chat_completion(
41
  messages=messages,
42
  max_tokens=100,
@@ -45,12 +44,11 @@ def respond(message, history):
45
  stream=True
46
  )
47
 
48
- # Receive tokens one by one
49
  for chunk in stream:
50
 
51
  token = chunk.choices[0].delta.content
52
 
53
- if token is not None:
54
 
55
  partial_response += token
56
 
 
6
 
7
  def respond(message, history):
8
 
 
9
  messages = [
10
  {
11
  "role": "system",
 
13
  }
14
  ]
15
 
16
+ # history format for newer Gradio versions
17
+ for item in history:
18
+
19
+ user_msg = item["user"]
20
+ bot_msg = item["assistant"]
21
 
22
  messages.append({
23
  "role": "user",
 
29
  "content": bot_msg
30
  })
31
 
 
32
  messages.append({
33
  "role": "user",
34
  "content": message
35
  })
36
 
 
37
  partial_response = ""
38
 
 
39
  stream = client.chat_completion(
40
  messages=messages,
41
  max_tokens=100,
 
44
  stream=True
45
  )
46
 
 
47
  for chunk in stream:
48
 
49
  token = chunk.choices[0].delta.content
50
 
51
+ if token:
52
 
53
  partial_response += token
54