WSE-research / LoRiS-LLM-generated-Representations-of-SPARQL-queries-backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Webservice: LLM-based natural-language representations for SPARQL queries (API)

This project provides a web service for generating natural-language representations for SPARQL queries over the Wikidata or DBpedia knowledge graphs.

The corresponding web-based frontend — LoRiS -  LLM-generated natural-language representations of SPARQL queries over Wikidata and DBpedia — is provided here.



Online Demo (API)

The API is available at https://wse-research.org/api/sparql2nl

Sample SPARQL2NL API request:

curl -X 'GET' \
  'https://wse-research.org/api/sparql2nl?query_text=QUERYTEXT&language=LANG&shots=SHOTS&model=MODELID' \
  -H 'accept: application/json'
  • query_text: a SPARQL query over Wikidata or DBpedia

  • language: English (en), German (de), or Russian (ru)

  • shots: zero-shot (0), one-shot (1)

  • model: model id (any text model from OpenAI https://platform.openai.com/docs/models)

Feedback API request:

curl -X 'POST'  'https://wse-research.org/api/sparql2nl-feedback' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
"query_text": "SELECT * WHERE { ?s ?p ?o }",
"verbalization": "select everything",
"rating": 5,
"comment": "cool"
}'
  • query_text: a SPARQL query over Wikidata or DBpedia

  • verbalization: a result of our model

  • rating: a grade from 1 (bad) to 5 (good)

  • comment: optional, additional notes to the result

Building and Running the Application

Running locally with Python 3.8+

Install dependencies

Install Python dependencies
pip install -r requirements.txt

Note: If you are using a virtual environment, make sure to activate it before running the command.

Run the Application

python

After that, you can access the application at http://localhost:PORT.

Docker

The application is available at Dockerhub for free use in your environment.

.env file

OPENAI_API_KEY=
PORT=
MONGO_HOST=
MONGO_PORT=
MONGO_USERNAME=
MONGO_PASSWORD=

Build Docker Image

docker-compose build

Run Docker Image

docker-compose up

Now, you can access the application at http://localhost:8501.

Contribute

We are happy to receive your contributions. Please create a pull request or an issue. As this tool is published under the MIT license, feel free to fork it and use it in your own projects.

Disclaimer

This tool just temporarily stores the image data. This tool is provided "as is" and without any warranty, express or implied.

About

License:MIT License


Languages

Language:Python 98.4%Language:Dockerfile 1.6%