OrifjonKenjayev commited on
Commit
595b02f
·
verified ·
1 Parent(s): b25dddd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -31,9 +31,9 @@ class ChatBot:
31
  # Initialize the model
32
  self.model = Together(
33
  model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
34
- temperature=0.5,
35
- max_tokens=150,
36
- top_k=30,
37
  together_api_key=TOGETHER_API_KEY
38
  )
39
 
@@ -45,13 +45,12 @@ class ChatBot:
45
  )
46
 
47
  # Create the prompt template
48
- self.template = """Quyidagi kontekst va suhbat tarixiga asoslanib, savolga o'zbek tilida tabiiy tarzda javob bering:
49
-
50
  Kontekst: {context}
51
-
52
  Suhbat Tarixi: {chat_history}
 
 
53
 
54
- Savol: {question}"""
55
 
56
  self.prompt = ChatPromptTemplate.from_template(self.template)
57
 
@@ -72,12 +71,20 @@ Savol: {question}"""
72
  messages = self.memory.load_memory_variables({})["chat_history"]
73
  return "\n".join([f"{m.type}: {m.content}" for m in messages])
74
 
 
 
75
  def process_response(self, response: str) -> str:
76
  """Clean up the response"""
77
  unwanted_tags = ["[INST]", "[/INST]", "<s>", "</s>"]
78
  for tag in unwanted_tags:
79
  response = response.replace(tag, "")
 
 
 
 
 
80
  return response.strip()
 
81
 
82
  def chat(self, message: str, history: List[Tuple[str, str]]) -> str:
83
  """Process a single chat message"""
 
31
  # Initialize the model
32
  self.model = Together(
33
  model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
34
+ temperature=0.2,
35
+ max_tokens=100,
36
+ top_k=20,
37
  together_api_key=TOGETHER_API_KEY
38
  )
39
 
 
45
  )
46
 
47
  # Create the prompt template
48
+ self.template = """Quyidagi kontekst va suhbat tarixiga asoslanib, savolga faqat matn ko'rinishida, kod yoki ortiqcha belgilarsiz, faqat o'zbek tilida tabiiy tarzda javob bering:
 
49
  Kontekst: {context}
 
50
  Suhbat Tarixi: {chat_history}
51
+ Savol: {question}
52
+ Javobni faqat matn shaklida bering, kod yoki ortiqcha belgilar kiritmang."""
53
 
 
54
 
55
  self.prompt = ChatPromptTemplate.from_template(self.template)
56
 
 
71
  messages = self.memory.load_memory_variables({})["chat_history"]
72
  return "\n".join([f"{m.type}: {m.content}" for m in messages])
73
 
74
+ import re
75
+
76
  def process_response(self, response: str) -> str:
77
  """Clean up the response"""
78
  unwanted_tags = ["[INST]", "[/INST]", "<s>", "</s>"]
79
  for tag in unwanted_tags:
80
  response = response.replace(tag, "")
81
+
82
+ # Python kod snippetlarini olib tashlash
83
+ response = re.sub(r"```.*?```", "", response, flags=re.DOTALL)
84
+ response = re.sub(r"print\(.*?\)", "", response)
85
+
86
  return response.strip()
87
+
88
 
89
  def chat(self, message: str, history: List[Tuple[str, str]]) -> str:
90
  """Process a single chat message"""