Skip to main content

Extension adds a pydantic ai chat interface to CKAN, that can run actions with user aware context.

Project description

ckanext-chat

Tests

A plugin integrating a chat interface in ckan with a pydanticai agent that can use all available ckan actions and url_patterns. All actions are done with user aware context. The chat interface uses marked and highightjs to display responses. Chat histories are saved in the local storage of the user. The agent is chat history aware. LLMs to use are configured in the bot/agent.py a section Model & Agent Setup. An Azure Openai and a local impementation using openai compartible api of ollama is implemeneted.

Option Rag Search

It has a rag_search tool that can facilitate a Milvus vector store if it is set up. Currently it relies on the Azure OpenAI embeddings api and will not work with local deployments. It uses the embedding model text-embedding-3-small to form the search vector. To make use of the documents it returns, the metadata of te vectores should include the dataset and resource ids at least. See the class VectorMeta for expected fields.

chat example

LLM Compartibility

Openai Models starting from gpt-35 on work very well. Local LLMs tested with ollama server are listed below.

LLM Compatible?
qwen2.5:32b works, but some wierd output
llama3.3:70B works not so well, reluctant to run actions right away
gemma3 not working, no tool support
phi4 not working, no tool support
qwq to much thinking, not enogh action
mistal:7B When Using OpenAI interface of Ollama no good tool integration

in general reasoning models dont perform well

Requirements

A completion endpoint of the LLM model to use with the agent is needed. Currently uses Azure Cognitive Service Integration. can be changed by replacing the client in /bot/agent.py

Compatibility with core CKAN versions:

CKAN version Compatible?
2.9 and earlier not tested
2.10 yes
2.11 yes

Suggested values:

  • "yes"
  • "not tested" - I can't think of a reason why it wouldn't work
  • "not yet" - there is an intention to get it working
  • "no"

Installation

To install the extension:

  1. Activate your CKAN virtual environment, for example:
. /usr/lib/ckan/default/bin/activate
  1. Use pip to install package
pip install ckanext-chat
  1. Add csvtocsvw to the ckan.plugins setting in your CKAN    config file (by default the config file is located at    /etc/ckan/default/ckan.ini).

  2. Restart CKAN. For example, if you've deployed CKAN with Apache on Ubuntu:

sudo service apache2 reload

Config settings

In your env variables set:

CKANINI__CKANEXT__CHAT__COMPLETION_URL="https://your-subscription.openai.azure.com/"
CKANINI__CKANEXT__CHAT__DEPLOYMENT="gpt-4o"
CKANINI__CKANEXT__CHAT__API_TOKEN="your-api-token"

or ckan.ini parameters.

ckanext.chat.completion_url="https://your-subscription.openai.azure.com/"
ckanext.chat.deployment="gpt-4o"
ckanext.chat.api_token="your-api-token"

Timeouts

To not run into api call timeouts the proxy infromt of ckan must be set to allow long running api calls for nginx

proxy_connect_timeout 3600s;
proxy_read_timeout 3600s;
proxy_send_timeout 3000s;
send_timeout 3000;

for production if ure using the official docker containers of ckan the harakiri options must be set. For this edit the start_ckan.sh script:

UWSGI_OPTS="--socket /tmp/uwsgi.sock \
            --wsgi-file /srv/app/wsgi.py \
            --module wsgi:application \
            --http 0.0.0.0:5000 \
            --master --enable-threads \
            --lazy-apps \
            -p 2 -L -b 32768 --vacuum \
            --harakiri-verbose \
            --socket-timeout $UWSGI_HARAKIRI \
            --harakiri $UWSGI_HARAKIRI \
            --http-timeout $UWSGI_HARAKIRI"

set in.env

UWSGI_HARAKIRI="3000"

Milvus Rag

if your also setup an Milvus vector database for rag search of documents or alike there is options you can set

ckanext.chat.embedding_mode=<embedding model name to request from the embedding api>
ckanext.chat.embedding_api=<api endpoint to send text to and to return an embeding>
ckanext.chat.milvus_url=<url to milvus server>
ckanext.chat.collection_name=<name of milvus collection

. You might need to lookup and change the exact embedding api generation because no api standard applies! If you dont set this options the literature_search agent will rely on the package_search action!

Developer installation

To install ckanext-csvtocsvw for development, activate your CKAN virtualenv and do:

git clone https://github.com/Mat-O-Lab/ckanext-chat.git
cd ckanext-chat
python setup.py develop
pip install -r dev-requirements.txt

Tests

To run the tests, do:

pytest --ckan-ini=test.ini

License

AGPL

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

ckanext_chat-0.1.6a0.tar.gz (970.4 kB view details)

Uploaded Source

Built Distribution

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

ckanext_chat-0.1.6a0-py3-none-any.whl (986.2 kB view details)

Uploaded Python 3

File details

Details for the file ckanext_chat-0.1.6a0.tar.gz.

File metadata

  • Download URL: ckanext_chat-0.1.6a0.tar.gz
  • Upload date:
  • Size: 970.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ckanext_chat-0.1.6a0.tar.gz
Algorithm Hash digest
SHA256 61c44054e948306119d3eed7eb2bb56b799a96c123a7a2afca38d32f057183af
MD5 4c6a13b2d4ef448498349d8f1ac39a68
BLAKE2b-256 f8a10c297280329f9af54bdd1f84a6b05c9605541d9e314ed2424b62a8dc268d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ckanext_chat-0.1.6a0.tar.gz:

Publisher: pypi.yml on Mat-O-Lab/ckanext-chat

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

File details

Details for the file ckanext_chat-0.1.6a0-py3-none-any.whl.

File metadata

  • Download URL: ckanext_chat-0.1.6a0-py3-none-any.whl
  • Upload date:
  • Size: 986.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ckanext_chat-0.1.6a0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b7f6950116df78b7654750bfc98d24c8912247602dc4dff76938d642e926605
MD5 a70dce3dfac40b1222120aa24b988fff
BLAKE2b-256 3e4bb19847ea44e6e7cacbe8d1f3fc4951a8e8f13681758890cbadabc095f7c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ckanext_chat-0.1.6a0-py3-none-any.whl:

Publisher: pypi.yml on Mat-O-Lab/ckanext-chat

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