JustKiddo commited on
Commit
cde2e05
1 Parent(s): 6dff6d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -27,26 +27,26 @@ class VietnameseChatbot:
27
 
28
  def get_response(self, user_query):
29
  try:
 
30
  payload = {
31
  "model": "gemma2-9b-it",
32
  "messages": [
 
 
 
 
33
  {"role": "user", "content": user_query}
34
  ]
35
  }
36
-
37
  response = requests.post(
38
- self.api_url,
39
- headers=self.headers,
40
- json=payload
41
  )
42
-
43
  if response.status_code == 200:
44
  return response.json()['choices'][0]['message']['content']
45
  else:
46
  print(f"API Error: {response.status_code}")
47
  print(f"Response: {response.text}")
48
  return "Đã xảy ra lỗi khi kết nối với API. Xin vui lòng thử lại."
49
-
50
  except Exception as e:
51
  print(f"Response generation error: {e}")
52
  return "Đã xảy ra lỗi. Xin vui lòng thử lại."
 
27
 
28
  def get_response(self, user_query):
29
  try:
30
+ # Add a system message to guide the model's response
31
  payload = {
32
  "model": "gemma2-9b-it",
33
  "messages": [
34
+ {
35
+ "role": "system",
36
+ "content": "You are an assistant designed to have helpful, ethical, non-biased, and constructive conversations. Do not engage with political, sensitive, or inappropriate topics. If asked about such subjects, politely decline to discuss them and redirect the conversation to more positive, constructive topics."
37
+ },
38
  {"role": "user", "content": user_query}
39
  ]
40
  }
 
41
  response = requests.post(
42
+ self.api_url, headers=self.headers, json=payload
 
 
43
  )
 
44
  if response.status_code == 200:
45
  return response.json()['choices'][0]['message']['content']
46
  else:
47
  print(f"API Error: {response.status_code}")
48
  print(f"Response: {response.text}")
49
  return "Đã xảy ra lỗi khi kết nối với API. Xin vui lòng thử lại."
 
50
  except Exception as e:
51
  print(f"Response generation error: {e}")
52
  return "Đã xảy ra lỗi. Xin vui lòng thử lại."