org.slashlib.py.inference.ollama 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ [AI](AI.md) [CHANGELOG](CHANGELOG.md) [README](README.md)
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2026 Dirk Brenckmann, db-developer
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: org.slashlib.py.inference.ollama
3
+ Version: 0.1.2
4
+ Summary: python inference handler for agents
5
+ Author-email: Dirk Brenckmann <db.developer@gmx.de>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/org-slashlib/org.slashlib.py.inference.ollama
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE.md
13
+ Requires-Dist: org.slashlib.py.agent>=0.1.5
14
+ Requires-Dist: org.slashlib.py.configloader>=0.1.0
15
+ Dynamic: license-file
16
+
17
+ [Bottom](#license) [AI](AI.md) [CHANGELOG](CHANGELOG.md) [LICENSE](LICENSE.md)
18
+ # org.slashlib.py.inference.ollama
19
+
20
+ The official **Ollama** inference adapter for the `org.slashlib.py.agent` framework.
21
+
22
+ [![PyPI version](https://img.shields.io/pypi/v/org.slashlib.py.inference.ollama.svg?color=blue)](https://pypi.org/project/org.slashlib.py.inference.ollama/)
23
+ [![PyPI-Test version](https://img.shields.io/badge/pypitest-latest-blue)](https://test.pypi.org/project/org.slashlib.py.inference.ollama/)
24
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
25
+
26
+ ---
27
+
28
+ ## 1. Overview & Architecture
29
+
30
+ This project provides a specialized implementation of the `InferenceAdapter` interface from the core **Agent Framework**. By decoupling the Ollama logic from the main framework, we ensure a lightweight core and allow for independent updates to the inference logic.
31
+
32
+ ### Architectural Role
33
+ - **Adapter Pattern**: Bridges the standardized framework calls to the Ollama-specific API.
34
+ - **Provider Agnostic**: The framework consumes this adapter through a unified interface.
35
+ - **Plugin-Based**: Leverages Python entry points for seamless, zero-config integration.
36
+
37
+ ---
38
+
39
+ ## 2. Prerequisites
40
+
41
+ - **Ollama Service**: Must be installed and reachable (Default: `http://localhost:11434`).
42
+ - **Python**: Version 3.10 or higher.
43
+ - **Base Framework**: `org.slashlib.py.agent` must be installed in the same environment.
44
+
45
+ ---
46
+
47
+ ## 3. Installation
48
+
49
+ ### Production / Standard
50
+ ```bash
51
+ pip install org.slashlib.py.inference.ollama
52
+ ```
53
+
54
+ ### Development (Editable Mode)
55
+ If you are developing both the framework and this adapter, install both in editable mode to ensure the **Entry Points** are correctly registered in your current Python environment:
56
+
57
+ ```bash
58
+ # 1. Install the framework
59
+ cd path/to/org.slashlib.py.agent
60
+ pip install -e .
61
+
62
+ # 2. Install this adapter
63
+ cd path/to/org.slashlib.py.inference.ollama
64
+ pip install -e .
65
+ ```
66
+
67
+ ---
68
+
69
+ ## 4. Integration Logic (Entry Points)
70
+
71
+ This adapter is designed to be \"invisible\" to the end user. It registers itself via the `pyproject.toml` entry points:
72
+
73
+ ```toml
74
+ [project.entry-points.\"org.slashlib.py.agent.inference\"]
75
+ ollama = \"org.slashlib.py.inference.ollama.adapter:OllamaInferenceAdapter\"
76
+ ```
77
+
78
+ The framework automatically scans this group and maps the name `ollama` to the `OllamaInferenceAdapter` class.
79
+
80
+ ---
81
+
82
+ ## 5. Configuration
83
+
84
+ The adapter's behavior is controlled via the framework's configuration loader (usually `pyproject.json`).
85
+
86
+ | Key | Type | Default | Description |
87
+ | :--- | :--- | :--- | :--- |
88
+ | `model` | string | (required) | The name of the Ollama model (e.g., \"llama3\", \"gemma\"). |
89
+ | `think` | boolean | `true` | Enables/Disables thinking process visibility if supported. |
90
+ | `timeout` | float | `600.0` | Connection timeout in seconds. |
91
+
92
+ **Example `pyproject.json`:**
93
+ ```json
94
+ {
95
+ \"adapter\": {
96
+ \"ollama\": {
97
+ \"model\": \"gemma\",
98
+ \"think\": true,
99
+ \"timeout\": 300.0
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 6. Usage Example
108
+
109
+ You do not need to import any classes from this package directly. Use the Framework's factory method:
110
+
111
+ ```python
112
+ import asyncio
113
+ from org.slashlib.py.agent.agent import Agent
114
+
115
+ async def main():
116
+ # Load the agent - the framework resolves 'ollama' via Entry Points
117
+ my_agent = Agent.from_plugin(
118
+ identifier=\"my-local-assistant\",
119
+ plugin_name=\"ollama\"
120
+ )
121
+
122
+ # All standard Agent methods are now available
123
+ response = await my_agent.chat(\"How does the plugin system work?\")
124
+ print(f\"Assistant: {response.content}\")
125
+
126
+ if __name__ == \"__main__\":
127
+ asyncio.run(main())
128
+ ```
129
+
130
+ ---
131
+
132
+ ## 7. Development & Testing
133
+
134
+ ### Testing with Pytest
135
+ ```bash
136
+ pytest tests/
137
+ ```
138
+
139
+ ### Logging
140
+ The adapter logs under the namespace `org.slashlib.py.inference.ollama`.
141
+
142
+ ---
143
+
144
+ ## 8. Documentation & Obsidian
145
+
146
+ The project root is fully prepared as an **Obsidian Vault**.
147
+
148
+ ---
149
+
150
+ ## License
151
+
152
+ Distributed under the **MIT License**. See `LICENSE.md` for more information.
153
+
154
+ ---
155
+ © 2026 org.slashlib
@@ -0,0 +1,139 @@
1
+ [Bottom](#license) [AI](AI.md) [CHANGELOG](CHANGELOG.md) [LICENSE](LICENSE.md)
2
+ # org.slashlib.py.inference.ollama
3
+
4
+ The official **Ollama** inference adapter for the `org.slashlib.py.agent` framework.
5
+
6
+ [![PyPI version](https://img.shields.io/pypi/v/org.slashlib.py.inference.ollama.svg?color=blue)](https://pypi.org/project/org.slashlib.py.inference.ollama/)
7
+ [![PyPI-Test version](https://img.shields.io/badge/pypitest-latest-blue)](https://test.pypi.org/project/org.slashlib.py.inference.ollama/)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ ---
11
+
12
+ ## 1. Overview & Architecture
13
+
14
+ This project provides a specialized implementation of the `InferenceAdapter` interface from the core **Agent Framework**. By decoupling the Ollama logic from the main framework, we ensure a lightweight core and allow for independent updates to the inference logic.
15
+
16
+ ### Architectural Role
17
+ - **Adapter Pattern**: Bridges the standardized framework calls to the Ollama-specific API.
18
+ - **Provider Agnostic**: The framework consumes this adapter through a unified interface.
19
+ - **Plugin-Based**: Leverages Python entry points for seamless, zero-config integration.
20
+
21
+ ---
22
+
23
+ ## 2. Prerequisites
24
+
25
+ - **Ollama Service**: Must be installed and reachable (Default: `http://localhost:11434`).
26
+ - **Python**: Version 3.10 or higher.
27
+ - **Base Framework**: `org.slashlib.py.agent` must be installed in the same environment.
28
+
29
+ ---
30
+
31
+ ## 3. Installation
32
+
33
+ ### Production / Standard
34
+ ```bash
35
+ pip install org.slashlib.py.inference.ollama
36
+ ```
37
+
38
+ ### Development (Editable Mode)
39
+ If you are developing both the framework and this adapter, install both in editable mode to ensure the **Entry Points** are correctly registered in your current Python environment:
40
+
41
+ ```bash
42
+ # 1. Install the framework
43
+ cd path/to/org.slashlib.py.agent
44
+ pip install -e .
45
+
46
+ # 2. Install this adapter
47
+ cd path/to/org.slashlib.py.inference.ollama
48
+ pip install -e .
49
+ ```
50
+
51
+ ---
52
+
53
+ ## 4. Integration Logic (Entry Points)
54
+
55
+ This adapter is designed to be \"invisible\" to the end user. It registers itself via the `pyproject.toml` entry points:
56
+
57
+ ```toml
58
+ [project.entry-points.\"org.slashlib.py.agent.inference\"]
59
+ ollama = \"org.slashlib.py.inference.ollama.adapter:OllamaInferenceAdapter\"
60
+ ```
61
+
62
+ The framework automatically scans this group and maps the name `ollama` to the `OllamaInferenceAdapter` class.
63
+
64
+ ---
65
+
66
+ ## 5. Configuration
67
+
68
+ The adapter's behavior is controlled via the framework's configuration loader (usually `pyproject.json`).
69
+
70
+ | Key | Type | Default | Description |
71
+ | :--- | :--- | :--- | :--- |
72
+ | `model` | string | (required) | The name of the Ollama model (e.g., \"llama3\", \"gemma\"). |
73
+ | `think` | boolean | `true` | Enables/Disables thinking process visibility if supported. |
74
+ | `timeout` | float | `600.0` | Connection timeout in seconds. |
75
+
76
+ **Example `pyproject.json`:**
77
+ ```json
78
+ {
79
+ \"adapter\": {
80
+ \"ollama\": {
81
+ \"model\": \"gemma\",
82
+ \"think\": true,
83
+ \"timeout\": 300.0
84
+ }
85
+ }
86
+ }
87
+ ```
88
+
89
+ ---
90
+
91
+ ## 6. Usage Example
92
+
93
+ You do not need to import any classes from this package directly. Use the Framework's factory method:
94
+
95
+ ```python
96
+ import asyncio
97
+ from org.slashlib.py.agent.agent import Agent
98
+
99
+ async def main():
100
+ # Load the agent - the framework resolves 'ollama' via Entry Points
101
+ my_agent = Agent.from_plugin(
102
+ identifier=\"my-local-assistant\",
103
+ plugin_name=\"ollama\"
104
+ )
105
+
106
+ # All standard Agent methods are now available
107
+ response = await my_agent.chat(\"How does the plugin system work?\")
108
+ print(f\"Assistant: {response.content}\")
109
+
110
+ if __name__ == \"__main__\":
111
+ asyncio.run(main())
112
+ ```
113
+
114
+ ---
115
+
116
+ ## 7. Development & Testing
117
+
118
+ ### Testing with Pytest
119
+ ```bash
120
+ pytest tests/
121
+ ```
122
+
123
+ ### Logging
124
+ The adapter logs under the namespace `org.slashlib.py.inference.ollama`.
125
+
126
+ ---
127
+
128
+ ## 8. Documentation & Obsidian
129
+
130
+ The project root is fully prepared as an **Obsidian Vault**.
131
+
132
+ ---
133
+
134
+ ## License
135
+
136
+ Distributed under the **MIT License**. See `LICENSE.md` for more information.
137
+
138
+ ---
139
+ © 2026 org.slashlib
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "org.slashlib.py.inference.ollama"
7
+ version = "0.1.2"
8
+ license = "MIT"
9
+ dependencies = [
10
+ "org.slashlib.py.agent>=0.1.5",
11
+ "org.slashlib.py.configloader>=0.1.0"
12
+ ]
13
+ authors = [
14
+ { name="Dirk Brenckmann", email="db.developer@gmx.de" },
15
+ ]
16
+ description = "python inference handler for agents"
17
+ readme = "README.md"
18
+ requires-python = ">=3.10"
19
+ classifiers = [
20
+ "Programming Language :: Python :: 3",
21
+ "Operating System :: OS Independent",
22
+ ]
23
+
24
+ [project.entry-points."org.slashlib.py.agent.inference"]
25
+ ollama-inference-adapter = "org.slashlib.py.inference.ollama.adapter:OllamaInferenceAdapter"
26
+
27
+ [project.urls]
28
+ "Homepage" = "https://github.com/org-slashlib/org.slashlib.py.inference.ollama"
29
+
30
+ [tool.setuptools.packages.find]
31
+ where = ["src"]
32
+
33
+ [tool.pytest.ini_options]
34
+ pythonpath = ["."]
35
+ testpaths = ["tests"]
36
+ asyncio_mode = "auto"
37
+ addopts = """
38
+ -v
39
+ --cov
40
+ --cov=src/org/slashlib/py/inference/ollama
41
+ --cov-report=term-missing
42
+ --cov-report=xml:docs/reports/coverage/xml
43
+ --cov-report=html:docs/reports/coverage/html
44
+ """
45
+
46
+ [tool.coverage.run]
47
+ data_file = "docs/reports/coverage/.coverage"
48
+ source = ["src/org/slashlib/py/inference/ollama"]
49
+
50
+ [tool.coverage.report]
51
+ show_missing = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+ # file src/org/slashlib/py/inference/ollama/__init__.py
3
+ # @AI:
4
+ # - INTEGRITY RULES:
5
+ # - STRICT PRESERVATION: Do not remove, move, or modify ANY existing lines of code or comments
6
+ # unless they are the explicit target of the requested change.
7
+ # - DEBUG MARKERS: Commented-out code (e.g., debug prints) MUST be kept exactly where they are.
8
+ # - WHITESPACE & STRUCTURE: Maintain all original empty lines and the existing file structure.
9
+ # Structural integrity takes precedence over "clean code" or "elegance".
10
+ # - LEAD-IN/OUT: The very first and last lines (and all comments in between) are immutable anchors.
11
+ # - MAINTENANCE:
12
+ # - Only update pydoc strings (args, returns, raises) if the function signature changes.
13
+ # - Do NOT delete existing examples or descriptions in pydoc.
14
+ # - LANGUAGE: en-US for all comments and documentation.
15
+
16
+ from org.slashlib.py.inference.ollama.adapter import OllamaInferenceAdapter
17
+ from org.slashlib.py.inference.ollama.result import OllamaInferenceResult
18
+
19
+ __all__ = ["OllamaInferenceAdapter", "OllamaInferenceResult"]
20
+
21
+ # end of file src/org/slashlib/py/inference/ollama/__init__.py
@@ -0,0 +1,113 @@
1
+ # -*- coding: utf-8 -*-
2
+ # file src/org/slashlib/py/inference/ollama/adapter.py
3
+ # @AI:
4
+ # - INTEGRITY RULES:
5
+ # - STRICT PRESERVATION: Do not remove, move, or modify ANY existing lines of code or comments
6
+ # unless they are the explicit target of the requested change.
7
+ # - DEBUG MARKERS: Commented-out code (e.g., debug prints) MUST be kept exactly where they are.
8
+ # - WHITESPACE & STRUCTURE: Maintain all original empty lines and the existing file structure.
9
+ # Structural integrity takes precedence over "clean code" or "elegance".
10
+ # - LEAD-IN/OUT: The very first and last lines (and all comments in between) are immutable anchors.
11
+ # - MAINTENANCE:
12
+ # - Only update pydoc strings (args, returns, raises) if the function signature changes.
13
+ # - Do NOT delete existing examples or descriptions in pydoc.
14
+ # - LANGUAGE: en-US for all comments and documentation.
15
+ #
16
+
17
+ # Python imports
18
+ import logging
19
+ import pathlib
20
+ import typing
21
+
22
+ # Third party imports
23
+ import ollama
24
+ import org.slashlib.py.agent as agent
25
+ import org.slashlib.py.configloader as config
26
+
27
+ # Internal imports
28
+ from org.slashlib.py.inference.ollama.result import OllamaInferenceResult
29
+
30
+ class OllamaInferenceAdapter(agent.InferenceAdapter):
31
+ """
32
+ Inference Adapter for the Ollama API.
33
+
34
+ Handles asynchronous communication with an Ollama server, including
35
+ parameter resolution from config and error mapping to the neutral
36
+ inference exception hierarchy.
37
+ """
38
+
39
+ def __init__(self):
40
+ """
41
+ Initialize the adapter and its logger.
42
+ """
43
+ self.log = logging.getLogger(f"org.slashlib.py.inference.ollama.{pathlib.Path(__file__).stem}.{self.__class__.__name__}")
44
+
45
+ async def chat(
46
+ self,
47
+ model: typing.Optional[str] = None,
48
+ messages: typing.List[typing.Dict[str, typing.Any]] = None,
49
+ tools: typing.Optional[typing.List[typing.Dict[str, typing.Any]]] = None,
50
+ **kwargs
51
+ ) -> agent.InferenceResult:
52
+ """
53
+ Sends a chat request to Ollama and returns a validated result.
54
+
55
+ Resolves model parameters using a priority chain:
56
+ 1. Explicit kwargs, 2. Method arguments, 3. pyproject.json via configloader.
57
+
58
+ Args:
59
+ model (Optional[str]): The model name. Defaults to config value.
60
+ messages (List[Dict[str, Any]]): The message history/context.
61
+ tools (Optional[List[Dict[str, Any]]]): JSON schemas of available tools.
62
+ **kwargs: Additional parameters like 'timeout' or 'think'.
63
+
64
+ Returns:
65
+ agent.InferenceResult: An instance of OllamaInferenceResult.
66
+
67
+ Raises:
68
+ agent.InferenceConfigError: If the model is not found or config is invalid.
69
+ agent.InferenceConnectionError: If the Ollama server is unreachable or times out.
70
+ agent.InferencePayloadError: If the response from Ollama is malformed.
71
+ agent.InferenceError: For any other unexpected errors during agent.
72
+ """
73
+ # Resolve parameters: priority is kwargs -> method arg -> pyproject.json
74
+ target_model = model or kwargs.get("model", config.resolve("adapter.ollama.model"))
75
+ timeout = kwargs.get("timeout", config.resolve("adapter.ollama.timeout"))
76
+ think = kwargs.get("think", config.resolve("adapter.ollama.think"))
77
+
78
+ try:
79
+ self.log.debug(f"Ollama request: timeout={timeout}, model={target_model}, messages={messages}, tools={tools}, think={think}")
80
+
81
+ client = ollama.AsyncClient(timeout=timeout)
82
+ response = await client.chat(
83
+ model=target_model,
84
+ messages=messages,
85
+ tools=tools,
86
+ think=think
87
+ )
88
+
89
+ self.log.debug(f"Ollama response: {response}")
90
+
91
+ message = response.get("message")
92
+ if not message:
93
+ raise agent.InferencePayloadError(f"Ollama API returned an empty response for model '{target_model}'.")
94
+
95
+ return OllamaInferenceResult(message)
96
+
97
+ except (ollama.ResponseError) as e:
98
+ self.log.error(f"Ollama logical/config error: {e}", exc_info=True)
99
+ raise agent.InferenceConfigError(f"Ollama model or config invalid: {str(e)}")
100
+ except (ollama.RequestError) as e:
101
+ self.log.error(f"Ollama communication error: {e}", exc_info=True)
102
+ raise agent.InferenceConnectionError(f"Failed to connect to Ollama: {str(e)}")
103
+ except agent.InferenceError:
104
+ # Re-raise internal inference errors to prevent them from being caught by the general Exception block
105
+ raise
106
+ except Exception as e:
107
+ self.log.error(f"Unexpected error in OllamaInferenceAdapter: {e}", exc_info=True)
108
+ raise agent.InferenceError(f"Internal adapter error: {str(e)}")
109
+
110
+
111
+ __all__ = ["OllamaInferenceAdapter"]
112
+
113
+ # end of file file src/org/slashlib/py/inference/ollama/adapter.py
@@ -0,0 +1,105 @@
1
+ # -*- coding: utf-8 -*-
2
+ # file src/org/slashlib/py/inference/ollama/result.py
3
+ # @AI:
4
+ # - INTEGRITY RULES:
5
+ # - STRICT PRESERVATION: Do not remove, move, or modify ANY existing lines of code or comments
6
+ # unless they are the explicit target of the requested change.
7
+ # - DEBUG MARKERS: Commented-out code (e.g., debug prints) MUST be kept exactly where they are.
8
+ # - WHITESPACE & STRUCTURE: Maintain all original empty lines and the existing file structure.
9
+ # Structural integrity takes precedence over "clean code" or "elegance".
10
+ # - LEAD-IN/OUT: The very first and last lines (and all comments in between) are immutable anchors.
11
+ # - MAINTENANCE:
12
+ # - Only update pydoc strings (args, returns, raises) if the function signature changes.
13
+ # - Do NOT delete existing examples or descriptions in pydoc.
14
+ # - LANGUAGE: en-US for all comments and documentation.
15
+ #
16
+
17
+ # Python imports
18
+ import logging
19
+ import pathlib
20
+ import typing
21
+
22
+ # Third party imports
23
+
24
+ # Internal imports
25
+ import org.slashlib.py.agent as agent
26
+
27
+
28
+ class OllamaInferenceResult(agent.InferenceResult):
29
+ """
30
+ Specific implementation of InferenceResult for Ollama.
31
+
32
+ This class takes the raw dictionary response from the Ollama API,
33
+ validates its mandatory fields (role, content/tool_calls), and
34
+ provides standardized accessors for the Agent.
35
+ """
36
+
37
+ def __init__(self, raw_response: typing.Dict[str, typing.Any]):
38
+ """
39
+ Initialize and validate the Ollama response.
40
+
41
+ Args:
42
+ raw_response (Dict[str, Any]): The 'message' part of the Ollama API response.
43
+
44
+ Raises:
45
+ agent.InferencePayloadError: If the 'role' is missing or if both
46
+ 'content' and 'tool_calls' are empty/None.
47
+ """
48
+ self.log = logging.getLogger(f"org.slashlib.py.inference.ollama.{pathlib.Path(__file__).stem}.{self.__class__.__name__}")
49
+ self._role = raw_response.get("role")
50
+ self._content = raw_response.get("content")
51
+ self._tool_calls = raw_response.get("tool_calls")
52
+
53
+ if not self._role:
54
+ raise agent.InferencePayloadError(f"Invalid Ollama response: 'role' is missing. Data: {raw_response}")
55
+
56
+ # Note: content can be None if tool_calls are present, which is valid.
57
+ if self._content is None and not self._tool_calls:
58
+ raise agent.InferencePayloadError(f"Invalid Ollama response: Both 'content' and 'tool_calls' are empty.")
59
+
60
+ @property
61
+ def role(self) -> str:
62
+ """
63
+ The role of the message sender.
64
+
65
+ Returns:
66
+ str: Typically 'assistant'.
67
+ """
68
+ return self._role
69
+
70
+ @property
71
+ def content(self) -> typing.Optional[str]:
72
+ """
73
+ The text content of the model's response.
74
+
75
+ Returns:
76
+ Optional[str]: The message text or None if only tool calls are present.
77
+ """
78
+ return self._content
79
+
80
+ @property
81
+ def tool_calls(self) -> typing.Optional[typing.List[typing.Dict[str, typing.Any]]]:
82
+ """
83
+ A list of tool calls generated by the model.
84
+
85
+ Returns:
86
+ Optional[List[Dict[str, Any]]]: Standardized tool call objects or None.
87
+ """
88
+ return self._tool_calls
89
+
90
+ def to_dict(self) -> typing.Dict[str, typing.Any]:
91
+ """
92
+ Converts the result into a standardized dictionary.
93
+
94
+ Returns:
95
+ Dict[str, Any]: A dictionary containing 'role', 'content', and 'tool_calls'.
96
+ """
97
+ return {
98
+ "role": self._role,
99
+ "content": self._content,
100
+ "tool_calls": self._tool_calls
101
+ }
102
+
103
+ __all__ = ["OllamaInferenceResult"]
104
+
105
+ # end of file src/org/slashlib/py/inference/ollama/result.py
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: org.slashlib.py.inference.ollama
3
+ Version: 0.1.2
4
+ Summary: python inference handler for agents
5
+ Author-email: Dirk Brenckmann <db.developer@gmx.de>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/org-slashlib/org.slashlib.py.inference.ollama
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE.md
13
+ Requires-Dist: org.slashlib.py.agent>=0.1.5
14
+ Requires-Dist: org.slashlib.py.configloader>=0.1.0
15
+ Dynamic: license-file
16
+
17
+ [Bottom](#license) [AI](AI.md) [CHANGELOG](CHANGELOG.md) [LICENSE](LICENSE.md)
18
+ # org.slashlib.py.inference.ollama
19
+
20
+ The official **Ollama** inference adapter for the `org.slashlib.py.agent` framework.
21
+
22
+ [![PyPI version](https://img.shields.io/pypi/v/org.slashlib.py.inference.ollama.svg?color=blue)](https://pypi.org/project/org.slashlib.py.inference.ollama/)
23
+ [![PyPI-Test version](https://img.shields.io/badge/pypitest-latest-blue)](https://test.pypi.org/project/org.slashlib.py.inference.ollama/)
24
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
25
+
26
+ ---
27
+
28
+ ## 1. Overview & Architecture
29
+
30
+ This project provides a specialized implementation of the `InferenceAdapter` interface from the core **Agent Framework**. By decoupling the Ollama logic from the main framework, we ensure a lightweight core and allow for independent updates to the inference logic.
31
+
32
+ ### Architectural Role
33
+ - **Adapter Pattern**: Bridges the standardized framework calls to the Ollama-specific API.
34
+ - **Provider Agnostic**: The framework consumes this adapter through a unified interface.
35
+ - **Plugin-Based**: Leverages Python entry points for seamless, zero-config integration.
36
+
37
+ ---
38
+
39
+ ## 2. Prerequisites
40
+
41
+ - **Ollama Service**: Must be installed and reachable (Default: `http://localhost:11434`).
42
+ - **Python**: Version 3.10 or higher.
43
+ - **Base Framework**: `org.slashlib.py.agent` must be installed in the same environment.
44
+
45
+ ---
46
+
47
+ ## 3. Installation
48
+
49
+ ### Production / Standard
50
+ ```bash
51
+ pip install org.slashlib.py.inference.ollama
52
+ ```
53
+
54
+ ### Development (Editable Mode)
55
+ If you are developing both the framework and this adapter, install both in editable mode to ensure the **Entry Points** are correctly registered in your current Python environment:
56
+
57
+ ```bash
58
+ # 1. Install the framework
59
+ cd path/to/org.slashlib.py.agent
60
+ pip install -e .
61
+
62
+ # 2. Install this adapter
63
+ cd path/to/org.slashlib.py.inference.ollama
64
+ pip install -e .
65
+ ```
66
+
67
+ ---
68
+
69
+ ## 4. Integration Logic (Entry Points)
70
+
71
+ This adapter is designed to be \"invisible\" to the end user. It registers itself via the `pyproject.toml` entry points:
72
+
73
+ ```toml
74
+ [project.entry-points.\"org.slashlib.py.agent.inference\"]
75
+ ollama = \"org.slashlib.py.inference.ollama.adapter:OllamaInferenceAdapter\"
76
+ ```
77
+
78
+ The framework automatically scans this group and maps the name `ollama` to the `OllamaInferenceAdapter` class.
79
+
80
+ ---
81
+
82
+ ## 5. Configuration
83
+
84
+ The adapter's behavior is controlled via the framework's configuration loader (usually `pyproject.json`).
85
+
86
+ | Key | Type | Default | Description |
87
+ | :--- | :--- | :--- | :--- |
88
+ | `model` | string | (required) | The name of the Ollama model (e.g., \"llama3\", \"gemma\"). |
89
+ | `think` | boolean | `true` | Enables/Disables thinking process visibility if supported. |
90
+ | `timeout` | float | `600.0` | Connection timeout in seconds. |
91
+
92
+ **Example `pyproject.json`:**
93
+ ```json
94
+ {
95
+ \"adapter\": {
96
+ \"ollama\": {
97
+ \"model\": \"gemma\",
98
+ \"think\": true,
99
+ \"timeout\": 300.0
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 6. Usage Example
108
+
109
+ You do not need to import any classes from this package directly. Use the Framework's factory method:
110
+
111
+ ```python
112
+ import asyncio
113
+ from org.slashlib.py.agent.agent import Agent
114
+
115
+ async def main():
116
+ # Load the agent - the framework resolves 'ollama' via Entry Points
117
+ my_agent = Agent.from_plugin(
118
+ identifier=\"my-local-assistant\",
119
+ plugin_name=\"ollama\"
120
+ )
121
+
122
+ # All standard Agent methods are now available
123
+ response = await my_agent.chat(\"How does the plugin system work?\")
124
+ print(f\"Assistant: {response.content}\")
125
+
126
+ if __name__ == \"__main__\":
127
+ asyncio.run(main())
128
+ ```
129
+
130
+ ---
131
+
132
+ ## 7. Development & Testing
133
+
134
+ ### Testing with Pytest
135
+ ```bash
136
+ pytest tests/
137
+ ```
138
+
139
+ ### Logging
140
+ The adapter logs under the namespace `org.slashlib.py.inference.ollama`.
141
+
142
+ ---
143
+
144
+ ## 8. Documentation & Obsidian
145
+
146
+ The project root is fully prepared as an **Obsidian Vault**.
147
+
148
+ ---
149
+
150
+ ## License
151
+
152
+ Distributed under the **MIT License**. See `LICENSE.md` for more information.
153
+
154
+ ---
155
+ © 2026 org.slashlib
@@ -0,0 +1,12 @@
1
+ LICENSE.md
2
+ README.md
3
+ pyproject.toml
4
+ src/org.slashlib.py.inference.ollama.egg-info/PKG-INFO
5
+ src/org.slashlib.py.inference.ollama.egg-info/SOURCES.txt
6
+ src/org.slashlib.py.inference.ollama.egg-info/dependency_links.txt
7
+ src/org.slashlib.py.inference.ollama.egg-info/entry_points.txt
8
+ src/org.slashlib.py.inference.ollama.egg-info/requires.txt
9
+ src/org.slashlib.py.inference.ollama.egg-info/top_level.txt
10
+ src/org/slashlib/py/inference/ollama/__init__.py
11
+ src/org/slashlib/py/inference/ollama/adapter.py
12
+ src/org/slashlib/py/inference/ollama/result.py
@@ -0,0 +1,2 @@
1
+ [org.slashlib.py.agent.inference]
2
+ ollama-inference-adapter = org.slashlib.py.inference.ollama.adapter:OllamaInferenceAdapter
@@ -0,0 +1,2 @@
1
+ org.slashlib.py.agent>=0.1.5
2
+ org.slashlib.py.configloader>=0.1.0