File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -824,19 +824,15 @@ def _create_completion(
824
824
if self .verbose :
825
825
llama_cpp .llama_reset_timings (self .ctx )
826
826
827
- if max_tokens <= 0 :
828
- # Unlimited, depending on n_ctx.
829
- if len (prompt_tokens ) >= int (llama_cpp .llama_n_ctx (self .ctx )):
830
- raise ValueError (
831
- f"Requested tokens exceed context window of { llama_cpp .llama_n_ctx (self .ctx )} "
832
- )
833
- else :
834
- max_tokens = int (llama_cpp .llama_n_ctx (self .ctx )) - len (prompt_tokens )
835
- elif len (prompt_tokens ) + max_tokens > int (llama_cpp .llama_n_ctx (self .ctx )):
827
+ if len (prompt_tokens ) >= llama_cpp .llama_n_ctx (self .ctx ):
836
828
raise ValueError (
837
- f"Requested tokens ( { len ( prompt_tokens ) } ) exceed context window of { self ._n_ctx } "
829
+ f"Requested tokens exceed context window of { llama_cpp . llama_n_ctx ( self .ctx ) } "
838
830
)
839
831
832
+ if max_tokens <= 0 :
833
+ # Unlimited, depending on n_ctx.
834
+ max_tokens = llama_cpp .llama_n_ctx (self .ctx ) - len (prompt_tokens )
835
+
840
836
# Truncate max_tokens if requested tokens would exceed the context window
841
837
max_tokens = (
842
838
max_tokens
You can’t perform that action at this time.
0 commit comments