This repository provides an example implementation of a Talk to Your Graph (TTYG) client for GraphDB. The client interacts with a GraphDB instance using low-level API calls to handle tool (query method) calls while performing base communication with the OpenAI API itself.
This mimics the TTYG client built into GraphDB Workbench and is the most flexible approach for integrating TTYG in your own application.
The full story behind the client is described in the Talk to Your Graph Client for GraphDB blog post.
- Leverages GraphDB and OpenAI to provide a third-party client for Talk to Your Graph
- Communicates with OpenAI Assistants API for natural language understanding and generation.
- Executes tool (query method) calls using GraphDB's low-level TTYG API.
- Configurable via a YAML file.
- GraphDB instance: A running GraphDB instance accessible via HTTP(S).
- TTYG agent: Ensure that one or more TTYG agents are already created in GraphDB Workbench. The client and the API it uses do not provide agent management.
- OpenAI API key: A valid OpenAI API key or Azure OpenAI setup. This must be identical to the OpenAI configuration of GraphDB.
- Python: Python 3.13+ installed on your system.
git clone https://github.com/Ontotext-AD/ttyg-client.git
cd ttyg-clientFirst, create a Python virtual environment.
python -m venv venvThen, activate the environment:
source venv/bin/activatepip install -r requirements.txtThe client.yaml file contains essential configuration parameters for both OpenAI and GraphDB. Edit the file to suit your environment. The file includes the following sections:
openai:
# Set this to your OpenAI API key
api_key: <your_openai_api_key>
# Set this to your Azure OpenAI URL if using Azure OpenAI
api_url:
# Azure API version
azure_api_version: 2024-08-01-previewgraphdb:
# The base URL of the GraphDB instance
url: http://localhost:7200
# GraphDB username to associate with created threads and use for HTTP basic auth
username: <your_graphdb_username>
# Set this to use HTTP basic auth (with the above username)
password:
# Set this to use a custom HTTP authorization header (for example, GraphDB or OpenID token)
auth_header:
# TTYG installation ID
installation_id: __default__Note that you need to specify a username even if GraphDB is not configured with security. Threads (and thus chats) are associated with the username.
If GraphDB has security enabled you must provide either the password (for using HTTP Basic auth) or an authorization header (for all other authentication types, e.g., an OpenAI Bearer token).
python chat.py <assistant-id> (<thread-id>|new)- Start the client: Run the
chat.pyscript to initiate communication. Note that you must pass the assistant ID and thread ID (or new to create a new thread) as arguments. If you run the script without arguments, it will show a list of all existing assistants and threads. - Communicate: Input natural language questions that will be processed by the OpenAI Assistant API and, if needed, translated into GraphDB tool queries that will allow the model to answer the questions.
- Inspect responses: The model will answer the questions by using context or invoking tools.
When running the chat, the following !-prefixed commands are available:
!help: Displays a list of available commands.!explain: Shows the tools used to answer the last question.!list: Lists the available assistants and threads.!assistant <assistant-id>: Switches to a different assistant.!thread <thread-id>|new: Switches to a different thread or creates a new thread.!rename <name>: Renames the current thread.!delete: Deletes the current thread.
Thread IDs and Persistence: Thread IDs (chats) are persisted locally due to limitations of the OpenAI Assistants API. Threads created in the client will not be visible in the GraphDB Workbench and vice versa.
chat.py: Main code and entry point for running the client.thread_store.py: Handles thread management for queries and responses.config.py: Manages configuration loading and parsing.
This client can be extended to support more sophisticated interaction patterns. Modify the API integration logic in chat.py as needed.
- Talk to Your Graph Client for GraphDB blog post
- Talk to Your Graph Documentation
- OpenAI Assistants API Documentation
This project is licensed under the Apache 2.0 License.