8000 Merge pull request #1 from ryan1117001/develop · abetlen/llama-cpp-python@207a5c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 207a5c3

Browse files
authored
Merge pull request #1 from ryan1117001/develop
Develop
2 parents a14b49d + 7bd9a79 commit 207a5c3

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
update:
2-
poetry install
2+
# poetry install
33
git submodule update --init --recursive
44

55
update.vendor:

llama_cpp/llama.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,11 @@ def logit_bias_processor(
15171517
"finish_reason": finish_reason,
15181518
}
15191519
],
1520+
"usage": {
1521+
"prompt_tokens": len(prompt_tokens),
1522+
"completion_tokens": len(completion_tokens),
1523+
"total_tokens": len(prompt_tokens) + len(completion_tokens),
1524+
},
15201525
}
15211526
if self.cache:
15221527
if self.verbose:

llama_cpp/llama_chat_format.py

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -304,26 +304,53 @@ def _convert_text_completion_chunks_to_chat(
304304
}
305305
],
306306
}
307-
yield {
308-
"id": "chat" + chunk["id"],
309-
"model": chunk["model"],
310-
"created": chunk["created"],
311-
"object": "chat.completion.chunk",
312-
"choices": [
313-
{
314-
"index": 0,
315-
"delta": (
316-
{
317-
"content": chunk["choices"][0]["text"],
318-
}
319-
if chunk["choices"][0]["finish_reason"] is None
320-
else {}
321-
),
322-
"logprobs": chunk["choices"][0]["logprobs"],
323-
"finish_reason": chunk["choices"][0]["finish_reason"],
307+
if chunk["choices"][0]["finish_reason"] is None:
308+
yield {
309+
"id": "chat" + chunk["id"],
310+
"model": chunk["model"],
311+
"created": chunk["created"],
312+
"object": "chat.completion.chunk",
313+
"choices": [
314+
{
315+
"index": 0,
316+
"delta": (
317+
{
318+
"content": chunk["choices"][0]["text"],
319+
}
320+
if chunk["choices"][0]["finish_reason"] is None
321+
else {}
322+
),
323+
"logprobs": chunk["choices"][0]["logprobs"],
324+
"finish_reason": chunk["choices"][0]["finish_reason"],
325+
}
326+
]
327+
}
328+
else:
329+
yield {
330+
"id": "chat" + chunk["id"],
331+
"model": chunk["model"],
332+
"created": chunk["created"],
333+
"object": "chat.completion.chunk",
334+
"choices": [
335+
{
336+
"index": 0,
337+
"delta": (
338+
{
339+
"content": chunk["choices"][0]["text"],
340+
}
341+
if chunk["choices"][0]["finish_reason"] is None
342+
else {}
343+
),
344+
"logprobs": chunk["choices"][0]["logprobs"],
345+
"finish_reason": chunk["choices"][0]["finish_reason"],
346+
}
347+
],
348+
"usage": {
349+
"prompt_tokens": chunk["usage"]["prompt_tokens"],
350+
"completion_tokens": chunk["usage"]["completion_tokens"],
351+
"total_tokens": chunk["usage"]["total_tokens"],
324352
}
325-
],
326-
}
353+
}
327354

328355

329356
def _convert_completion_to_chat(

0 commit comments

Comments
 (0)
0