From 98870482ec6d5f89d303a5886380c4df7859950d Mon Sep 17 00:00:00 2001 From: alkidbaci Date: Fri, 27 Mar 2026 15:37:22 +0100 Subject: [PATCH] dspy made optional --- .github/workflows/docs.yml | 2 +- .github/workflows/test.yml | 2 +- README.md | 20 ++++++++++++ docs/usage/ontologies.md | 31 ++++++++++++++++--- owlapy/agen_kg/agent.py | 6 +++- .../domain_graph_extractor.py | 5 ++- .../open_graph_extractor.py | 5 ++- setup.py | 6 ++-- 8 files changed, 65 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 6ec4267b..14dfe332 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -27,7 +27,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -e '.[dev]' + pip install -e '.[all]' pip install dicee[dev] pip install sphinx sphinx_rtd_theme sphinx-autoapi sphinx-theme sphinxcontrib-plantuml plantuml-local-client myst-parser diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 76e59552..ade586d5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -e '.[dev]' + pip install -e '.[all]' pip install dicee[dev] - name: Lint with ruff run: | diff --git a/README.md b/README.md index b4da77f2..3a325fe4 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,26 @@ Our latest feature employees a combination of state-of-the-art approaches to ext text using Large Language Models (LLMs). The algorithm consist of an agentic pipeline called AGen-KG (stands for agent-generated KG) which can scale to large documents through chunking and merging strategies. +#### Installation + +Before using this feature, install the required extra dependencies for LLM-based +ontology generation: + +```shell +pip install owlapy[agentic] # or: pip install owlapy[all] +``` + +If you already have the minimum version of OWLAPY installed, you can install DSPy directly: + +```shell +pip install dspy +``` + +> **Note:** DSPy is updated frequently and compatibility with the latest versions is not guaranteed. The last verified compatible version is **3.1.3**. + + +#### Example + ```python from owlapy.agen_kg import AGenKG from owlapy.owl_ontology import SyncOntology diff --git a/docs/usage/ontologies.md b/docs/usage/ontologies.md index d84d0185..d5baf6d4 100644 --- a/docs/usage/ontologies.md +++ b/docs/usage/ontologies.md @@ -190,10 +190,32 @@ created in the same directory as the file you are running this code. ## Generate Ontology From Text -In OWLAPY, you’ll find a module named agen_kg (short for "agent-generated knowledge graph") that enables you to -extract ontologies from unstructured text using Large Language Models (LLMs). -This functionality is built on using [DSPy](https://dspy.ai/). To use it, you need to create an instance of the `AGenKG` class, -where you can configure general LLM settings. Once initialized, the instance can be used as a callable object to generate an ontology, as shown below: + +OWLAPY includes a module named `agen_kg` (short for **"agent-generated knowledge graph"**) +that enables ontology extraction from unstructured text using **Large Language Models (LLMs)**. +This functionality is powered by [DSPy](https://dspy.ai/). + +To use it, create an instance of the `AGenKG` class, where you can configure your LLM +settings. Once initialized, the instance can be invoked as a callable to generate an ontology. + +### Installation + +Before using this feature, install the required extra dependencies for LLM-based +ontology generation: + +```shell +pip install owlapy[agentic] # or: pip install owlapy[all] +``` + +If you already have the minimum version of OWLAPY installed, you can install DSPy directly: + +```shell +pip install dspy +``` + +> **Note:** DSPy is updated frequently and compatibility with the latest versions is not guaranteed. The last verified compatible version is **3.1.3**. + +### Example ```python from owlapy.agen_kg import AGenKG @@ -259,4 +281,3 @@ reasoning. In the next guide, we will explore how to use a reasoner in Owlapy. - diff --git a/owlapy/agen_kg/agent.py b/owlapy/agen_kg/agent.py index 9f87aec0..53253e79 100644 --- a/owlapy/agen_kg/agent.py +++ b/owlapy/agen_kg/agent.py @@ -1,4 +1,8 @@ -import dspy + +try: + import dspy +except ImportError: + raise ImportError("dspy is required for AGenKG. Please install it using 'pip install dspy'") from owlapy.agen_kg.graph_extracting_models import (OpenGraphExtractor, DomainGraphExtractor) class AGenKG: diff --git a/owlapy/agen_kg/graph_extracting_models/domain_graph_extractor.py b/owlapy/agen_kg/graph_extracting_models/domain_graph_extractor.py index 515c95bc..bd824542 100644 --- a/owlapy/agen_kg/graph_extracting_models/domain_graph_extractor.py +++ b/owlapy/agen_kg/graph_extracting_models/domain_graph_extractor.py @@ -1,6 +1,9 @@ from typing import List, Union, Optional import os -import dspy +try: + import dspy +except ImportError: + raise ImportError("dspy is required for DomainGraphExtractor. Please install it using 'pip install dspy'") import uuid from pathlib import Path diff --git a/owlapy/agen_kg/graph_extracting_models/open_graph_extractor.py b/owlapy/agen_kg/graph_extracting_models/open_graph_extractor.py index 0da6dcc2..98a3ca6d 100644 --- a/owlapy/agen_kg/graph_extracting_models/open_graph_extractor.py +++ b/owlapy/agen_kg/graph_extracting_models/open_graph_extractor.py @@ -1,6 +1,9 @@ from typing import List, Union import os -import dspy +try: + import dspy +except ImportError: + raise ImportError("dspy is required for OpenGraphExtractor. Please install it using 'pip install dspy'") import uuid from pathlib import Path diff --git a/setup.py b/setup.py index d8021226..2ad7cacb 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ "uvicorn>=0.32.1", "dicee==0.3.2", "litserve>=0.2.0", - "dspy==3.0.3", + "dspy>=3.0.3", "ruff>=0.7.2", "pytest>=8.1.1", ] @@ -44,7 +44,9 @@ def deps_list(*pkgs): "dspy", ) -extras["dev"] = (extras["min"] + deps_list("pytest", "ruff", "dicee")) +extras["dev"] = (extras["min"] + deps_list("pytest", "ruff")) +extras["agentic"] = (extras["min"] + deps_list("dspy")) +extras["all"] = (extras["dev"] + deps_list("dspy", "dicee")) install_requires = [extras["min"]] with open('README.md', 'r') as fh: