Skip to main content

Use `outlines` generators with Haystack.

Project description

outlines-haystack

PyPI - Version PyPI - Python Version PyPI - License 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.5.tar.gz (11.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.5-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for outlines_haystack-0.2.5.tar.gz
Algorithm Hash digest
SHA256 ff6d7a36b9b215ce219b55b7e28b7bb34e89346a1d0c53d6f6ca537d20615982
MD5 658a487001f00fae1e71588091523ef2
BLAKE2b-256 b972370d146468dac14fccfe5bb3de4055dc84725b48b2de5034ef6873b2babd

See more details on using hashes here.

Provenance

The following attestation bundles were made for outlines_haystack-0.2.5.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.5-py3-none-any.whl.

File metadata

File hashes

Hashes for outlines_haystack-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fd9a3c88e0aabba0f070a035e80a09535001f0bcb586c86a4d178a401d769255
MD5 beefd2a2942c1b09511c2af189c84e30
BLAKE2b-256 d5a924a12264f47ed25d2905e6c43aef1cc78c451e5f0af06e66a45c576e7c94

See more details on using hashes here.

Provenance

The following attestation bundles were made for outlines_haystack-0.2.5-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