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'}]}

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.

>>> 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.1.tar.gz (22.9 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.1-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for outlines_haystack-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1968152a9e7e19c4eafbcc8f0f27dcea5f24352257670271339fb8c1ce731e27
MD5 b9c9ec73c1ef89be68fa6b0dfbe7f7a2
BLAKE2b-256 d600ac2aa224b20b23ff098a4b95926cbb7eb55d7c20737e1ab805311814ff44

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for outlines_haystack-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d7506a427f4e5b2957573bf29fbc748e16073dd60941ca8e50fd4e784359621
MD5 1170bdf9177615a70607a5eb0458a3b2
BLAKE2b-256 cd75e7281c125bcf1c8e08b31aae97c10306afac03941a3b5f7adca1743e4aaa

See more details on using hashes here.

Provenance

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