Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 26 additions & 5 deletions docs/usage/ontologies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -259,4 +281,3 @@ reasoning. In the next guide, we will explore how to use a reasoner in Owlapy.




6 changes: 5 additions & 1 deletion owlapy/agen_kg/agent.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down Expand Up @@ -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:
Expand Down
Loading