Skip to main content

A flexible, easy-to-use library for running and optimizing prompts for Large Language Models (LLMs).

Project description

SAMMO (📘User Guide)

Latest PyPI version License: MIT Binder

A flexible, easy-to-use library for running and optimizing prompts for Large Language Models (LLMs).

🎉 News

  • Nov 13, 2024: Turn Markdown into prompt programs: First version of SAMMO express released
  • Nov 1, 2024: Use CSS selectors to query and modify prompt programs!
  • Oct 15, 2024: SAMMO now supports structured outputs!

How to Get Started

Go to the user guide for examples, how-tos, and API reference.

Just want to have a quick look? Try the live demo on Binder.

Install library only

pip install sammo

Install and run tutorials

Prerequisites

  • Python 3.9+

The following commands will install sammo and jupyter and launch jupyter notebook. It's recommended that you create and activate a virtualenv prior to installing packages.

pip install sammo jupyter

# clone sammo to a local directory
git clone https://github.com/microsoft/sammo.git
cd sammo

# launch jupyter notebook and open tutorials directory
jupyter notebook --notebook-dir docs/tutorials

Example

This example shows how easy it is to optimize a prompt with SAMMO. The full example is in the user guide.

runner = OpenAIChat(model_id="gpt-3.5-turbo", api_config=API_CONFIG)
PROMPT_IN_MARKDOWN = """
# Instructions <!-- #instr -->
Convert the following user queries into a SQL query.

# Table
Users:
- user_id (INTEGER, PRIMARY KEY)
- name (TEXT)
- age (INTEGER)
- city (TEXT)

# Complete this
Input: {{{input}}}
Output:
"""

spp = MarkdownParser(PROMPT_IN_MARKDOWN).get_sammo_program()
mutation_operators = BagOfMutators(
    Output(GenerateText(spp)),
    Paraphrase("#instr"),
    Rewrite("#instr", "Make this more verbose.\n\n {{{{text}}}}")
)
prompt_optimizer = BeamSearch(runner, mutation_operators, accuracy)
prompt_optimizer.fit(d_train)
prompt_optimizer.show_report()

Use Cases

Overview

SAMMO is designed to support

  • Efficient data labeling: Supports minibatching by packing and parsing multiple datapoints into a single prompt.
  • Prompt prototyping and engineering: Re-usable components and prompt structures to quickly build and test new prompts.
  • Instruction optimization: Optimize instructions to do better on a given task.
  • Prompt compression: Compress prompts while maintaining performance.
  • Large-scale prompt execution: parallelization and rate-limiting out-of-the-box so you can run many queries in parallel and at scale without overwhelming the LLM API.

It is less useful if you want to build

  • Interactive, agent-based LLM applications (→ check out AutoGen)
  • Interactive, production-ready LLM applications (→ check out LangChain)

Licence

This project is licensed under MIT.

To cite this paper, you can use the following BibTeX entry:

@inproceedings{schnabel-neville-2024-symbolic,
    title = "Symbolic Prompt Program Search: A Structure-Aware Approach to Efficient Compile-Time Prompt Optimization",
    author = "Schnabel, Tobias and Neville, Jennifer",
    booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2024",
    year = "2024",
    url = "https://aclanthology.org/2024.findings-emnlp.37",
    pages = "670--686"
}

Authors

SAMMO was written by Tobias Schnabel.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sammo-0.3.3.tar.gz (68.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sammo-0.3.3-py3-none-any.whl (80.3 kB view details)

Uploaded Python 3

File details

Details for the file sammo-0.3.3.tar.gz.

File metadata

  • Download URL: sammo-0.3.3.tar.gz
  • Upload date:
  • Size: 68.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sammo-0.3.3.tar.gz
Algorithm Hash digest
SHA256 2e2602d9ed17fdd74ad00e4ab2d8908bf5b8c55bfd4ef0f7b534107bbcb92128
MD5 31f3043136529f40a482512a7eb3d7a0
BLAKE2b-256 15d0905cd2efa7b53d47cf69a7037eb4776403aa27903d5ef6a39559d0a23743

See more details on using hashes here.

Provenance

The following attestation bundles were made for sammo-0.3.3.tar.gz:

Publisher: build.yml on microsoft/sammo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sammo-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: sammo-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 80.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sammo-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 64e10dfda4eaa6b3ff5063c69fc4650a29c577094927841112b7805ecf7f0c63
MD5 e3d7555dac906e9dc8143ad808dcaa71
BLAKE2b-256 5ae7c882ad206e796a4aa3fec748dc71991d8a21055c59350b75379a300bee01

See more details on using hashes here.

Provenance

The following attestation bundles were made for sammo-0.3.3-py3-none-any.whl:

Publisher: build.yml on microsoft/sammo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page