-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use logging instead of print in sparql-llm. add SparqlInfoLoader
- Loading branch information
Showing
27 changed files
with
7,905 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
"""Utilities to improve LLMs capabilities when working with SPARQL and RDF.""" | ||
|
||
__version__ = "0.0.6" | ||
__version__ = "0.0.8" | ||
|
||
from .utils import SparqlEndpointInfo | ||
from .utils import SparqlEndpointLinks | ||
from .validate_sparql import validate_sparql_in_msg, validate_sparql_with_void | ||
from .sparql_examples_loader import SparqlExamplesLoader | ||
from .sparql_void_shapes_loader import SparqlVoidShapesLoader, get_shex_dict_from_void, get_shex_from_void | ||
from .sparql_info_loader import SparqlInfoLoader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import Optional | ||
|
||
from langchain_core.document_loaders.base import BaseLoader | ||
from langchain_core.documents import Document | ||
|
||
from sparql_llm.utils import SparqlEndpointLinks, logger | ||
|
||
DOC_TYPE = "General information" | ||
|
||
|
||
class SparqlInfoLoader(BaseLoader): | ||
"""Load informations for a list of SPARQL endpoints.""" | ||
|
||
def __init__(self, endpoints: list[SparqlEndpointLinks], source_iri: Optional[str] = None, org_label: str = ""): | ||
"""Initialize the SparqlInfoLoader.""" | ||
self.endpoints = endpoints | ||
self.source_iri = source_iri | ||
self.org_label = org_label | ||
|
||
def load(self) -> list[Document]: | ||
"""Load and return documents from the SPARQL endpoint.""" | ||
docs: list[Document] = [] | ||
|
||
resources_summary_question = "Which resources are available through this system?" | ||
metadata = { | ||
"question": resources_summary_question, | ||
"answer": f"This system helps to access the following SPARQL endpoints {self.org_label}:\n- " | ||
+ "\n- ".join( | ||
[ | ||
f"{endpoint.get('label')}: {endpoint['endpoint_url']}" | ||
if endpoint.get("label") | ||
else f"{endpoint['endpoint_url']}" | ||
for endpoint in self.endpoints | ||
] | ||
), | ||
"doc_type": DOC_TYPE, | ||
} | ||
if self.source_iri: | ||
metadata["iri"] = self.source_iri | ||
docs.append( | ||
Document( | ||
page_content=resources_summary_question, | ||
metadata=metadata, | ||
) | ||
) | ||
|
||
logger.info(f"Added {len(docs)} documents with general informations") | ||
return docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.