Spaces:
Sleeping
Sleeping
Update server.py
Browse files
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.
|
| 27 |
|
| 28 |
app.add_middleware(
|
| 29 |
CORSMiddleware,
|
|
@@ -161,8 +161,8 @@ class Message(BaseModel):
|
|
| 161 |
|
| 162 |
class ChatCompletionRequest(BaseModel):
|
| 163 |
messages: List[Message]
|
| 164 |
-
max_tokens: Optional[int] =
|
| 165 |
-
temperature: Optional[float] = 0.
|
| 166 |
stream: Optional[bool] = False
|
| 167 |
|
| 168 |
@app.on_event("startup")
|
|
@@ -204,15 +204,16 @@ async def chat_completions(request: ChatCompletionRequest):
|
|
| 204 |
|
| 205 |
if context:
|
| 206 |
sys_msg = (
|
| 207 |
-
"
|
| 208 |
-
"
|
| 209 |
-
"1.
|
| 210 |
-
"2.
|
| 211 |
-
"3.
|
| 212 |
-
|
|
|
|
| 213 |
)
|
| 214 |
else:
|
| 215 |
-
sys_msg = "
|
| 216 |
|
| 217 |
if request.messages[0].role == "system":
|
| 218 |
request.messages[0].content = sys_msg
|
|
@@ -226,12 +227,12 @@ async def chat_completions(request: ChatCompletionRequest):
|
|
| 226 |
|
| 227 |
gen_kwargs = dict(
|
| 228 |
inputs=prompt_ids,
|
| 229 |
-
max_new_tokens=request.max_tokens,
|
| 230 |
-
temperature=0.
|
| 231 |
top_p=0.9,
|
| 232 |
do_sample=True,
|
| 233 |
pad_token_id=tokenizer.eos_token_id,
|
| 234 |
-
repetition_penalty=1.
|
| 235 |
)
|
| 236 |
|
| 237 |
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.3.0")
|
| 27 |
|
| 28 |
app.add_middleware(
|
| 29 |
CORSMiddleware,
|
|
|
|
| 161 |
|
| 162 |
class ChatCompletionRequest(BaseModel):
|
| 163 |
messages: List[Message]
|
| 164 |
+
max_tokens: Optional[int] = 512
|
| 165 |
+
temperature: Optional[float] = 0.2
|
| 166 |
stream: Optional[bool] = False
|
| 167 |
|
| 168 |
@app.on_event("startup")
|
|
|
|
| 204 |
|
| 205 |
if context:
|
| 206 |
sys_msg = (
|
| 207 |
+
"System: You are a technical assistant for 'Smart Home'. Answer in Hebrew.\n"
|
| 208 |
+
"Instructions:\n"
|
| 209 |
+
"1. Read the provided connection list.\n"
|
| 210 |
+
"2. Summarize it in one simple Hebrew sentence.\n"
|
| 211 |
+
"3. Example: 'המסך מחובר לבקר בפיני התקשורת RX ו-TX'.\n"
|
| 212 |
+
"4. Do not invent names or repeat yourself.\n"
|
| 213 |
+
f"\nContext:\n{context}"
|
| 214 |
)
|
| 215 |
else:
|
| 216 |
+
sys_msg = "System: You are a helpful assistant. Answer in Hebrew."
|
| 217 |
|
| 218 |
if request.messages[0].role == "system":
|
| 219 |
request.messages[0].content = sys_msg
|
|
|
|
| 227 |
|
| 228 |
gen_kwargs = dict(
|
| 229 |
inputs=prompt_ids,
|
| 230 |
+
max_new_tokens=request.max_tokens,
|
| 231 |
+
temperature=0.2, # דיוק גבוה
|
| 232 |
top_p=0.9,
|
| 233 |
do_sample=True,
|
| 234 |
pad_token_id=tokenizer.eos_token_id,
|
| 235 |
+
repetition_penalty=1.2 # מניעת לופים חזקה
|
| 236 |
)
|
| 237 |
|
| 238 |
if request.stream:
|