Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

想在使用文件对话时使用自己的提示词,想要的回答时结构化的格式输出,我在自定义提示词的时候如何写我需要结构化方式的回答? #4030

Open
Ptianyu opened this issue May 16, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@Ptianyu
Copy link

Ptianyu commented May 16, 2024

No description provided.

@Ptianyu Ptianyu added the enhancement New feature or request label May 16, 2024
Copy link

dosubot bot commented May 16, 2024

To customize your prompt for structured format responses in file dialogs, you can use Python's str.format method for dynamic prompt generation. Here's a concise guide:

  1. Create a Custom Prompt Template: Use str.format with placeholders ({}) for dynamic content. This allows you to insert variables like user input or context into the prompt.

  2. Define Variables for the Template: Identify the variables you need (e.g., user input, context) and prepare them to be inserted into the template at runtime.

  3. Render the Custom Prompt: Fill in the template with your variables to generate the final prompt to be used in your dialog system.

  4. Handle Structured Responses: Ensure your system can parse and handle the structured responses, which might include actions, observations, and other structured data.

Example code snippet to illustrate these steps:

class CustomPromptTemplate(StringPromptTemplate):
    template: str
    tools: List[Tool]

    def format(self, **kwargs) -> str:
        # Example of adding intermediate steps and tool descriptions
        kwargs["agent_scratchpad"] = "\n".join([f"Thought: {action.log}" for action, _ in kwargs.get("intermediate_steps", [])])
        kwargs["tools"] = "\n".join([f"{tool.name}: {tool.description}" for tool in self.tools])
        return self.template.format(**kwargs)

# Rendering the custom prompt
custom_prompt_template = CustomPromptTemplate(template="Your custom prompt here with variables like {input}")
rendered_prompt = custom_prompt_template.format(input="Your specific question or input")

# Simulate getting a structured response
def get_response_for_custom_prompt(prompt):
    # Logic to process the prompt and return a structured response
    return {"action": "ExampleAction", "data": "ExampleData"}

# Handling the structured response
response = get_response_for_custom_prompt(rendered_prompt)
print(response)

This approach allows you to dynamically generate prompts tailored to your needs and handle responses in a structured format, facilitating easier parsing and processing of the data.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@Dannissss0704
Copy link

插眼

@blackwhites
Copy link

prompt_config.py里改提示词,我把中文的改成英文了,这样老外可以看到英文回复

@Ptianyu Ptianyu closed this as completed May 16, 2024
@Ptianyu Ptianyu reopened this May 16, 2024
@Ptianyu
Copy link
Author

Ptianyu commented May 16, 2024

我想以xxx:xxx
xxx:xxx的格式输出
但是他的输出格式是xxx:xxx xxx:xxx 我已经在提示词写了以第一种格式输出可回答还是第二种

@blackwhites
Copy link

没明白你的意思,能具体些?

@CRonaldo1997
Copy link

1-prompt中举例说明回复格式
2-用符合格式的数据微调模型

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants