MCPcopy Index your code
hub / github.com/abetlen/llama-cpp-python / prepare_request_resources

Function prepare_request_resources

llama_cpp/server/app.py:158–188  ·  view source on GitHub ↗
(
    body: CreateCompletionRequest | CreateChatCompletionRequest,
    llama_proxy: LlamaProxy,
    body_model: str | None,
    kwargs,
)

Source from the content-addressed store, hash-verified

156
157
158def 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
191async def get_event_publisher(

Callers 3

get_event_publisherFunction · 0.85
create_completionFunction · 0.85
create_chat_completionFunction · 0.85

Calls 4

from_stringMethod · 0.80
token_eosMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…