Prompt#
This module provides two classes namely ChatPrompt and ChatTemplate. The ChatPrompt is used to store the system prompt, chat history, and demonstrations used to interact with the Generator. The ChatTemplate is used to convert the ChatPrompt into a string or a list of tokens that can be used by the model.
Chat Prompt#
- class flexrag.prompt.ChatTurn(role, content)[源代码]#
- dump(path)#
Dump the dataclass to a YAML file.
- dumps()#
Dump the dataclass to a YAML string.
- classmethod load(path)#
Load the dataclass from a YAML file.
- classmethod loads(s)#
Load the dataclass from a YAML string.
- class flexrag.prompt.ChatPrompt(system=None, history=[], demonstrations=[])[源代码]#
- dump(path)#
Dump the dataclass to a YAML file.
- dumps()#
Dump the dataclass to a YAML string.
- classmethod load(path)#
Load the dataclass from a YAML file.
- classmethod loads(s)#
Load the dataclass from a YAML string.
- class flexrag.prompt.MultiModelChatTurn(role, content)[源代码]#
- dump(path)#
Dump the dataclass to a YAML file.
- dumps()#
Dump the dataclass to a YAML string.
- classmethod load(path)#
Load the dataclass from a YAML file.
- classmethod loads(s)#
Load the dataclass from a YAML string.
- class flexrag.prompt.MultiModelChatPrompt(system=None, history=[], demonstrations=[])[源代码]#
This class shares almost all the methods with ChatPrompt. However, the Generics in Python does not support calling the TypeVar's classmethod. So we have to duplicate the code here.
- dump(path)#
Dump the dataclass to a YAML file.
- dumps()#
Dump the dataclass to a YAML string.
- classmethod load(path)#
Load the dataclass from a YAML file.
- classmethod loads(s)#
Load the dataclass from a YAML string.
Template#
- class flexrag.prompt.HFTemplate(tokenizer, sys_prompt=None, chat_template=None)[源代码]#
基类:
ChatTemplate
- flexrag.prompt.load_template(tokenizer, model_name=None)[源代码]#
Load ChatTemplate for different models. If model_name is not provided, the default template in the Tokenizer will be used.
- 参数:
tokenizer (PreTrainedTokenizer) -- The tokenizer used to encode the prompt.
model_name (Optional[str]) -- The name of the model. Default is None.
- 返回:
The loaded ChatTemplate
- 返回类型: