rahul7star commited on
Commit
1bacd30
·
verified ·
1 Parent(s): eac9997

Update lm.py

Browse files
Files changed (1) hide show
  1. lm.py +30 -20
lm.py CHANGED
@@ -382,32 +382,42 @@ if USE_LM_STUDIO:
382
  # CHAT
383
  # ---------------------------------------------------------
384
 
 
 
385
  def _chat(prompt: str) -> str:
 
 
 
 
 
 
 
 
386
 
387
- try:
 
 
 
 
388
 
389
- model = _load_llm()
 
 
 
 
 
390
 
391
- response = model.create_chat_completion(
392
- messages=[
393
- {
394
- "role": "user",
395
- "content": prompt
396
- }
397
- ],
398
- temperature=0.3,
399
- max_tokens=512,
400
- )
401
 
402
- return (
403
- response["choices"][0]
404
- .get("message", {})
405
- .get("content", "")
406
- )
407
 
408
- except Exception as e:
409
- print("Chat error:", e)
410
- return ""
 
 
411
 
412
  # ---------------------------------------------------------
413
  # EMBED
 
382
  # CHAT
383
  # ---------------------------------------------------------
384
 
385
+ import re
386
+
387
  def _chat(prompt: str) -> str:
388
+ try:
389
+ response = _load_llm().create_chat_completion(
390
+ messages=[
391
+ {"role": "user", "content": prompt}
392
+ ],
393
+ temperature=0.3,
394
+ max_tokens=512,
395
+ )
396
 
397
+ text = (
398
+ response["choices"][0]
399
+ .get("message", {})
400
+ .get("content", "")
401
+ )
402
 
403
+ text = re.sub(
404
+ r"<think>.*?</think>",
405
+ "",
406
+ text,
407
+ flags=re.DOTALL
408
+ )
409
 
410
+ text = text.replace("<start_of_turn>model", "")
411
+ text = text.replace("<end_of_turn>", "")
412
+ text = text.strip()
 
 
 
 
 
 
 
413
 
414
+ print("[lm] RESPONSE:", repr(text))
 
 
 
 
415
 
416
+ return text
417
+
418
+ except Exception as e:
419
+ print("Chat error:", e)
420
+ return ""
421
 
422
  # ---------------------------------------------------------
423
  # EMBED