(
body: CreateCompletionRequest | CreateChatCompletionRequest,
llama_proxy: LlamaProxy,
body_model: str | None,
kwargs,
)
| 156 | |
| 157 | |
| 158 | def prepare_request_resources( |
| 159 | body: CreateCompletionRequest | CreateChatCompletionRequest, |
| 160 | llama_proxy: LlamaProxy, |
| 161 | body_model: str | None, |
| 162 | kwargs, |
| 163 | ) -> llama_cpp.Llama: |
| 164 | if llama_proxy is None: |
| 165 | raise HTTPException( |
| 166 | status_code=status.HTTP_503_SERVICE_UNAVAILABLE, |
| 167 | detail="Service is not available", |
| 168 | ) |
| 169 | llama = llama_proxy(body_model) |
| 170 | if body.logit_bias is not None: |
| 171 | kwargs["logit_bias"] = ( |
| 172 | _logit_bias_tokens_to_input_ids(llama, body.logit_bias) |
| 173 | if body.logit_bias_type == "tokens" |
| 174 | else body.logit_bias |
| 175 | ) |
| 176 | |
| 177 | if body.grammar is not None: |
| 178 | kwargs["grammar"] = llama_cpp.LlamaGrammar.from_string(body.grammar) |
| 179 | |
| 180 | if body.min_tokens > 0: |
| 181 | _min_tokens_logits_processor = llama_cpp.LogitsProcessorList( |
| 182 | [llama_cpp.MinTokensLogitsProcessor(body.min_tokens, llama.token_eos())] |
| 183 | ) |
| 184 | if "logits_processor" not in kwargs: |
| 185 | kwargs["logits_processor"] = _min_tokens_logits_processor |
| 186 | else: |
| 187 | kwargs["logits_processor"].extend(_min_tokens_logits_processor) |
| 188 | return llama |
| 189 | |
| 190 | |
| 191 | async def get_event_publisher( |
no test coverage detected
searching dependent graphs…