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

Load chains and prompts from YAML using Catalogs #11

Merged
merged 5 commits into from
Aug 11, 2023

Conversation

rudolfolah
Copy link
Owner

  • A catalog is a collection of chains and prompts stored in a YAML file.
  • Makes it easier to share prompts and chains between projects and build up a prompts library
  • Chains are optional, prompts must be defined
  • When you use get_prompt the same arguments when constructing a new Prompt can be used

Usage

from chaincrafter import Catalog
# Load the catalog
catalog = Catalog()
path = os.path.dirname(__file__)
catalog.load(os.path.join(path, "catalog.yml"))
print(catalog["hello_world_prompt"])
print(catalog.get_prompt("hello_world_prompt"])
# Run the chain as usual
catalog.get_chain("example_chain").run(chat_model, {"input": "var", ...})

# Example of providing overrides for prompt modifiers and input vars transformers
followup_question_prompt = catalog.get_prompt(
    "followup_question",
    [
        response_style("a pirate who has just returned from the Galapagos Islands"),
        response_length("short", "4-5 sentences"),
    ],
    # Parses and extracts data from the previous response to populate the input variable that is used by the prompt
    facts_list=lambda facts_list: extract_items_from_list(facts_list)[0],
)

Catalog Format YAML

YAML file format for Catalogs:

prompts:
  helpful_assistant: You are a helpful assistant
  initial_code_review: |
    I just put a lot of work into this code, can you please review it and offer suggestions for improvement? Do not write any code.
    ```
    {diff}
    ```
  city_population: "{city} sounds like a nice place to visit. What is the population of {city}?"
chains:
  example:
    - helpful_assistant:
    - initial_code_review: city
    - city_population: output

@rudolfolah rudolfolah added the python Python-related issue label Aug 11, 2023
@rudolfolah rudolfolah self-assigned this Aug 11, 2023
@rudolfolah rudolfolah merged commit 61d1f2f into main Aug 11, 2023
@rudolfolah rudolfolah deleted the load-chains-and-prompts-from-yaml branch August 11, 2023 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Python-related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant