Skip to content

Commit 09a8406

Browse files
authored
Fix streaming doesn't return finish reason (#798)
When streaming the yield that contains the finish can be skipped. This change ensures that yield isn't skipped.
1 parent 28c2b88 commit 09a8406

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

llama_cpp/llama.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,20 +1232,6 @@ def _create_completion(
12321232
}
12331233
],
12341234
}
1235-
yield {
1236-
"id": completion_id,
1237-
"object": "text_completion",
1238-
"created": created,
1239-
"model": model_name,
1240-
"choices": [
1241-
{
1242-
"text": "",
1243-
"index": 0,
1244-
"logprobs": None,
1245-
"finish_reason": finish_reason,
1246-
}
1247-
],
1248-
}
12491235
break
12501236
returned_tokens += 1
12511237
yield {
@@ -1264,20 +1250,20 @@ def _create_completion(
12641250
}
12651251
],
12661252
}
1267-
yield {
1268-
"id": completion_id,
1269-
"object": "text_completion",
1270-
"created": created,
1271-
"model": model_name,
1272-
"choices": [
1273-
{
1274-
"text": "",
1275-
"index": 0,
1276-
"logprobs": None,
1277-
"finish_reason": finish_reason,
1278-
}
1279-
],
1280-
}
1253+
yield {
1254+
"id": completion_id,
1255+
"object": "text_completion",
1256+
"created": created,
1257+
"model": model_name,
1258+
"choices": [
1259+
{
1260+
"text": "",
1261+
"index": 0,
1262+
"logprobs": None,
1263+
"finish_reason": finish_reason,
1264+
}
1265+
],
1266+
}
12811267
if self.cache:
12821268
if self.verbose:
12831269
print("Llama._create_completion: cache save", file=sys.stderr)

0 commit comments

Comments
 (0)