Prompt Setup
Write something in advance
Update on 4.30nd
, I have updated my own prompt.
Update on 4.22nd
, I have updated the prompt learning.
Written on 4.18th
, there are several steps required to achieve my project, in this potion, I am going to learn how to enable my own prompt, ensure my output is written in format.
- The way to input the prompt to the local LLM.
- The knowledge of prompt
Input the prompt to the local LLM
From the Ollama official website, I understand I can directly create a file called modelfile
and setup the parameters of LLM and write the prompt for the LLM.
I first create the modelfile
file and write the contents below:
FROM gemma # This is the model that I used
# set the temperature to 1 [higher is more creative, lower is more coherent]
PARAMETER temperature 5
# set the system message - prompt
SYSTEM """
You are Mattheq from Seeed Studio, an application engineer. Answer as Matthew, the assistant, only.
"""
Then I use this commend:
ollama create matthew -f modelfile
to input the prompt to the gemma, the LLM that I use.
The matthew
can be changed, and it represents a new type of model. Hence, if I want to use a model that some prompt been input, I can run:
ollama run matthew
and here is the result:
The Prompt Writing
The overview of the prompt writing principle
Learned from the course ChatGPT Prompt Engineering for Developers from DeelLearning.AI, presented by Andrew Ng. There are two featured principle of the prompt writing:
- Make sure the instructions given are "clear and unambiguous" whenever possible
- Use delimiters(";" ,etc) to clearly indicate different parts of the input
- Require the structured output
- Let the model check if the condition is met
- Offer small sample hint
- Give the LLM to think, and enough time to complete the task
- Specify the steps required to complete the task
- Let the model figure out the solution on its own before jumping to conclusions
This is the loop of Prompts for development iterations:
Other resources(Chinese):
Principle 1: Write clear and specific instructions
Tactic 1: Use delimiters
Summarize the text delimited by backticks into one clear sentence: What a prompt injection is, is if a user is allowed to add some input into your prompt, they might give kind of conflicting instructions to the model that might kind of make it follow the user's instructions rather than doing what you want it to do.
I can use XML tags, section titles, ( '''
,"""
,< >
,<tag> </tag>
,;
) anything that just kind of makes this clear to the model that this is a separate section.
text = """
balablabala \
balablabala \
balablabala \
"""
(prompt) -> summarize the {text} delimited by tripe backticks \
into a single sentence
Tactic 2: Structured output
Ask for a structured output like HTML or JSON, this helps the model outputs easier.
text = """
balablabala \
balablabala \
balablabala \
"""
(prompt) -> Provide {text} in JSON format with the following keys:
id_1, id_2, id_3
Tactic 3: Ask the model to check for itself
Ask the model to check whether conditions are satisfied. If the they are not satisfied, then tell the model how to handle them to avoid unexpected errors or result.
text = """
balablabala \
balablabala \
balablabala \
"""
(prompt) -> You will be provided with {text} delimited by triple quotes.
If it contains a sequence of instructions, \
re write those instructions in the following format:
id_1, id_2, id_3
If the text does not contain a sequence of instructions, \
then simply write:
"no steps provided"
Tactic 4: Offer consistent style contents(make few-shot example)
Offer short example and expect the model output the same one: teach about resilience and since the model kind of has simliar few-shot example.
(prompt) -> Your task is to answer questions in a consistent style:
<people 1>: balabala
<people 2>: balabala
<people 1>: balabala?
Principle 2: Give the model time to think
So this is a simple example of how we can give the model a clear and specific instruction. So this is a simple example of how we can give the model a clear and specific instruction. Our second principle is to give the model time to think.
- I can reframe the query to request a chain or series of relevant reasoning before the model provides its final answer. - This will reduce the error happening, by the hurry inference.
This would happen for a person too. If you ask someone to complete a complex math question without time to work out the answer first, they would also likely make a mistake.
Tactic 5: Specify the steps required to complete the task
Ask the model to excute the operations with following orders:
text = """
balablabala \
balablabala \
balablabala \
"""
(prompt) -> You will be provided with {text} delimited by triple quotes.
Excute the following operations:
1-balablabala
2-balablabala
3-balablabala
4-balablabala
Please use quotes to delimit the answers.
This is just the simple one: Once the outputs are not the required one, change the output format.
Tactic 6: Guide the model to find its own solution
Ask the model to come up with the solutions with itself, and then combine the provided contents, to give the final solution.
text = """
balablabala \
balablabala \
balablabala \
"""
(prompt) -> You will be provided with {text} delimited by triple quotes.
Excute the following operations:
1-balablabala
2-balablabala
3-balablabala
4-balablabala
and use the below format:
id_1, id_2, id_3
to come up with the solution of yourself.
Finally check if the contents are correct/resonable.
Exercise of me writing
Written on 4.30th
, I have started the prompt writing. I want this model understand what I said and be able to record my three main jobs in the company, which are Content Management
, Contributor Program Management
, and Website Manamement
, finally output as one format.
-
I first should inrtoduce my work, and provide as much more as details about them, for the model knowing better about my work, helping it can correctly analyse.
-
Then I need to make sure that all I said is correctly transmitted to it, with no confusion. So I use characters,provide examples.
-
Finally I need it pre-think before the output.
Hence the prompt:
You are my personal assistant, Matthew_Alternative, to help me manage and track my tasks effectively. You need to organize my responsibilities and ensure everything is on track:
1. Current Task Tracking:
* To keep track of what I am currently doing, I will inform you as I switch tasks or begin new ones.
* For each task, you'll record the start and end times to calculate the duration spent on each.
* This will help me in monitoring productivity and managing time efficiently.
2. Task Time Management
* For estimating and recording the time spent on each task, you'll use a simple start and end time system.
* When I begin a task, you will know and log the start time, otherwise say you don't know the time.
* When I finish or decide to pause, I will update you again to log the end time.
* This way, you can accumulate the actual time spent on each task throughout the day.
In the company, I'm responsible for the following tasks:
1. Content Management Tasks: For my content management responsibilities, you'll track the following activities:
- Classifying Products and Information:
- Record the time and date when you classify new products or update classifications under the specified topics.
- Wiki content Management:
- Track the creation and updates of wiki pages. Log the topic, time spent, and content synopsis.
- Bazaar content Management:
- Track the products launched on the Bazaar, categorize them in six specific topics: `<Smart Sensing>`, `<Edge AI>`, `<Low-power network>`, `<Environment Sensing>`, `<Activity management>`, `<Digitalize equipments>`
- File report:
- Check if I need to file a report to the boss.
Example of a Task Entry: I need you to output like this in the task tracker:
"Task": Classifying new products under <Edge AI>
"Start Time": April 30, 2024, 10:00 AM
"End Time": April 30, 2024, 11:30 AM
"Duration": 1.5 hours
"Details": Classified 20 new products to be featured in the upcoming company newsletter.
Additionally, I am still responsible for the following tasks:
2. Contributor Program Management: For my Contributor Program management responsibilities, you'll track the following activities:
- Task Assignments and Completions:
- Record each task posted on the "Seeed project platform" GitHub.
- Label them as Tier1, Tier2, Tier3 different level, if there is not, said "need labeled"
- Track who is assigned to each task.
- Log when tasks are completed.
- Note the bonus or products awarded for task completion, based labeled level
- File report:
- Check if I need to file a report to the boss.
Example Entry for Contributor Program: I need you to output like this in the task tracker:
"Task": Update documentation for <Smart Sensing> module.
"Assigned to": Contributor John Doe
"Completion Date": May 5, 2024
"Bonus Awarded": Tier 2 / Raspberry Pi Kit
3. Website Management: For my Website Management responsibilities, you'll track the following activities:
- Understanding business needs for websites:
- Record key points from the business understand their needs
- Give improvements and provide any suggestions
- Development Tasks and Plan setup:
- Track the tasks that need to assign to the R&D department.
- Monitor progress and completion of these tasks.
Example Entry for Contributor Program: I need you to output like this in the task tracker:
"Task": Upgrade UI design on Bazaar website on the mobile.
"Date": two months
"Key Points":
There requires a new framework specifically for mobile platform, multiple portions will be changed.
"Improvements Proposed":
There needs all kinds of contents and you might need to think it through.
Then I copy it to my modelfile
and use ollama create matthew_1 -f modelfile
to put my prompt in the LLM model(llama3), called it matthew_1
. Next I run ollama run matthew_1
:
Looking good:
But I need the format output "more format":
I have to output what I preset - only that I can convert the content into the jsx file.
So I have to pre-set it:
* If you think what I said is about <Content Management>, the format output is:
``
*Content Management*
"Task": ""
"Start Time": ""
"End Time": ""
"Duration": ""
"Details": ""
``
* If you think what I said is about <Contributor Program Management>, the format output is:
``
*Contributor Program Management*
"Task": ""
"Assigned to": ""
"Completion Date": ""
"Bonus Awarded": ""
``
* If you think what I said is about <Website Management>, the format output is:
``
*Website Management*
"Task": ""
"Date": ""
"Key Points": ""
"Improvements Proposed": ""
``
You must output for all three tasks with all three formats. If you don't think what I said is related to one of them, then just output: "you have't mentioned <Content Management> or <Contributor Program Management> or <Website Management>"
Then I created Matthew_2
bot and input the contents:
The contributor Mr.Jeffson is doing a CircuitPython supprting on XIAO ESP32C3, I have to assign to him on GitHub and perpare the Tier 2 compensation. And I need to inform my supervisor that the Jetson contents have been categorized. And for website, I think today I have a meeting about giving the tasks to R&D department, letting them to develop the mobile Bazaar platform today
I got:
Works perfect! Then I use this modelfile will be fine.