qianfan.common.prompt package
Submodules
qianfan.common.prompt.prompt module
- class qianfan.common.prompt.prompt.Prompt(template: Optional[str] = None, name: Optional[str] = None, id: Optional[int] = None, identifier: Literal['{}', '{{}}', '[]', '[[]]', '()', '(())'] = '{}', variables: Optional[List[str]] = None, labels: List[PromptLabel] = [], type: PromptType = PromptType.User, scene_type: PromptSceneType = PromptSceneType.Text2Text, framework_type: PromptFrameworkType = PromptFrameworkType.NotUse, negative_template: Optional[str] = None, negative_variables: Optional[List[str]] = None, creator_name: Optional[str] = None)[source]
Bases:
HubSerializable- classmethod base_prompt(prompt: str, background: str = '', additional_data: str = '', output_schema: str = '') str[source]
Generates a base type prompt for language models.
- Parameters:
- prompt (str):
The main text prompt that defines the task or query for the language model.
- background (str, optional):
Additional context or background information to provide more context to the model.
- additional_data (str, optional):
Extra data that can be included to enhance the specificity or details of the prompt.
- output_schema (str, optional):
The desired schema for formatting the output of the language model.
Please refer to the following link for more details about CRISPE prompt.
API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Zlo55g7t3
- creator_name: Optional[str] = None
- classmethod crispe_prompt(statement: str, capacity: str = '', insight: str = '', personality: str = '', experiment: str = '') str[source]
Generates a CRISPE-type prompt for fine-tuning models.
- Parameters:
- statement (str):
The main task that the model should focus on.
- capacity (str, optional):
Capacity information specifying what role you want the model to play.
- insight (str, optional):
Insights or guidance to provide additional context for the fine-tuning task.
- personality (str, optional):
The output style or personality of the model.
- experiment (str, optional):
The limit of the output range of the model.
Please refer to the following link for more details about CRISPE prompt.
API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Hlo56qd21
- classmethod fewshot_prompt(prompt: str = '', examples: List[Tuple[str, str]] = []) str[source]
Generates a few-shot prompt for model input.
- Parameters:
- prompt (str):
The main prompt that sets the context for what task should the model focus on.
- examples (List[Tuple[str, str]]):
A list of example tuples, where each tuple contains a model input string and its corresponding expected output. These examples help the model understand the desired behavior.
Please refer to the following link for more details about fewshot prompt.
API Doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Nlo57dbf4
- framework_type: PromptFrameworkType
- classmethod from_file(path: str, identifier: Literal['{}', '{{}}', '[]', '[[]]', '()', '(())'] = '{}') Prompt[source]
Create a Prompt object from file. The file should only contain the prompt template.
- Parameters:
- path (str):
The path of the prompt file.
- identifier (Literal[“{}”, “{{}}”, “[]”, “[[]]”, “()”, “(())”]):
The identifier of the prompt.
- id: Optional[int] = None
- identifier: Literal['{}', '{{}}', '[]', '[[]]', '()', '(())']
- labels: List[PromptLabel]
- name: Optional[str] = None
- negative_template: Optional[str] = None
- negative_variables: Optional[List[str]] = None
- render(**kwargs: str) Tuple[str, Optional[str]][source]
Render the prompt with given variables.
- Parameters:
- kwargs (Any):
The value of the variables to be used for variable replacement in the template.
- save_to_file(path: str) None[source]
Save the prompt template to file.
- Parameters:
- path (str):
The path of the prompt file.
- scene_type: PromptSceneType
- set_negative_template(template: str) None[source]
Set the prompt’s negative template. The variables in the template will be extracted.
- Parameters:
- template (str):
The new negative template.
- set_template(template: str) None[source]
Set the prompt’s template. The variables in the template will be extracted.
- Parameters:
- template (str):
The new template.
- template: str
- type: PromptType
- variables: List[str]