Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4b01a87

Browse filesBrowse files
swgabetlen
andauthored
server: Support none defaulting to infinity for completions (abetlen#111)
* Support defaulting to infinity or -1 for chat completions * Check if completion_tokens is none in error handler. * fix: max_tokens in create completion should match openai spec * Fix __call__ --------- Co-authored-by: Andrei Betlen <abetlen@gmail.com>
1 parent 12b7f2f commit 4b01a87
Copy full SHA for 4b01a87

File tree

Expand file treeCollapse file tree

3 files changed

+6
-4
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+6
-4
lines changed

‎llama_cpp/llama.py

Copy file name to clipboardExpand all lines: llama_cpp/llama.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ def create_completion(
19171917
completion_or_chunks = self._create_completion(
19181918
prompt=prompt,
19191919
suffix=suffix,
1920-
max_tokens=max_tokens,
1920+
max_tokens=-1 if max_tokens is None else max_tokens,
19211921
temperature=temperature,
19221922
top_p=top_p,
19231923
min_p=min_p,
@@ -1951,7 +1951,7 @@ def __call__(
19511951
self,
19521952
prompt: str,
19531953
suffix: Optional[str] = None,
1954-
max_tokens: int = 128,
1954+
max_tokens: Optional[int] = 16,
19551955
temperature: float = 0.8,
19561956
top_p: float = 0.95,
19571957
min_p: float = 0.05,

‎llama_cpp/server/errors.py

Copy file name to clipboardExpand all lines: llama_cpp/server/errors.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def context_length_exceeded(
7272
return 400, ErrorResponse(
7373
message=message.format(
7474
context_window,
75-
completion_tokens + prompt_tokens,
75+
(completion_tokens or 0) + prompt_tokens,
7676
prompt_tokens,
7777
completion_tokens,
7878
), # type: ignore

‎llama_cpp/server/types.py

Copy file name to clipboardExpand all lines: llama_cpp/server/types.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ class CreateCompletionRequest(BaseModel):
110110
default=None,
111111
description="A suffix to append to the generated text. If None, no suffix is appended. Useful for chatbots.",
112112
)
113-
max_tokens: int = max_tokens_field
113+
max_tokens: Optional[int] = Field(
114+
default=16, ge=0, description="The maximum number of tokens to generate."
115+
)
114116
temperature: float = temperature_field
115117
top_p: float = top_p_field
116118
min_p: float = min_p_field

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.