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.3.tar.gz (27.3 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.3-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: outlines_haystack-0.2.3.tar.gz
  • Upload date:
  • Size: 27.3 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.3.tar.gz
Algorithm Hash digest
SHA256 e1228f1d600a15fd634405f591eee18803f1f0dd2a164f92300f2abcf5f17775
MD5 955b102df037e466c6e7c35f6084ff4d
BLAKE2b-256 3521abf92ce4c2bb6c5f14155cb4a1e57ade92179cfbc0df9e03def4e077fd44

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for outlines_haystack-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7b8123366de1ef249e69650214295353469a18a8bfe5261e1f5c1b939115abc2
MD5 7c56df2ef292bea4a76482025c99613d
BLAKE2b-256 01f17242f54f1272b46dd2088585617ee1df125e5231057dcb38cebc662501bc

See more details on using hashes here.

Provenance

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