diff --git a/docs/examples.md b/docs/examples.md index 7f6f66f..3f373c4 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -140,7 +140,7 @@ Summary: ## Use a LLM to generate a text while rendering a prompt Sometimes it might be useful to ask another LLM to generate examples for you in a -few-shot prompt. Provided you have a valid OpenAI API key stored in an env var +few-shots prompt. Provided you have a valid OpenAI API key stored in an env var called `OPENAI_API_KEY` you can ask Banks to do something like this (note we can annotate the prompt using comments - anything within `{# ... #}` will be removed from the final prompt): @@ -150,16 +150,17 @@ from banks import Prompt prompt_template = """ -Generate a tweet about the topic {{ topic }} with a positive sentiment. +{% set examples %} +{% completion model="gpt-3.5-turbo-0125" %} + {% chat role="system" %}You are a helpful assistant{% endchat %} + {% chat role="user" %}Generate a bullet list of 3 tweets with a positive sentiment.{% endchat %} +{% endcompletion %} +{% endset %} -{# - This is for illustration purposes only, there are better and cheaper ways - to generate examples for a few-shots prompt. -#} +{# output the response content #} +Generate a tweet about the topic {{ topic }} with a positive sentiment. Examples: -{% for number in range(3) %} -- {% generate "write a tweet with positive sentiment" "gpt-3.5-turbo" %} -{% endfor %} +{{ examples }} """ p = Prompt(prompt_template) @@ -169,24 +170,14 @@ print(p.text({"topic": "climate change"})) The output would be something similar to the following: ```txt Generate a tweet about the topic climate change with a positive sentiment. - - Examples: - -- "Feeling grateful for the amazing capabilities of #GPT3.5Turbo! It's making my work so much easier and efficient. Thank you, technology!" #positivity #innovation - -- "Feeling grateful for all the opportunities that come my way! With #GPT3.5Turbo, I am able to accomplish tasks faster and more efficiently. #positivity #productivity" - -- "Feeling grateful for all the wonderful opportunities and experiences that life has to offer! #positivity #gratitude #blessed #gpt3.5turbo" -``` - -If you paste Banks' output into ChatGPT you would get something like this: -```txt -Climate change is a pressing global issue, but together we can create positive change! Let's embrace renewable energy, protect our planet, and build a sustainable future for generations to come. 🌍💚 #ClimateAction #PositiveFuture +- "Feeling grateful for the sunshine today! 🌞 #thankful #blessed" +- "Just had a great workout and feeling so energized! 💪 #fitness #healthyliving" +- "Spent the day with loved ones and my heart is so full. 💕 #familytime #grateful" ``` > [!IMPORTANT] -> The `generate` extension uses [LiteLLM](https://github.com/BerriAI/litellm) under the hood, and provided you have the +> The `completion` extension uses [LiteLLM](https://github.com/BerriAI/litellm) under the hood, and provided you have the > proper environment variables set, you can use any model from the supported [model providers](https://docs.litellm.ai/docs/providers). > [!NOTE]