Skip to content

Commit

Permalink
Add ensure_ascii = False for json.dumps (InternLM#2707)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllentDan committed Nov 13, 2024
1 parent 8400cfd commit 93f05dc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lmdeploy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def messages2prompt(self,
for tool_call in message['tool_calls']:
function = tool_call.get('function', {})
function['arguments'] = function.pop('parameters', {})
content += f'<|action_start|><|plugin|>\n{json.dumps(function)}<|action_end|>'
content += f'<|action_start|><|plugin|>\n{json.dumps(function, ensure_ascii=False)}<|action_end|>'
if 'name' in message and message['name'] in name_map:
begin = box_map[role].strip(
) + f" name={name_map[message['name']]}\n"
Expand Down
3 changes: 2 additions & 1 deletion lmdeploy/pytorch/engine/logits_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def _guided_sampling(response_formats: Tuple[Dict], scores: torch.Tensor,
if isinstance(schema, Dict):
for key in ['json_schema', 'schema']:
if key in schema:
schema = json.dumps(schema[key])
schema = json.dumps(schema[key],
ensure_ascii=False)
elif schema is None:
from .guided_process import JSON_GRAMMAR
schema = JSON_GRAMMAR
Expand Down
5 changes: 3 additions & 2 deletions lmdeploy/serve/async_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,9 @@ def parse_tool_response(self, text, tools, **kwargs):
action = action.split('<|action_end|>'.strip())[0]
action = action[action.find('{'):]
action = json.loads(action)
name, parameters = action['name'], json.dumps(
action.get('parameters', action.get('arguments', {})))
name, parameters = action['name'], json.dumps(action.get(
'parameters', action.get('arguments', {})),
ensure_ascii=False)
elif '<function=' in text: # llama3.1
action, _ = text.split('</function>')
parameters = action[action.find('{'):]
Expand Down

0 comments on commit 93f05dc

Please sign in to comment.