QLWD commited on
Commit
248fc73
1 Parent(s): f563211

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -42,11 +42,18 @@ model = PeftModel.from_pretrained(base_model, LORA_MODEL_PATH)
42
  model = model.to("cuda" if torch.cuda.is_available() else "cpu")
43
 
44
  # 定义推理函数
45
- @spaces.GPU(duration=30)
46
  def stream_chat(message: str, history: list, temperature: float, max_new_tokens: int, top_p: float, top_k: int, penalty: float):
47
  conversation = []
 
 
 
 
 
48
  for prompt, answer in history:
49
  conversation.extend([{"role": "user", "content": prompt}, {"role": "assistant", "content": answer}])
 
 
50
  conversation.append({"role": "user", "content": message})
51
 
52
  # 使用自定义对话模板生成 input_ids
 
42
  model = model.to("cuda" if torch.cuda.is_available() else "cpu")
43
 
44
  # 定义推理函数
45
+ @spaces.GPU(duration=50)
46
  def stream_chat(message: str, history: list, temperature: float, max_new_tokens: int, top_p: float, top_k: int, penalty: float):
47
  conversation = []
48
+
49
+ # 添加系统提示,定义模型的角色
50
+ conversation.append({"role": "system", "content": "你是一个检测代码漏洞的AI助手,帮助用户找到并修复代码中的安全问题。"})
51
+
52
+ # 将历史对话内容添加到会话中
53
  for prompt, answer in history:
54
  conversation.extend([{"role": "user", "content": prompt}, {"role": "assistant", "content": answer}])
55
+
56
+ # 添加当前用户的输入到对话中
57
  conversation.append({"role": "user", "content": message})
58
 
59
  # 使用自定义对话模板生成 input_ids