# `outlines-haystack`
[](https://pypi.org/project/outlines-haystack)
[](https://pypi.org/project/outlines-haystack)
[](https://pypi.org/project/outlines-haystack)
[](https://github.com/psf/black)
[](https://github.com/astral-sh/ruff)
[](https://github.com/EdAbati/outlines-haystack/actions/workflows/test.yml)
[](https://results.pre-commit.ci/latest/github/EdAbati/outlines-haystack/main)
-----
## Table of Contents
- [🛠️ Installation](#installation)
- [📃 Description](#description)
- [💻 Usage](#usage)
## 🛠️ Installation
```console
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](https://dottxt.co).
>
> -- <cite>[Outlines docs](https://dottxt-ai.github.io/outlines/latest/welcome/)</cite>
This library allow you to use [`outlines`](https://dottxt-ai.github.io/outlines/latest/) generators in your [Haystack](https://haystack.deepset.ai) pipelines!
This library currently supports the following generators:
- [x] [JSON](https://dottxt-ai.github.io/outlines/latest/reference/generation/json/): generate a JSON object with a given schema
- [x] [Choices](https://dottxt-ai.github.io/outlines/latest/reference/generation/choices/): generate text from a list of options. Useful for classification tasks!
- [x] [Text](https://dottxt-ai.github.io/outlines/latest/reference/text/): _simply_ generate text
- [ ] [Regex](https://dottxt-ai.github.io/outlines/latest/reference/generation/regex/): ⚠️ coming soon
- [ ] [Format](https://dottxt-ai.github.io/outlines/latest/reference/generation/format/): ⚠️ coming soon
- [ ] [Grammar](https://dottxt-ai.github.io/outlines/latest/reference/generation/cfg/): ⚠️ coming soon
`outlines` supports a wide range of models and frameworks, we are currently supporting:
- [x] [OpenAI/Azure OpenAI](https://dottxt-ai.github.io/outlines/latest/reference/models/openai/)
- [x] [🤗 Transformers](https://dottxt-ai.github.io/outlines/latest/reference/models/transformers/)
- [x] [`mlx-lm`](https://dottxt-ai.github.io/outlines/latest/reference/models/mlxlm/)
## 💻 Usage
> [!TIP]
> See the [Example Notebooks](./notebooks) for complete examples.
>
> All below examples only use the `transformers` models.
### JSON Generation
```python
>>> 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](https://docs.haystack.deepset.ai/docs/generators) that offer more features.
```python
>>> 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](https://spdx.org/licenses/MIT.html) license.
Raw data
{
"_id": null,
"home_page": null,
"name": "outlines-haystack",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.13,>=3.9",
"maintainer_email": null,
"keywords": "ai, generative-ai, haystack, llm, machine-learning, nlp, outlines, structured-generation",
"author": "Edoardo Abati",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/a3/8d/6e19619da3b4c29b355c872a49cae9df16ceeef6e02a72c45439baebe6de/outlines_haystack-0.2.0.tar.gz",
"platform": null,
"description": "# `outlines-haystack`\n\n[](https://pypi.org/project/outlines-haystack)\n[](https://pypi.org/project/outlines-haystack)\n[](https://pypi.org/project/outlines-haystack)\n\n\n[](https://github.com/psf/black)\n[](https://github.com/astral-sh/ruff)\n\n[](https://github.com/EdAbati/outlines-haystack/actions/workflows/test.yml)\n[](https://results.pre-commit.ci/latest/github/EdAbati/outlines-haystack/main)\n\n-----\n\n## Table of Contents\n\n- [\ud83d\udee0\ufe0f Installation](#installation)\n- [\ud83d\udcc3 Description](#description)\n- [\ud83d\udcbb Usage](#usage)\n\n## \ud83d\udee0\ufe0f Installation\n\n```console\npip install outlines-haystack\n```\n\n## \ud83d\udcc3 Description\n\n> 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](https://dottxt.co).\n>\n> -- <cite>[Outlines docs](https://dottxt-ai.github.io/outlines/latest/welcome/)</cite>\n\nThis library allow you to use [`outlines`](https://dottxt-ai.github.io/outlines/latest/) generators in your [Haystack](https://haystack.deepset.ai) pipelines!\n\nThis library currently supports the following generators:\n- [x] [JSON](https://dottxt-ai.github.io/outlines/latest/reference/generation/json/): generate a JSON object with a given schema\n- [x] [Choices](https://dottxt-ai.github.io/outlines/latest/reference/generation/choices/): generate text from a list of options. Useful for classification tasks!\n- [x] [Text](https://dottxt-ai.github.io/outlines/latest/reference/text/): _simply_ generate text\n- [ ] [Regex](https://dottxt-ai.github.io/outlines/latest/reference/generation/regex/): \u26a0\ufe0f coming soon\n- [ ] [Format](https://dottxt-ai.github.io/outlines/latest/reference/generation/format/): \u26a0\ufe0f coming soon\n- [ ] [Grammar](https://dottxt-ai.github.io/outlines/latest/reference/generation/cfg/): \u26a0\ufe0f coming soon\n\n`outlines` supports a wide range of models and frameworks, we are currently supporting:\n- [x] [OpenAI/Azure OpenAI](https://dottxt-ai.github.io/outlines/latest/reference/models/openai/)\n- [x] [\ud83e\udd17 Transformers](https://dottxt-ai.github.io/outlines/latest/reference/models/transformers/)\n- [x] [`mlx-lm`](https://dottxt-ai.github.io/outlines/latest/reference/models/mlxlm/)\n\n## \ud83d\udcbb Usage\n\n> [!TIP]\n> See the [Example Notebooks](./notebooks) for complete examples.\n>\n> All below examples only use the `transformers` models.\n\n### JSON Generation\n\n```python\n>>> from enum import Enum\n>>> from pydantic import BaseModel\n>>> from outlines_haystack.generators.transformers import TransformersJSONGenerator\n>>> class User(BaseModel):\n... name: str\n... last_name: str\n\n>>> generator = TransformersJSONGenerator(\n... model_name=\"microsoft/Phi-3-mini-4k-instruct\",\n... schema_object=User,\n... device=\"cuda\",\n... sampling_algorithm_kwargs={\"temperature\": 0.5},\n... )\n>>> generator.warm_up()\n>>> generator.run(prompt=\"Create a user profile with the fields name, last_name\")\n{'structured_replies': [{'name': 'John', 'last_name': 'Doe'}]}\n```\n\n### Text Generation\n\n> [!TIP]\n> While `outlines` supports classic text generation, it excels at structured generation.\n> For text generation, consider using [Haystack's built-in text generators](https://docs.haystack.deepset.ai/docs/generators) that offer more features.\n\n```python\n>>> generator = TransformersTextGenerator(\n... model_name=\"microsoft/Phi-3-mini-4k-instruct\",\n... device=\"cuda\",\n... sampling_algorithm_kwargs={\"temperature\": 0.5},\n... )\n>>> generator.warm_up()\n>>> generator.run(prompt=\"What is the capital of Italy?\")\n{'replies': ['\\n\\n# Answer\\nThe capital of Italy is Rome.']}\n```\n\n## License\n\n`outlines-haystack` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.\n",
"bugtrack_url": null,
"license": null,
"summary": "Use `outlines` generators with Haystack.",
"version": "0.2.0",
"project_urls": {
"Documentation": "https://github.com/EdAbati/outlines-haystack#readme",
"Issues": "https://github.com/EdAbati/outlines-haystack/issues",
"Source": "https://github.com/EdAbati/outlines-haystack"
},
"split_keywords": [
"ai",
" generative-ai",
" haystack",
" llm",
" machine-learning",
" nlp",
" outlines",
" structured-generation"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "40c283b11026590022af1a91996c1a90fc6c012f1fe962f88ecc89690122f205",
"md5": "4d99341a4574bd135666b680af2cdcfe",
"sha256": "8666f72011ae5c2ac659143ab597866108f679301611386e546c8cae60f5cf80"
},
"downloads": -1,
"filename": "outlines_haystack-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4d99341a4574bd135666b680af2cdcfe",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.13,>=3.9",
"size": 15949,
"upload_time": "2025-02-16T22:40:37",
"upload_time_iso_8601": "2025-02-16T22:40:37.898770Z",
"url": "https://files.pythonhosted.org/packages/40/c2/83b11026590022af1a91996c1a90fc6c012f1fe962f88ecc89690122f205/outlines_haystack-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "a38d6e19619da3b4c29b355c872a49cae9df16ceeef6e02a72c45439baebe6de",
"md5": "53015dd94cfa5f4b9c6cc990a092a615",
"sha256": "09e4a51551be73b0fa0ef2f096a9373dd6af912dabb68c2dee02d12baa39953b"
},
"downloads": -1,
"filename": "outlines_haystack-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "53015dd94cfa5f4b9c6cc990a092a615",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.13,>=3.9",
"size": 22749,
"upload_time": "2025-02-16T22:40:39",
"upload_time_iso_8601": "2025-02-16T22:40:39.191541Z",
"url": "https://files.pythonhosted.org/packages/a3/8d/6e19619da3b4c29b355c872a49cae9df16ceeef6e02a72c45439baebe6de/outlines_haystack-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-16 22:40:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "EdAbati",
"github_project": "outlines-haystack#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "outlines-haystack"
}