Anjo123 commited on
Commit
0baea9e
·
verified ·
1 Parent(s): 76f727d

Updated chat history so country and language updates are reflected in system message

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -8,15 +8,23 @@ conversation_history = []
8
 
9
  def get_chatbot_response(user_message, country, language):
10
  global conversation_history
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  conversation_history.append({"role": "user", "content": user_message})
13
 
14
- if len(conversation_history) == 1:
15
- conversation_history.insert(0, {
16
- "role": "system",
17
- "content": f"You are a lawyer specializing in providing concise and accurate legal information based on the laws in {country}. Respond in {language}. Provide clear, factual information without offering personal legal advice or opinions. Include relevant legal references, statutes, or case law when possible."
18
- })
19
-
20
  completion = client.chat.completions.create(
21
  model="deepseek-r1-distill-llama-70b",
22
  messages=conversation_history,
 
8
 
9
  def get_chatbot_response(user_message, country, language):
10
  global conversation_history
11
+
12
+ system_message = (
13
+ f"You are a lawyer specializing in providing concise and accurate legal information based on the laws in {country}. "
14
+ f"Respond in {language}. Provide clear, factual information without offering personal legal advice or opinions. "
15
+ "Include relevant legal references, statutes, or case law when possible."
16
+ )
17
+
18
+ if conversation_history:
19
+ if conversation_history[0]["role"] == "system":
20
+ conversation_history[0]["content"] = system_message
21
+ else:
22
+ conversation_history.insert(0, {"role": "system", "content": system_message})
23
+ else:
24
+ conversation_history.append({"role": "system", "content": system_message})
25
 
26
  conversation_history.append({"role": "user", "content": user_message})
27
 
 
 
 
 
 
 
28
  completion = client.chat.completions.create(
29
  model="deepseek-r1-distill-llama-70b",
30
  messages=conversation_history,