Few-Shot Prompting
LLMs are highly capable of following a given structure. By providing a few examples of how the assistant should respond to a given prompt, the LLM can generate responses that closely follow the format of these examples.
Portkey enhances this capability with the raw prompt feature of prompt templates. You can easily add few-shot learning examples to your templates with raw prompt and dynamically update them whenever you want, without needing to modify the prompt templates!
How does it work?
Let’s consider a use case where, given a candidate profile and a job description, the LLM is expected to output candidate notes in a specific JSON format.
This is how our raw prompt looks:
Let’s define our variables:
As you can see, we have added variables few_shot_examples
, profile
, and jd
in the above examples.
And now let’s add some examples with the expected JSON structure:
In this configuration, {{few_shot_examples}}
is a placeholder for the few-shot learning examples, which are dynamically provided and can be updated as needed. This allows the LLM to adapt its responses to the provided examples, facilitating versatile and context-aware outputs.
Putting it all together in Portkey’s prompt manager:
- Go to the “Prompts” page on https://app.portkey.ai/ and Create a new Prompt template with your preferred AI provider.
- Selecting Chat mode will enable the Raw Prompt feature:
- Click on it and paste the raw prompt code from above. And that’s it! You have your dynamically updatable few shot prompt template ready to deploy.
Deploying the Prompt with Portkey
Deploying your prompt template to an API is extremely easy with Portkey. You can use our Prompt Completions API to use the prompt we created.
You can pass your dynamic few shot learning examples with the few_shot_examples
variable, and start using the prompt template in production!
Detailed Guide on Few-Shot Prompting
We recommend this guide detailing the research as well as edge cases for few-shot prompting.
Support
Facing an issue? Reach out on [email protected] for a quick resolution.
Was this page helpful?