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).

Overview

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.11+

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

Use Cases

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)

Example

This is extending the chat dialog example from Guidance by running queries in parallel.

runner = OpenAIChat(model_id="gpt-3.5-turbo", api_config=API_CONFIG)
expert_names = GenerateText(
    Template(
        "I want a response to the following question:"
        "{{input}}\n"
        "Name 3 world-class experts (past or present) who would be great at answering this? Don't answer the question yet."
    ),
    system_prompt="You are a helpful and terse assistant.",
    randomness=0,
    max_tokens=300,
)

joint_answer = GenerateText(
    "Great, now please answer the question as if these experts had collaborated in writing a joint anonymous answer.",
    history=expert_names,
    randomness=0,
    max_tokens=500,
)

questions = [
    "How can I be more productive?",
    "What will AI look like in 10 years?",
    "How do we end world hunger?",
]
print(Output(joint_answer).run(runner, questions))

Licence

This project is licensed under MIT.

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.2.4.tar.gz (61.9 kB view details)

Uploaded Source

Built Distribution

sammo-0.2.4-py3-none-any.whl (71.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sammo-0.2.4.tar.gz
  • Upload date:
  • Size: 61.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for sammo-0.2.4.tar.gz
Algorithm Hash digest
SHA256 860455e716aeb6eb2eaf4569ee9c92717c5be166c44d48b598459e5dee0320aa
MD5 ad8e95dd4d01339f87821a4e145560e9
BLAKE2b-256 3b40f8b2cfe0239424446852c69665e8e66471f3899bc315acc95fb6f4bda6b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sammo-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 71.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for sammo-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6189762cd8afe0b4b2c09dbc08b7aab3631d8252479bb02c6a7df2bb952ea2fa
MD5 d2f1ec3708a791c09e6b0582b0d5f382
BLAKE2b-256 1266b48fcdb2b358cad54adb552e7e7444173d84003cdd1efb1b594e9a844b71

See more details on using hashes here.

Supported by

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