Datangtang commited on
Commit
37b5c7e
·
verified ·
1 Parent(s): 540a0fc

真没招了

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -15,7 +15,7 @@ MODEL_CONFIGS = {
15
  "filename": "llama-3.2-1b-instruct.Q4_K_M.gguf"
16
  },
17
  "3B Model (Datangtang/GGUF3B)": {
18
- "repo_id": "Datangtang/GGGF3B",
19
  "filename": "llama-3.2-3b-instruct.Q4_K_M.gguf"
20
  }
21
  }
@@ -73,12 +73,28 @@ def chat(message, history, model_choice):
73
  # System prompt
74
  conversation = "System: You are a helpful assistant.\n"
75
 
76
- # Add last 3 messages
77
- for human, assistant in history[-3:]:
78
- conversation += f"User: {human}\nAssistant: {assistant}\n"
79
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  conversation += f"User: {message}\nAssistant:"
81
 
 
82
  response = llm(
83
  conversation,
84
  max_tokens=128,
@@ -92,7 +108,6 @@ def chat(message, history, model_choice):
92
 
93
  return response["choices"][0]["text"].strip()
94
 
95
-
96
  # ----------------------------------------
97
  # Gradio UI
98
  # ----------------------------------------
 
15
  "filename": "llama-3.2-1b-instruct.Q4_K_M.gguf"
16
  },
17
  "3B Model (Datangtang/GGUF3B)": {
18
+ "repo_id": "Datangtang/GGUF3B",
19
  "filename": "llama-3.2-3b-instruct.Q4_K_M.gguf"
20
  }
21
  }
 
73
  # System prompt
74
  conversation = "System: You are a helpful assistant.\n"
75
 
76
+ # Convert ChatInterface history (list of dicts) into text prompt
77
+ for msg in history[-3:]:
78
+ # ChatInterface format: {"role": "...", "content": "..."}
79
+ if isinstance(msg, dict):
80
+ role = msg.get("role")
81
+ content = msg.get("content", "")
82
+ if role == "user":
83
+ conversation += f"User: {content}\n"
84
+ elif role == "assistant":
85
+ conversation += f"Assistant: {content}\n"
86
+
87
+ # Safety: old tuple format
88
+ elif isinstance(msg, list) or isinstance(msg, tuple):
89
+ human, assistant = msg
90
+ conversation += f"User: {human}\n"
91
+ if assistant:
92
+ conversation += f"Assistant: {assistant}\n"
93
+
94
+ # Add current message
95
  conversation += f"User: {message}\nAssistant:"
96
 
97
+ # Generate model response
98
  response = llm(
99
  conversation,
100
  max_tokens=128,
 
108
 
109
  return response["choices"][0]["text"].strip()
110
 
 
111
  # ----------------------------------------
112
  # Gradio UI
113
  # ----------------------------------------