-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ollama generator * add test skeleton * add __inits__ * add __inits__ * add __inits__ * add pyproject * add version * Add instructions for building local environment * Add integration tests using docker ollama service * Add integration test market in pyproject.toml * lint with black * Delete integrations/__init__.py * drop unused dunders * update pyproject based on elasticsearch integration * rename metadata to meta * Use full /generate URL from ollama in init * add docstrings and additional post arguments * add github action * change single to double quotes in tests * fix init paths * make timeout argument explicit in POST * lint with black * fix typo from jina to ollama in hatch lint * ignore pytest and haystack typing issues * correct type hint in output type * add assertion for replies and meta in tests * update labeler with ollama * try to install and run ollama wo docker * try to see if the issue with ports is related to concurrency * another try * better try to run ollama * Update ollama.yml * Update ollama.yml * simplify docker-compose * try to pull the model when the container is already running * add -d * Update ollama.yml * Delete integrations/ollama/docker-compose.yml * Update integrations/ollama/pyproject.toml Co-authored-by: Stefano Fiorucci <[email protected]> * Add timeout to POST Request * Remove unpacking of dictionary arguments to pass mypy * Add docstring to run function * add test for init defaults, delete telemetry tests * drop use of dataclass for housing response data * modify type hints in protected methods * update readme with new docker testing regime * refactor post_args to json payload only * try using a github service for Ollama * modify post_args test to new json_payload * add ollama integration to general README * refinements * fix tests * rm unused fixture --------- Co-authored-by: Stefano Fiorucci <[email protected]>
- Loading branch information
1 parent
0d0c1af
commit b80138e
Showing
9 changed files
with
497 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# This workflow comes from https://github.com/ofek/hatch-mypyc | ||
# https://github.com/ofek/hatch-mypyc/blob/5a198c0ba8660494d02716cfc9d79ce4adfb1442/.github/workflows/test.yml | ||
name: Test / ollama | ||
|
||
on: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
pull_request: | ||
paths: | ||
- "integrations/ollama/**" | ||
- ".github/workflows/ollama.yml" | ||
|
||
concurrency: | ||
group: ollama-${{ github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
PYTHONUNBUFFERED: "1" | ||
FORCE_COLOR: "1" | ||
LLM_FOR_TESTS: "orca-mini" | ||
|
||
jobs: | ||
run: | ||
name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest] | ||
python-version: ["3.9","3.10","3.11"] | ||
services: | ||
ollama: | ||
image: ollama/ollama:latest | ||
ports: | ||
- 11434:11434 | ||
options: --name ollama | ||
|
||
steps: | ||
- name: Pull the LLM in the Ollama service | ||
run: docker exec ollama ollama pull ${{ env.LLM_FOR_TESTS }} | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install Hatch | ||
run: pip install --upgrade hatch | ||
|
||
- name: Lint | ||
working-directory: integrations/ollama | ||
if: matrix.python-version == '3.9' | ||
run: hatch run lint:all | ||
|
||
- name: Run tests | ||
working-directory: integrations/ollama | ||
run: hatch run cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# ollama-haystack | ||
|
||
[![PyPI - Version](https://img.shields.io/pypi/v/ollama-haystack.svg)](https://pypi.org/project/ollama-haystack) | ||
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ollama-haystack.svg)](https://pypi.org/project/ollama-haystack) | ||
|
||
----- | ||
|
||
**Table of Contents** | ||
|
||
- [Installation](#installation) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
```console | ||
pip install ollama-haystack | ||
``` | ||
|
||
## License | ||
|
||
`ollama-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license. | ||
|
||
## Testing | ||
|
||
To run tests first start a Docker container running Ollama and pull a model for integration testing | ||
It's recommended to use the smallest model possible for testing purposes - see https://ollama.ai/library for a list that Ollama supportd | ||
|
||
```console | ||
docker run -d -p 11434:11434 --name ollama ollama/ollama:latest | ||
docker exec ollama ollama pull <your model here> | ||
``` | ||
|
||
Then run tests: | ||
|
||
```console | ||
hatch run test | ||
``` | ||
|
||
The default model used here is ``orca-mini`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
[build-system] | ||
requires = ["hatchling", "hatch-vcs"] | ||
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "ollama-haystack" | ||
dynamic = ["version"] | ||
description = 'An integration between the Ollama LLM framework and Haystack' | ||
readme = "README.md" | ||
requires-python = ">=3.8" | ||
license = "Apache-2.0" | ||
keywords = [] | ||
authors = [ | ||
{ name = "Alistair Rogers", email = "[email protected]" }, | ||
{ name = "Sachin Sachdeva", email = "[email protected]" }, | ||
{ name = "deepset GmbH", email = "[email protected]" }, | ||
] | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
"Programming Language :: Python :: Implementation :: PyPy", | ||
] | ||
dependencies = ["haystack-ai", "requests"] | ||
|
||
[project.urls] | ||
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/ollama#readme" | ||
Issues = "https://github.com/deepset-ai/haystack-core-integrations/issues" | ||
Source = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/ollama" | ||
|
||
[tool.hatch.version] | ||
source = "vcs" | ||
tag-pattern = 'integrations\/ollama-v(?P<version>.*)' | ||
|
||
[tool.hatch.version.raw-options] | ||
root = "../.." | ||
git_describe_command = 'git describe --tags --match="integrations/ollama-v[0-9]*"' | ||
|
||
[tool.hatch.envs.default] | ||
dependencies = [ | ||
"coverage[toml]>=6.5", | ||
"pytest", | ||
] | ||
[tool.hatch.envs.default.scripts] | ||
test = "pytest {args:tests}" | ||
test-cov = "coverage run -m pytest {args:tests}" | ||
cov-report = [ | ||
"- coverage combine", | ||
"coverage report", | ||
] | ||
cov = [ | ||
"test-cov", | ||
"cov-report", | ||
] | ||
|
||
[[tool.hatch.envs.all.matrix]] | ||
python = ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
|
||
|
||
[tool.hatch.envs.lint] | ||
detached = true | ||
dependencies = [ | ||
"black>=23.1.0", | ||
"mypy>=1.0.0", | ||
"ruff>=0.0.243", | ||
] | ||
|
||
[tool.hatch.envs.lint.scripts] | ||
typing = "mypy --install-types --non-interactive {args:src/ollama_haystack tests}" | ||
style = [ | ||
"ruff {args:.}", | ||
"black --check --diff {args:.}", | ||
] | ||
fmt = [ | ||
"black {args:.}", | ||
"ruff --fix {args:.}", | ||
"style", | ||
] | ||
all = [ | ||
"style", | ||
"typing", | ||
] | ||
|
||
[tool.hatch.metadata] | ||
allow-direct-references = true | ||
|
||
[tool.ruff.isort] | ||
known-first-party = ["ollama_haystack"] | ||
|
||
[tool.black] | ||
target-version = ["py37"] | ||
line-length = 120 | ||
skip-string-normalization = true | ||
|
||
[tool.ruff] | ||
target-version = "py37" | ||
line-length = 120 | ||
select = [ | ||
"A", | ||
"ARG", | ||
"B", | ||
"C", | ||
"DTZ", | ||
"E", | ||
"EM", | ||
"F", | ||
"I", | ||
"ICN", | ||
"ISC", | ||
"N", | ||
"PLC", | ||
"PLE", | ||
"PLR", | ||
"PLW", | ||
"Q", | ||
"RUF", | ||
"S", | ||
"T", | ||
"TID", | ||
"UP", | ||
"W", | ||
"YTT", | ||
] | ||
ignore = [ | ||
# Allow non-abstract empty methods in abstract base classes | ||
"B027", | ||
# Ignore checks for possible passwords | ||
"S105", "S106", "S107", | ||
# Ignore complexity | ||
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915", | ||
] | ||
unfixable = [ | ||
# Don't touch unused imports | ||
"F401", | ||
] | ||
|
||
[tool.ruff.flake8-tidy-imports] | ||
ban-relative-imports = "all" | ||
|
||
[tool.ruff.per-file-ignores] | ||
# Tests can use magic values, assertions, and relative imports | ||
"tests/**/*" = ["PLR2004", "S101", "TID252"] | ||
|
||
|
||
[tool.coverage.run] | ||
source_pkgs = ["ollama_haystack", "tests"] | ||
branch = true | ||
parallel = true | ||
|
||
|
||
[tool.coverage.paths] | ||
ollama_haystack = ["src/ollama_haystack", "*/ollama-haystack/src/ollama_haystack"] | ||
tests = ["tests", "*/ollama-haystack/tests"] | ||
|
||
[tool.coverage.report] | ||
exclude_lines = [ | ||
"no cov", | ||
"if __name__ == .__main__.:", | ||
"if TYPE_CHECKING:", | ||
] | ||
|
||
[tool.pytest.ini_options] | ||
markers = [ | ||
"integration: marks tests as slow (deselect with '-m \"not integration\"')", | ||
] | ||
addopts = [ | ||
"--import-mode=importlib", | ||
] | ||
|
||
[[tool.mypy.overrides]] | ||
module = [ | ||
"haystack.*", | ||
"pytest.*" | ||
] | ||
ignore_missing_imports = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-FileCopyrightText: 2023-present deepset GmbH <[email protected]> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from ollama_haystack.generator import OllamaGenerator | ||
|
||
__all__ = ["OllamaGenerator"] |
Oops, something went wrong.