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

Method __call__

llama_cpp/llama_chat_format.py:3402–3656  ·  view source on GitHub ↗
(
        self,
        *,
        llama: llama.Llama,
        messages: List[llama_types.ChatCompletionRequestMessage],
        functions: Optional[List[llama_types.ChatCompletionFunction]] = None,
        function_call: Optional[llama_types.ChatCompletionRequestFunctionCall] = None,
        tools: Optional[List[llama_types.ChatCompletionTool]] = None,
        tool_choice: Optional[llama_types.ChatCompletionToolChoiceOption] = None,
        temperature: float = 0.2,
        top_p: float = 0.95,
        top_k: int = 40,
        min_p: float = 0.05,
        typical_p: float = 1.0,
        stream: bool = False,
        stop: Optional[Union[str, List[str]]] = [],
        seed: Optional[int] = None,
        response_format: Optional[
            llama_types.ChatCompletionRequestResponseFormat
        ] = None,
        max_tokens: Optional[int] = None,
        presence_penalty: float = 0.0,
        frequency_penalty: float = 0.0,
        repeat_penalty: float = 1.1,
        tfs_z: float = 1.0,
        mirostat_mode: int = 0,
        mirostat_tau: float = 5.0,
        mirostat_eta: float = 0.1,
        model: Optional[str] = None,
        logits_processor: Optional[llama.LogitsProcessorList] = None,
        grammar: Optional[llama.LlamaGrammar] = None,
        logit_bias: Optional[Dict[str, float]] = None,
        logprobs: Optional[bool] = None,
        top_logprobs: Optional[int] = None,
        **kwargs,  # type: ignore
    )

Source from the content-addressed store, hash-verified

3400 return text
3401
3402 def __call__(
3403 self,
3404 *,
3405 llama: llama.Llama,
3406 messages: List[llama_types.ChatCompletionRequestMessage],
3407 functions: Optional[List[llama_types.ChatCompletionFunction]] = None,
3408 function_call: Optional[llama_types.ChatCompletionRequestFunctionCall] = None,
3409 tools: Optional[List[llama_types.ChatCompletionTool]] = None,
3410 tool_choice: Optional[llama_types.ChatCompletionToolChoiceOption] = None,
3411 temperature: float = 0.2,
3412 top_p: float = 0.95,
3413 top_k: int = 40,
3414 min_p: float = 0.05,
3415 typical_p: float = 1.0,
3416 stream: bool = False,
3417 stop: Optional[Union[str, List[str]]] = [],
3418 seed: Optional[int] = None,
3419 response_format: Optional[
3420 llama_types.ChatCompletionRequestResponseFormat
3421 ] = None,
3422 max_tokens: Optional[int] = None,
3423 presence_penalty: float = 0.0,
3424 frequency_penalty: float = 0.0,
3425 repeat_penalty: float = 1.1,
3426 tfs_z: float = 1.0,
3427 mirostat_mode: int = 0,
3428 mirostat_tau: float = 5.0,
3429 mirostat_eta: float = 0.1,
3430 model: Optional[str] = None,
3431 logits_processor: Optional[llama.LogitsProcessorList] = None,
3432 grammar: Optional[llama.LlamaGrammar] = None,
3433 logit_bias: Optional[Dict[str, float]] = None,
3434 logprobs: Optional[bool] = None,
3435 top_logprobs: Optional[int] = None,
3436 **kwargs, # type: ignore
3437 ) -> Union[
3438 llama_types.CreateChatCompletionResponse,
3439 Iterator[llama_types.CreateChatCompletionStreamResponse],
3440 ]:
3441 self._init_mtmd_context(llama)
3442 assert self.mtmd_ctx is not None
3443
3444 image_urls = self.get_image_urls(messages)
3445 media_marker = self._mtmd_cpp.mtmd_default_marker().decode("utf-8")
3446 template_env = ImmutableSandboxedEnvironment(
3447 trim_blocks=True,
3448 lstrip_blocks=True,
3449 extensions=[
3450 Jinja2ChatFormatter.IgnoreGenerationTags,
3451 jinja2.ext.loopcontrols,
3452 ],
3453 )
3454 template_env.filters["tojson"] = Jinja2ChatFormatter.tojson
3455 template = template_env.from_string(self._get_chat_template(llama))
3456
3457 def raise_exception(message: str):
3458 raise ValueError(message)
3459

Callers

nothing calls this directly

Calls 15

_init_mtmd_contextMethod · 0.95
get_image_urlsMethod · 0.95
_get_chat_templateMethod · 0.95
_decode_token_pieceMethod · 0.95
load_imageMethod · 0.95
from_stringMethod · 0.80

Tested by

no test coverage detected