ItamarMordo commited on
Commit
0366b96
·
verified ·
1 Parent(s): 93be860

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +13 -11
server.py CHANGED
@@ -23,7 +23,7 @@ JSON_SOURCE = "database.json"
23
  logging.basicConfig(level=logging.INFO)
24
  logger = logging.getLogger(__name__)
25
 
26
- app = FastAPI(title="Hebrew Smart Home Technician", version="11.1.0")
27
 
28
  app.add_middleware(
29
  CORSMiddleware,
@@ -86,10 +86,10 @@ def expand_query(query: str) -> List[str]:
86
  return list(search_terms)
87
 
88
  def simplify_schematic_text(text: str) -> str:
89
- # ניקוי אגרסיבי והפיכה לעברית
90
  text = text.replace("ESP32-DEVKITC-32D_ESP32-DEVKITC-30GPIO", "בקר ESP32")
91
  text = text.replace("BOB_19002", "ממיר רמות")
92
  text = text.replace("TLM-SH_board", "הלוח הראשי")
 
93
  text = text.replace("NEXTION", "המסך")
94
  text = text.replace("LCD1", "המסך")
95
  text = text.replace("connects to", "מחובר אל")
@@ -132,13 +132,15 @@ def query_knowledge_base(query: str) -> str:
132
  relevant_lines = []
133
  target_terms = [t.lower() for t in search_terms if len(t) > 1]
134
  for line in lines:
135
- # לוגיקה משופרת: אם חיפשנו רכיב (כמו מסך), נביא את כל החיבורים שלו
136
- line_lower = line.lower()
137
- if "connect" in line_lower and any(t in line_lower for t in target_terms):
138
  relevant_lines.append(simplify_schematic_text(line.strip()))
139
 
 
 
 
 
 
140
  if relevant_lines:
141
- # הופך את הרשימה לפסקה קריאה יותר
142
  return "הנה החיבורים שנמצאו:\n" + "\n".join(relevant_lines)
143
 
144
  return raw_content
@@ -159,8 +161,8 @@ class Message(BaseModel):
159
 
160
  class ChatCompletionRequest(BaseModel):
161
  messages: List[Message]
162
- max_tokens: Optional[int] = 512
163
- temperature: Optional[float] = 0.4 # הועלה כדי לאפשר שפה טבעית יותר
164
  stream: Optional[bool] = False
165
 
166
  @app.on_event("startup")
@@ -224,12 +226,12 @@ async def chat_completions(request: ChatCompletionRequest):
224
 
225
  gen_kwargs = dict(
226
  inputs=prompt_ids,
227
- max_new_tokens=request.max_tokens,
228
- temperature=0.4, # יותר חופש = שפה טבעית יותר
229
  top_p=0.9,
230
  do_sample=True,
231
  pad_token_id=tokenizer.eos_token_id,
232
- repetition_penalty=1.05 # ענישה מינימלית, רק למנוע לופים קשים
233
  )
234
 
235
  if request.stream:
 
23
  logging.basicConfig(level=logging.INFO)
24
  logger = logging.getLogger(__name__)
25
 
26
+ app = FastAPI(title="Hebrew Smart Home Technician", version="11.2.0")
27
 
28
  app.add_middleware(
29
  CORSMiddleware,
 
86
  return list(search_terms)
87
 
88
  def simplify_schematic_text(text: str) -> str:
 
89
  text = text.replace("ESP32-DEVKITC-32D_ESP32-DEVKITC-30GPIO", "בקר ESP32")
90
  text = text.replace("BOB_19002", "ממיר רמות")
91
  text = text.replace("TLM-SH_board", "הלוח הראשי")
92
+ text = text.replace("StudentBoard", "הלוח הראשי")
93
  text = text.replace("NEXTION", "המסך")
94
  text = text.replace("LCD1", "המסך")
95
  text = text.replace("connects to", "מחובר אל")
 
132
  relevant_lines = []
133
  target_terms = [t.lower() for t in search_terms if len(t) > 1]
134
  for line in lines:
135
+ if "connect" in line.lower() and any(t in line.lower() for t in target_terms):
 
 
136
  relevant_lines.append(simplify_schematic_text(line.strip()))
137
 
138
+ # Optimization: Limit to top 10 relevant lines to ensure completion
139
+ if len(relevant_lines) > 10:
140
+ relevant_lines = relevant_lines[:10]
141
+ relevant_lines.append("... (רשימה חלקית)")
142
+
143
  if relevant_lines:
 
144
  return "הנה החיבורים שנמצאו:\n" + "\n".join(relevant_lines)
145
 
146
  return raw_content
 
161
 
162
  class ChatCompletionRequest(BaseModel):
163
  messages: List[Message]
164
+ max_tokens: Optional[int] = 1024 # Increased to prevent cut-off
165
+ temperature: Optional[float] = 0.3
166
  stream: Optional[bool] = False
167
 
168
  @app.on_event("startup")
 
226
 
227
  gen_kwargs = dict(
228
  inputs=prompt_ids,
229
+ max_new_tokens=request.max_tokens, # Now 1024
230
+ temperature=0.4,
231
  top_p=0.9,
232
  do_sample=True,
233
  pad_token_id=tokenizer.eos_token_id,
234
+ repetition_penalty=1.05
235
  )
236
 
237
  if request.stream: