mirror of
https://github.com/ml-explore/mlx-examples.git
synced 2025-06-24 17:31:18 +08:00
Set finish_reason in response (#592)
This commit is contained in:
parent
6c3d4c8ba2
commit
373dd6f2a2
@ -238,6 +238,7 @@ class APIHandler(BaseHTTPRequestHandler):
|
|||||||
A list of stop words passed to the stopping_criteria function
|
A list of stop words passed to the stopping_criteria function
|
||||||
"""
|
"""
|
||||||
tokens = []
|
tokens = []
|
||||||
|
finish_reason = "length"
|
||||||
for (token, _), _ in zip(
|
for (token, _), _ in zip(
|
||||||
generate_step(
|
generate_step(
|
||||||
prompt=prompt,
|
prompt=prompt,
|
||||||
@ -255,12 +256,13 @@ class APIHandler(BaseHTTPRequestHandler):
|
|||||||
tokens, stop_id_sequences, TOKENIZER.eos_token_id
|
tokens, stop_id_sequences, TOKENIZER.eos_token_id
|
||||||
)
|
)
|
||||||
if stop_condition.stop_met:
|
if stop_condition.stop_met:
|
||||||
|
finish_reason = "stop"
|
||||||
if stop_condition.trim_length:
|
if stop_condition.trim_length:
|
||||||
tokens = tokens[: -stop_condition.trim_length]
|
tokens = tokens[: -stop_condition.trim_length]
|
||||||
break
|
break
|
||||||
|
|
||||||
text = TOKENIZER.decode(tokens)
|
text = TOKENIZER.decode(tokens)
|
||||||
response = self.generate_response(text, "stop", len(prompt), len(tokens))
|
response = self.generate_response(text, finish_reason, len(prompt), len(tokens))
|
||||||
|
|
||||||
response_json = json.dumps(response).encode()
|
response_json = json.dumps(response).encode()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user