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: Union[str, List[int]],
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,
)
| 1806 | } |
| 1807 | |
| 1808 | def create_completion( |
| 1809 | self, |
| 1810 | prompt: Union[str, List[int]], |
| 1811 | suffix: Optional[str] = None, |
| 1812 | max_tokens: Optional[int] = 16, |
| 1813 | temperature: float = 0.8, |
| 1814 | top_p: float = 0.95, |
| 1815 | min_p: float = 0.05, |
| 1816 | typical_p: float = 1.0, |
| 1817 | logprobs: Optional[int] = None, |
| 1818 | echo: bool = False, |
| 1819 | stop: Optional[Union[str, List[str]]] = [], |
| 1820 | frequency_penalty: float = 0.0, |
| 1821 | presence_penalty: float = 0.0, |
| 1822 | repeat_penalty: float = 1.0, |
| 1823 | top_k: int = 40, |
| 1824 | stream: bool = False, |
| 1825 | seed: Optional[int] = None, |
| 1826 | tfs_z: float = 1.0, |
| 1827 | mirostat_mode: int = 0, |
| 1828 | mirostat_tau: float = 5.0, |
| 1829 | mirostat_eta: float = 0.1, |
| 1830 | model: Optional[str] = None, |
| 1831 | stopping_criteria: Optional[StoppingCriteriaList] = None, |
| 1832 | logits_processor: Optional[LogitsProcessorList] = None, |
| 1833 | grammar: Optional[LlamaGrammar] = None, |
| 1834 | logit_bias: Optional[Dict[int, float]] = None, |
| 1835 | ) -> Union[CreateCompletionResponse, Iterator[CreateCompletionStreamResponse]]: |
| 1836 | """Generate text from a prompt. |
| 1837 | |
| 1838 | Args: |
| 1839 | prompt: The prompt to generate text from. |
| 1840 | suffix: A suffix to append to the generated text. If None, no suffix is appended. |
| 1841 | 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. |
| 1842 | temperature: The temperature to use for sampling. |
| 1843 | 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 |
| 1844 | 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 |
| 1845 | typical_p: The typical-p value to use for sampling. Locally Typical Sampling implementation described in the paper https://arxiv.org/abs/2202.00666. |
| 1846 | logprobs: The number of logprobs to return. If None, no logprobs are returned. |
| 1847 | echo: Whether to echo the prompt. |
| 1848 | stop: A list of strings to stop generation when encountered. |
| 1849 | frequency_penalty: The penalty to apply to tokens based on their frequency in the prompt. |
| 1850 | presence_penalty: The penalty to apply to tokens based on their presence in the prompt. |
| 1851 | repeat_penalty: The penalty to apply to repeated tokens. |
| 1852 | 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 |
| 1853 | stream: Whether to stream the results. |
| 1854 | seed: The seed to use for sampling. |
| 1855 | tfs_z: The tail-free sampling parameter. Tail Free Sampling described in https://www.trentonbricken.com/Tail-Free-Sampling/. |
| 1856 | mirostat_mode: The mirostat sampling mode. |
| 1857 | 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. |
| 1858 | 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. |
| 1859 | model: The name to use for the model in the completion object. |
| 1860 | stopping_criteria: A list of stopping criteria to use. |
| 1861 | logits_processor: A list of logits processors to use. |
| 1862 | grammar: A grammar to use for constrained sampling. |
| 1863 | logit_bias: A logit bias to use. |
| 1864 | |
| 1865 | Raises: |