Module: StubOllamaServer
- Defined in:
- spec/spec_helper.rb
Overview
A module that provides functionality for stubbing Ollama server responses.
The StubOllamaServer module enables developers to simulate Ollama API interactions in test environments by intercepting requests and returning predefined responses. This allows for faster, more reliable testing without requiring external service calls.
Instance Method Summary collapse
-
#connect_to_ollama_server(instantiate: true) ⇒ Object
The connect_to_ollama_server method establishes a connection to an Ollama server.
Instance Method Details
#connect_to_ollama_server(instantiate: true) ⇒ Object
The connect_to_ollama_server method establishes a connection to an Ollama server.
This method sets up stubbed HTTP requests to simulate responses from an Ollama server, including API tags, show, and version endpoints. It can optionally instantiate a chat session after setting up the stubs.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'spec/spec_helper.rb', line 95 def connect_to_ollama_server(instantiate: true) before do stub_request(:get, %r(/api/tags\z)). to_return(status: 200, body: asset_json('api_tags.json')) stub_request(:post, %r(/api/show\z)). to_return(status: 200, body: asset_json('api_show.json')) stub_request(:get, %r(/api/version\z)). to_return(status: 200, body: asset_json('api_version.json')) instantiate and chat end end |