ontocast.tool
¶
ConverterTool
¶
Bases: Tool
Tool for converting documents to structured data.
This class provides functionality for converting various document formats into structured data that can be processed by the OntoCast system.
Attributes:
Name | Type | Description |
---|---|---|
supported_extensions |
set[str]
|
Set of supported file extensions. |
Source code in ontocast/tool/converter.py
__call__(file_input)
¶
Convert a document to structured data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_input
|
Union[bytes, str]
|
The input file as either a BytesIO object or file path. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The converted document data. |
Source code in ontocast/tool/converter.py
__init__(**kwargs)
¶
Initialize the converter tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
FilesystemTripleStoreManager
¶
Bases: TripleStoreManager
Filesystem-based implementation of triple store management.
This class provides a concrete implementation of triple store management using the local filesystem for storage.
Attributes:
Name | Type | Description |
---|---|---|
working_directory |
Path
|
Path to the working directory for storing data. |
ontology_path |
Optional[Path]
|
Optional path to the ontology directory. |
Source code in ontocast/tool/triple_manager.py
__init__(**kwargs)
¶
Initialize the filesystem triple store manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
fetch_ontologies()
¶
Fetch all available ontologies from the filesystem.
Returns:
Type | Description |
---|---|
list[Ontology]
|
list[Ontology]: List of available ontologies. |
Source code in ontocast/tool/triple_manager.py
serialize_facts(g, **kwargs)
¶
Store a graph in the filesystem.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
Graph
|
The graph to store. |
required |
**kwargs
|
Additional keyword arguments for serialization. spec: Optional specification for the filename. |
{}
|
Source code in ontocast/tool/triple_manager.py
serialize_ontology(o, **kwargs)
¶
Store an ontology in the filesystem.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
o
|
Ontology
|
The ontology to store. |
required |
**kwargs
|
Additional keyword arguments for serialization. |
{}
|
Source code in ontocast/tool/triple_manager.py
LLMTool
¶
Bases: Tool
Tool for interacting with language models.
This class provides a unified interface for working with different language model providers (OpenAI, Ollama) through LangChain. It supports both synchronous and asynchronous operations.
Attributes:
Name | Type | Description |
---|---|---|
provider |
str
|
The LLM provider to use (default: "openai"). |
model |
str
|
The specific model to use (default: "gpt-4o-mini"). |
api_key |
Optional[str]
|
Optional API key for the provider. |
base_url |
Optional[str]
|
Optional base URL for the provider. |
temperature |
float
|
Temperature parameter for generation (default: 0.1). |
Source code in ontocast/tool/llm.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
llm
property
¶
Get the underlying language model instance.
Returns:
Name | Type | Description |
---|---|---|
BaseChatModel |
BaseChatModel
|
The configured language model. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the LLM has not been properly initialized. |
__call__(*args, **kwds)
¶
Call the language model directly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
Positional arguments passed to the LLM. |
()
|
**kwds
|
Any
|
Keyword arguments passed to the LLM. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The LLM's response. |
Source code in ontocast/tool/llm.py
__init__(**kwargs)
¶
Initialize the LLM tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
acreate(**kwargs)
async
classmethod
¶
Create a new LLM tool instance asynchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Keyword arguments for initialization. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
LLMTool |
A new instance of the LLM tool. |
Source code in ontocast/tool/llm.py
complete(prompt, **kwargs)
async
¶
Generate a completion for the given prompt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
The input prompt for generation. |
required |
**kwargs
|
Additional keyword arguments for generation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The generated completion. |
Source code in ontocast/tool/llm.py
create(**kwargs)
classmethod
¶
Create a new LLM tool instance synchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Keyword arguments for initialization. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
LLMTool |
A new instance of the LLM tool. |
Source code in ontocast/tool/llm.py
extract(prompt, output_schema, **kwargs)
async
¶
Extract structured data from the prompt according to a schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
The input prompt for extraction. |
required |
output_schema
|
Type[T]
|
The Pydantic model class defining the output structure. |
required |
**kwargs
|
Additional keyword arguments for extraction. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
The extracted data conforming to the output schema. |
Source code in ontocast/tool/llm.py
setup()
async
¶
Set up the language model based on the configured provider.
Raises:
Type | Description |
---|---|
ValueError
|
If the provider is not supported. |
Source code in ontocast/tool/llm.py
OntologyManager
¶
Bases: Tool
Manager for handling multiple ontologies.
This class provides functionality for managing a collection of ontologies, including selection and retrieval operations.
Attributes:
Name | Type | Description |
---|---|---|
ontologies |
list[Ontology]
|
List of managed ontologies. |
Source code in ontocast/tool/ontology_manager.py
__init__(**kwargs)
¶
Initialize the ontology manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
get_ontology(short_name)
¶
Get an ontology by its short name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
short_name
|
str
|
The short name of the ontology to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
Ontology |
Ontology
|
The matching ontology if found, NULL_ONTOLOGY otherwise. |
Source code in ontocast/tool/ontology_manager.py
get_ontology_names()
¶
Get a list of all ontology short names.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: List of ontology short names. |
update_ontology(short_name, ontology_addendum)
¶
Update an existing ontology with additional triples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
short_name
|
str
|
The short name of the ontology to update. |
required |
ontology_addendum
|
RDFGraph
|
The RDF graph containing additional triples to add. |
required |
Source code in ontocast/tool/ontology_manager.py
Tool
¶
Bases: BasePydanticModel
Base class for all OntoCast tools.
This class serves as the foundation for all tools in the OntoCast system. It provides common functionality and interface that all tools must implement. Tools should inherit from this class and implement their specific functionality.
Source code in ontocast/tool/onto.py
__init__(**kwargs)
¶
Initialize the tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Keyword arguments passed to the parent class. |
{}
|
TripleStoreManager
¶
Bases: Tool
Base class for managing RDF triple stores.
This class defines the interface for triple store management operations, including fetching and storing ontologies and their graphs.
Source code in ontocast/tool/triple_manager.py
__init__(**kwargs)
¶
Initialize the triple store manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
fetch_ontologies()
abstractmethod
¶
Fetch all available ontologies.
Returns:
Type | Description |
---|---|
list[Ontology]
|
list[Ontology]: List of available ontologies. |
serialize_facts(g, **kwargs)
abstractmethod
¶
Store a graph with a given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
Graph
|
The graph to store. |
required |
**kwargs
|
Additional keyword arguments for serialization. |
{}
|