Skip to main content

Use `outlines` generators with Haystack.

Project description

outlines-haystack

PyPI - Version PyPI - Python Version PyPI - License

Code style: black Ruff

GH Actions Tests pre-commit.ci status


Table of Contents

🛠️ Installation

pip install outlines-haystack

📃 Description

Outlines is a Python library that allows you to use Large Language Model in a simple and robust way (with structured generation). It is built by .txt.

-- Outlines docs

This library allow you to use outlines generators in your Haystack pipelines!

This library currently supports the following generators:

  • JSON: generate a JSON object with a given schema
  • Choices: generate text from a list of options. Useful for classification tasks!
  • Text: simply generate text
  • Regex: ⚠️ coming soon
  • Format: ⚠️ coming soon
  • Grammar: ⚠️ coming soon

outlines supports a wide range of models and frameworks, we are currently supporting:

💻 Usage

[!TIP] See the Example Notebooks for complete examples.

All below examples only use the transformers models.

JSON Generation

>>> from enum import Enum
>>> from pydantic import BaseModel
>>> from outlines_haystack.generators.transformers import TransformersJSONGenerator

>>> class User(BaseModel):
...    name: str
...    last_name: str

>>> generator = TransformersJSONGenerator(
...     model_name="microsoft/Phi-3-mini-4k-instruct",
...     schema_object=User,
...     device="cuda",
...     sampling_algorithm_kwargs={"temperature": 0.5},
... )
>>> generator.warm_up()
>>> generator.run(prompt="Create a user profile with the fields name, last_name")
{'structured_replies': [{'name': 'John', 'last_name': 'Doe'}]}

Choice Generation

>>> from outlines_haystack.generators.transformers import TransformersChoiceGenerator

>>> generator = TransformersChoiceGenerator(
...     model_name="microsoft/Phi-3-mini-4k-instruct",
...     choices=["Positive", "Negative"],
...     device="cuda",
...     sampling_algorithm_kwargs={"temperature": 0.5},
... )
>>> generator.warm_up()
>>> generator.run(prompt="Classify the following statement: 'I love pizza'")
{'choice': 'Positive'}

Text Generation

[!TIP] While outlines supports classic text generation, it excels at structured generation. For text generation, consider using Haystack's built-in text generators that offer more features.

>>> from outlines_haystack.generators.transformers import TransformersTextGenerator

>>> generator = TransformersTextGenerator(
...     model_name="microsoft/Phi-3-mini-4k-instruct",
...     device="cuda",
...     sampling_algorithm_kwargs={"temperature": 0.5},
... )
>>> generator.warm_up()
>>> generator.run(prompt="What is the capital of Italy?")
{'replies': ['\n\n# Answer\nThe capital of Italy is Rome.']}

License

outlines-haystack is distributed under the terms of the MIT license.

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

outlines_haystack-0.2.2.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

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

outlines_haystack-0.2.2-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file outlines_haystack-0.2.2.tar.gz.

File metadata

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

File hashes

Hashes for outlines_haystack-0.2.2.tar.gz
Algorithm Hash digest
SHA256 e138fd333aebd5aebc0217dad41061b0c53d791a1ae8fbf2c6e17db936af55eb
MD5 b44a0b0d36fc3ef74fd18a87339c5a79
BLAKE2b-256 5c3dfef437245e4c6b1b29ce7e268b81171cd6ad48d50bf539853234a6313541

See more details on using hashes here.

Provenance

The following attestation bundles were made for outlines_haystack-0.2.2.tar.gz:

Publisher: publish.yml on EdAbati/outlines-haystack

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

File details

Details for the file outlines_haystack-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for outlines_haystack-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 429919b025b356c0dc07d33ac970ea5ac3c093becee49ee3122db5749537ee3e
MD5 c3ad7c3e93b6f307b07359a64fc3f852
BLAKE2b-256 86d4937508f7d908d2f1dc81b5639484d26de120a6580818ecf7f644e2c50fec

See more details on using hashes here.

Provenance

The following attestation bundles were made for outlines_haystack-0.2.2-py3-none-any.whl:

Publisher: publish.yml on EdAbati/outlines-haystack

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