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

Method __call__

llama_cpp/llama_chat_format.py:2852–3122  ·  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

2850 return bitmap
2851
2852 def __call__(
2853 self,
2854 *,
2855 llama: llama.Llama,
2856 messages: List[llama_types.ChatCompletionRequestMessage],
2857 functions: Optional[List[llama_types.ChatCompletionFunction]] = None,
2858 function_call: Optional[llama_types.ChatCompletionRequestFunctionCall] = None,
2859 tools: Optional[List[llama_types.ChatCompletionTool]] = None,
2860 tool_choice: Optional[llama_types.ChatCompletionToolChoiceOption] = None,
2861 temperature: float = 0.2,
2862 top_p: float = 0.95,
2863 top_k: int = 40,
2864 min_p: float = 0.05,
2865 typical_p: float = 1.0,
2866 stream: bool = False,
2867 stop: Optional[Union[str, List[str]]] = [],
2868 seed: Optional[int] = None,
2869 response_format: Optional[
2870 llama_types.ChatCompletionRequestResponseFormat
2871 ] = None,
2872 max_tokens: Optional[int] = None,
2873 presence_penalty: float = 0.0,
2874 frequency_penalty: float = 0.0,
2875 repeat_penalty: float = 1.1,
2876 tfs_z: float = 1.0,
2877 mirostat_mode: int = 0,
2878 mirostat_tau: float = 5.0,
2879 mirostat_eta: float = 0.1,
2880 model: Optional[str] = None,
2881 logits_processor: Optional[llama.LogitsProcessorList] = None,
2882 grammar: Optional[llama.LlamaGrammar] = None,
2883 logit_bias: Optional[Dict[str, float]] = None,
2884 logprobs: Optional[bool] = None,
2885 top_logprobs: Optional[int] = None,
2886 **kwargs, # type: ignore
2887 ) -> Union[
2888 llama_types.CreateChatCompletionResponse,
2889 Iterator[llama_types.CreateChatCompletionStreamResponse],
2890 ]:
2891 # Initialize mtmd context
2892 self._init_mtmd_context(llama)
2893 assert self.mtmd_ctx is not None
2894
2895 system_prompt = _get_system_message(messages)
2896 if system_prompt == "" and self.DEFAULT_SYSTEM_MESSAGE is not None:
2897 messages = [
2898 llama_types.ChatCompletionRequestSystemMessage(
2899 role="system", content=self.DEFAULT_SYSTEM_MESSAGE
2900 )
2901 ] + messages
2902
2903 image_urls = self.get_image_urls(messages)
2904 template = ImmutableSandboxedEnvironment(
2905 trim_blocks=True,
2906 lstrip_blocks=True,
2907 ).from_string(self.CHAT_FORMAT)
2908
2909 # Get the default media marker

Callers

nothing calls this directly

Calls 15

_init_mtmd_contextMethod · 0.95
get_image_urlsMethod · 0.95
load_imageMethod · 0.95
_get_system_messageFunction · 0.85
from_stringMethod · 0.80
appendMethod · 0.80
kv_cache_clearMethod · 0.80
evalMethod · 0.80

Tested by

no test coverage detected