NemoVonNirgend commited on
Commit
bdedbd5
·
verified ·
1 Parent(s): f58f56a

Upload serve_ministral.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. serve_ministral.py +15 -0
serve_ministral.py CHANGED
@@ -15,6 +15,20 @@ import traceback
15
 
16
  app = FastAPI()
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  # Global model and tokenizer
19
  model = None
20
  processor = None
@@ -105,6 +119,7 @@ async def chat_completions(request: ChatRequest):
105
  # Decode only the new tokens
106
  new_tokens = outputs[0][input_len:]
107
  response_text = processor.tokenizer.decode(new_tokens, skip_special_tokens=True)
 
108
  print(f"Generated {len(new_tokens)} tokens")
109
 
110
  return ChatResponse(
 
15
 
16
  app = FastAPI()
17
 
18
+ def fix_bpe_tokens(text):
19
+ """Fix BPE tokenization artifacts"""
20
+ text = text.replace("Ġ", " ")
21
+ text = text.replace("Ċ", "\n")
22
+ text = text.replace("ĉ", "\t")
23
+ text = text.replace("âĢĻ", "'")
24
+ text = text.replace("âĢľ", '"')
25
+ text = text.replace("âĢĿ", '"')
26
+ text = text.replace("âĢĶ", "—")
27
+ text = text.replace("âĢĵ", "–")
28
+ text = text.replace("â̦", "…")
29
+ text = text.replace("âĢĺ", "'")
30
+ return text
31
+
32
  # Global model and tokenizer
33
  model = None
34
  processor = None
 
119
  # Decode only the new tokens
120
  new_tokens = outputs[0][input_len:]
121
  response_text = processor.tokenizer.decode(new_tokens, skip_special_tokens=True)
122
+ response_text = fix_bpe_tokens(response_text)
123
  print(f"Generated {len(new_tokens)} tokens")
124
 
125
  return ChatResponse(