muaadh019 commited on
Commit
3a79f1a
·
verified ·
1 Parent(s): 2381dd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -28,9 +28,15 @@ def chat(message, history):
28
  return "", history
29
 
30
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
31
- for human, assistant in history:
32
- messages.append({"role": "user", "content": human})
33
- messages.append({"role": "assistant", "content": assistant})
 
 
 
 
 
 
34
  messages.append({"role": "user", "content": message})
35
 
36
  try:
@@ -40,11 +46,14 @@ def chat(message, history):
40
  max_tokens=2048
41
  )
42
  reply = response.choices[0].message.content
43
- history.append((message, reply))
 
 
44
  return "", history
45
 
46
  except Exception as e:
47
- history.append((message, f" خطأ: {str(e)}"))
 
48
  return "", history
49
 
50
  css = """
@@ -94,6 +103,7 @@ with gr.Blocks(title="درع - المساعد الأمني العربي") as dem
94
  height=500,
95
  show_label=False,
96
  rtl=True,
 
97
  avatar_images=(
98
  "https://api.dicebear.com/7.x/avataaars/svg?seed=user",
99
  "https://api.dicebear.com/7.x/bottts/svg?seed=shield"
 
28
  return "", history
29
 
30
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
31
+
32
+ for item in history:
33
+ if isinstance(item, dict):
34
+ messages.append({"role": item["role"], "content": item["content"]})
35
+ else:
36
+ human, assistant = item
37
+ messages.append({"role": "user", "content": human})
38
+ messages.append({"role": "assistant", "content": assistant})
39
+
40
  messages.append({"role": "user", "content": message})
41
 
42
  try:
 
46
  max_tokens=2048
47
  )
48
  reply = response.choices[0].message.content
49
+
50
+ history.append({"role": "user", "content": message})
51
+ history.append({"role": "assistant", "content": reply})
52
  return "", history
53
 
54
  except Exception as e:
55
+ history.append({"role": "user", "content": message})
56
+ history.append({"role": "assistant", "content": f"❌ خطأ: {str(e)}"})
57
  return "", history
58
 
59
  css = """
 
103
  height=500,
104
  show_label=False,
105
  rtl=True,
106
+ type="messages",
107
  avatar_images=(
108
  "https://api.dicebear.com/7.x/avataaars/svg?seed=user",
109
  "https://api.dicebear.com/7.x/bottts/svg?seed=shield"