Generate text from a prompt. Args: prompt: The prompt to generate text from. suffix: A suffix to append to the generated text. If None, no suffix is appended. max_tokens: The maximum number of tokens to generate. If max_tokens <= 0 or None, the maximum nu
(
self,
prompt: str,
suffix: Optional[str] = None,
max_tokens: Optional[int] = 16,
temperature: float = 0.8,
top_p: float = 0.95,
min_p: float = 0.05,
typical_p: float = 1.0,
logprobs: Optional[int] = None,
echo: bool = False,
stop: Optional[Union[str, List[str]]] = [],
frequency_penalty: float = 0.0,
presence_penalty: float = 0.0,
repeat_penalty: float = 1.0,
top_k: int = 40,
stream: bool = False,
seed: Optional[int] = None,
tfs_z: float = 1.0,
mirostat_mode: int = 0,
mirostat_tau: float = 5.0,
mirostat_eta: float = 0.1,
model: Optional[str] = None,
stopping_criteria: Optional[StoppingCriteriaList] = None,
logits_processor: Optional[LogitsProcessorList] = None,
grammar: Optional[LlamaGrammar] = None,
logit_bias: Optional[Dict[int, float]] = None,
)
| 1903 | return completion |
| 1904 | |
| 1905 | def __call__( |
| 1906 | self, |
| 1907 | prompt: str, |
| 1908 | suffix: Optional[str] = None, |
| 1909 | max_tokens: Optional[int] = 16, |
| 1910 | temperature: float = 0.8, |
| 1911 | top_p: float = 0.95, |
| 1912 | min_p: float = 0.05, |
| 1913 | typical_p: float = 1.0, |
| 1914 | logprobs: Optional[int] = None, |
| 1915 | echo: bool = False, |
| 1916 | stop: Optional[Union[str, List[str]]] = [], |
| 1917 | frequency_penalty: float = 0.0, |
| 1918 | presence_penalty: float = 0.0, |
| 1919 | repeat_penalty: float = 1.0, |
| 1920 | top_k: int = 40, |
| 1921 | stream: bool = False, |
| 1922 | seed: Optional[int] = None, |
| 1923 | tfs_z: float = 1.0, |
| 1924 | mirostat_mode: int = 0, |
| 1925 | mirostat_tau: float = 5.0, |
| 1926 | mirostat_eta: float = 0.1, |
| 1927 | model: Optional[str] = None, |
| 1928 | stopping_criteria: Optional[StoppingCriteriaList] = None, |
| 1929 | logits_processor: Optional[LogitsProcessorList] = None, |
| 1930 | grammar: Optional[LlamaGrammar] = None, |
| 1931 | logit_bias: Optional[Dict[int, float]] = None, |
| 1932 | ) -> Union[CreateCompletionResponse, Iterator[CreateCompletionStreamResponse]]: |
| 1933 | """Generate text from a prompt. |
| 1934 | |
| 1935 | Args: |
| 1936 | prompt: The prompt to generate text from. |
| 1937 | suffix: A suffix to append to the generated text. If None, no suffix is appended. |
| 1938 | max_tokens: The maximum number of tokens to generate. If max_tokens <= 0 or None, the maximum number of tokens to generate is unlimited and depends on n_ctx. |
| 1939 | temperature: The temperature to use for sampling. |
| 1940 | top_p: The top-p value to use for nucleus sampling. Nucleus sampling described in academic paper "The Curious Case of Neural Text Degeneration" https://arxiv.org/abs/1904.09751 |
| 1941 | min_p: The min-p value to use for minimum p sampling. Minimum P sampling as described in https://github.com/ggerganov/llama.cpp/pull/3841 |
| 1942 | typical_p: The typical-p value to use for sampling. Locally Typical Sampling implementation described in the paper https://arxiv.org/abs/2202.00666. |
| 1943 | logprobs: The number of logprobs to return. If None, no logprobs are returned. |
| 1944 | echo: Whether to echo the prompt. |
| 1945 | stop: A list of strings to stop generation when encountered. |
| 1946 | frequency_penalty: The penalty to apply to tokens based on their frequency in the prompt. |
| 1947 | presence_penalty: The penalty to apply to tokens based on their presence in the prompt. |
| 1948 | repeat_penalty: The penalty to apply to repeated tokens. |
| 1949 | top_k: The top-k value to use for sampling. Top-K sampling described in academic paper "The Curious Case of Neural Text Degeneration" https://arxiv.org/abs/1904.09751 |
| 1950 | stream: Whether to stream the results. |
| 1951 | seed: The seed to use for sampling. |
| 1952 | tfs_z: The tail-free sampling parameter. Tail Free Sampling described in https://www.trentonbricken.com/Tail-Free-Sampling/. |
| 1953 | mirostat_mode: The mirostat sampling mode. |
| 1954 | mirostat_tau: The target cross-entropy (or surprise) value you want to achieve for the generated text. A higher value corresponds to more surprising or less predictable text, while a lower value corresponds to less surprising or more predictable text. |
| 1955 | mirostat_eta: The learning rate used to update `mu` based on the error between the target and observed surprisal of the sampled word. A larger learning rate will cause `mu` to be updated more quickly, while a smaller learning rate will result in slower updates. |
| 1956 | model: The name to use for the model in the completion object. |
| 1957 | stopping_criteria: A list of stopping criteria to use. |
| 1958 | logits_processor: A list of logits processors to use. |
| 1959 | grammar: A grammar to use for constrained sampling. |
| 1960 | logit_bias: A logit bias to use. |
| 1961 | |
| 1962 | Raises: |
nothing calls this directly
no test coverage detected