Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator: Ollama #876

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

generator: Ollama #876

wants to merge 9 commits into from

Conversation

martinebl
Copy link

Add two Ollama generators, using either the chat or generate functions from the Ollama package.
Add tests, that are skipped when no Ollama server is running.

The tests are skipped when no Ollama server can be found.
Copy link
Contributor

github-actions bot commented Sep 3, 2024

DCO Assistant Lite bot All contributors have signed the DCO ✍️ ✅

@martinebl
Copy link
Author

I have read the DCO Document and I hereby sign the DCO

@martinebl
Copy link
Author

recheck

github-actions bot added a commit that referenced this pull request Sep 3, 2024
@leondz leondz added generators Interfaces with LLMs new plugin Describes an entirely new probe, detector, generator or harness labels Sep 4, 2024
@leondz
Copy link
Owner

leondz commented Sep 4, 2024

Thanks for this! Will take a look

Copy link
Collaborator

@jmartin-tech jmartin-tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, this should work for a local service and the change to access instance parameters will enable config.

Tests need a bit of work to have proper value.

garak/generators/ollama.py Outdated Show resolved Hide resolved
garak/generators/ollama.py Outdated Show resolved Hide resolved
garak/generators/ollama.py Outdated Show resolved Hide resolved
garak/generators/ollama.py Outdated Show resolved Hide resolved
tests/generators/test_ollama.py Outdated Show resolved Hide resolved
martinebl and others added 3 commits September 12, 2024 19:51
Co-authored-by: Jeffrey Martin <jmartin@Op3n4M3.dev>
Signed-off-by: Martin <31307962+martinebl@users.noreply.github.com>
@leondz leondz linked an issue Sep 13, 2024 that may be closed by this pull request
@leondz leondz changed the title Ollama generator generator: Ollama Sep 24, 2024

@backoff.on_exception(
backoff.fibo,
(TimeoutError, ollama.ResponseError),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing shows TimeoutError may not be the exception that should be handled here.

This exception here is an OSError not a request timeout.

class TimeoutError(OSError): ...

Example failure:

  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/site-packages/httpx/_transports/default.py", line 69, in map_httpcore_exceptions
    yield
  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/site-packages/httpx/_transports/default.py", line 233, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py", line 216, in handle_request
    raise exc from None
  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py", line 196, in handle_request
    response = connection.handle_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/site-packages/httpcore/_sync/connection.py", line 101, in handle_request
    return self._connection.handle_request(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 143, in handle_request
    raise exc
  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 113, in handle_request
    ) = self._receive_response_headers(**kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 186, in _receive_response_headers
    event = self._receive_event(timeout=timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 224, in _receive_event
    data = self._network_stream.read(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/site-packages/httpcore/_backends/sync.py", line 124, in read
    with map_exceptions(exc_map):
  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/home/jemartin/miniconda3/envs/garak/lib/python3.12/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ReadTimeout: timed out

The expected timeout class would be httpx.TimeoutException which would cover ConnectTimeout, ReadTimeout, WriteTimeout, & PoolTimeout:

from httpx import TimeoutException
Suggested change
(TimeoutError, ollama.ResponseError),
(TimeoutException, ollama.ResponseError),

This would apply to both implementation of _call_model().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generators Interfaces with LLMs new plugin Describes an entirely new probe, detector, generator or harness
Projects
None yet
Development

Successfully merging this pull request may close these issues.

generator: ollama
3 participants