Skip to main content

OntoGPT is a Python package for extracting structured information from text with large language models (LLMs), instruction prompts, and ontology-based grounding.

Project description

OntoGPT

OntoGPT Logo

DOI PyPI

Introduction

OntoGPT is a Python package for extracting structured information from text with large language models (LLMs), instruction prompts, and ontology-based grounding.

For more details, please see the full documentation.

Quick Start

OntoGPT runs on the command line, though there's also a minimal web app interface (see Web Application section below).

  1. Ensure you have Python 3.10 or greater installed.

  2. Install with pip:

    pip install ontogpt
    
  3. Set your OpenAI API key:

    runoak set-apikey -e openai <your openai api key>
    
  4. See the list of all OntoGPT commands:

    ontogpt --help
    
  5. Try a simple example of information extraction:

    echo "One treatment for high blood pressure is carvedilol." > example.txt
    ontogpt extract -i example.txt -t drug
    

    OntoGPT will retrieve the necessary ontologies and output results to the command line. Your output will provide all extracted objects under the heading extracted_object.

Web Application

There is a bare bones web application for running OntoGPT and viewing results.

First, install the required dependencies with pip by running the following command:

pip install ontogpt[web]

Then run this command to start the web application:

web-ontogpt

NOTE: We do not recommend hosting this webapp publicly without authentication.

Model APIs

OntoGPT uses LiteLLM to interface with LLMs.

This means OntoGPT can work with a much broader range of providers than just OpenAI. If a provider and model are supported by the installed LiteLLM version, they will generally work in OntoGPT as well. This includes OpenAI, Azure OpenAI, Anthropic, Mistral, Groq, Cohere, Vertex AI, Replicate, and many others.

The model name to use may be found from the command ontogpt list-models - use the name in the first column with the --model option. In most cases, the most reliable form is a provider-qualified LiteLLM model name such as openai/gpt-4o, anthropic/claude-3-5-sonnet, groq/llama-3.1-8b-instant, or mistral/mistral-large-latest.

Credential handling now follows LiteLLM first. Standard LiteLLM environment variables such as OPENAI_API_KEY, ANTHROPIC_API_KEY, GROQ_API_KEY, MISTRAL_API_KEY, AZURE_API_KEY, AZURE_API_BASE, and AZURE_API_VERSION are supported directly. For backward compatibility, OntoGPT also checks Oaklib credentials created with runoak set-apikey and passes them through to LiteLLM when the corresponding provider settings are missing.

Examples:

runoak set-apikey -e openai <your openai api key>
runoak set-apikey -e anthropic-key <your anthropic api key>
runoak set-apikey -e mistral-key <your mistral api key>
runoak set-apikey -e groq-key <your groq api key>

Some endpoints, such as Azure OpenAI, require additional details. These may be set similarly:

runoak set-apikey -e azure-key <your azure api key>
runoak set-apikey -e azure-base <your azure endpoint url>
runoak set-apikey -e azure-version <your azure api version, e.g. "2023-05-15">

These details may also be set as environment variables as follows:

export AZURE_API_KEY="my-azure-api-key"
export AZURE_API_BASE="https://example-endpoint.openai.azure.com"
export AZURE_API_VERSION="2023-05-15"

If the provider is not encoded in the model name, use --model-provider to specify it explicitly. This is most common for OpenAI-compatible proxy endpoints.

For the current list of supported providers, model naming rules, and credential environment variables, see the LiteLLM docs:

Open Models

Open LLMs may be retrieved and run through the ollama package (https://ollama.com/).

You will need to install ollama (see the GitHub repo), and you may need to start it as a service with a command like ollama serve or sudo systemctl start ollama.

Then retrieve a model with ollama pull <modelname>, e.g., ollama pull llama3.

The model may then be used in OntoGPT by prefixing its name with ollama/, e.g., ollama/llama3, along with the --model option.

Some ollama models may not be listed in ontogpt list-models but the full list of downloaded LLMs can be seen with ollama list command.

Evaluations

OntoGPT's functions have been evaluated on test data. Please see the full documentation for details on these evaluations and how to reproduce them.

Related Projects

  • TALISMAN, a tool for generating summaries of functions enriched within a gene set. TALISMAN uses OntoGPT to work with LLMs.

Tutorials and Presentations

  • Presentation: "Staying grounded: assembling structured biological knowledge with help from large language models" - presented by Harry Caufield as part of the AgBioData Consortium webinar series (September 2023)
  • Presentation: "Transforming unstructured biomedical texts with large language models" - presented by Harry Caufield as part of the BOSC track at ISMB/ECCB 2023 (July 2023)
  • Presentation: "OntoGPT: A framework for working with ontologies and large language models" - talk by Chris Mungall at Joint Food Ontology Workgroup (May 2023)

Citation

The information extraction approach used in OntoGPT, SPIRES, is described further in: Caufield JH, Hegde H, Emonet V, Harris NL, Joachimiak MP, Matentzoglu N, et al. Structured prompt interrogation and recursive extraction of semantics (SPIRES): A method for populating knowledge bases using zero-shot learning. Bioinformatics, Volume 40, Issue 3, March 2024, btae104, https://doi.org/10.1093/bioinformatics/btae104.

Acknowledgements

This project is part of the Monarch Initiative. We also gratefully acknowledge Bosch Research for their support of this research project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ontogpt-1.1.1.tar.gz (315.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ontogpt-1.1.1-py3-none-any.whl (475.0 kB view details)

Uploaded Python 3

File details

Details for the file ontogpt-1.1.1.tar.gz.

File metadata

  • Download URL: ontogpt-1.1.1.tar.gz
  • Upload date:
  • Size: 315.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ontogpt-1.1.1.tar.gz
Algorithm Hash digest
SHA256 0b6ba7b9663e008ff07e71463a244e4845654446e62f79dd540a35281b07748b
MD5 8c6b0a935c84e903b506daf4a5e86187
BLAKE2b-256 fe945bd59ff02b4b311fb1068ddc075bdf011c02bf4ff58aa83ee386ba2fe645

See more details on using hashes here.

Provenance

The following attestation bundles were made for ontogpt-1.1.1.tar.gz:

Publisher: pypi-publish.yml on monarch-initiative/ontogpt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ontogpt-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: ontogpt-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 475.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ontogpt-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5cfc6b6deaa310175fef40810106da5ed00745d1af139d99b31d8c2fb67d1cdd
MD5 a36d75425ef71d5d6c672b8644f4c184
BLAKE2b-256 6f0991b930c8fc87d542385156c91421f2a8b89137606f14ac4eccdf8cbc2c2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ontogpt-1.1.1-py3-none-any.whl:

Publisher: pypi-publish.yml on monarch-initiative/ontogpt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page