A Directus extension that provides an Insights panel and API endpoint allowing you to chat with your data using OpenAI.
- Directus 10.6.0
- An OpenAI account with access to
gpt-3.5-turbo-0613
- This extension allows users to quickly find out useful information about their data using a chat interface. For example:
- How many customers do I have?
- How many sales did I have last month?
- List all of my customer's emails in the state of Texas.
- What is my top selling product this week?
- I used langchain.js (a modified version) to access the OpenAI API.
- A local copy resides in
packages
folder and can be built usingpnpm build:langchain
.
- A local copy resides in
- I built a bundle extension that provides an Insight panel (named 'Copilot') and an API endpoint (
POST /copilot/ask
). - If given longer, I would make many improvements:
- Store the chat history so it remains when the user navigates away from their dashboard.
- Ask the AI for richer data (like tables, markdown, etc.) that could be displayed in a companion side drawer alongside the chat.
- Enhance its capabilities by building an "Agent" that could plan multiple API calls instead of relying on a one-shot API call.
- Would allow the AI to explore more endpoints, and possibly even perform POST and PATCH operations!
- Support Llama and other LLMs, especially self-hosted ones.
- Allow users to fine-tune the LLM parameters, like temperature and which model.
- Remove the dependency on langchain in favor of something simpler, more lightweight.
- Smooth out the build process.
demo.mp4
![screenshot-1](https://private-user-images.githubusercontent.com/622192/264774146-de911a27-7ffb-4d7a-9f1e-3129489308f7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5MzE1OTksIm5iZiI6MTcyMzkzMTI5OSwicGF0aCI6Ii82MjIxOTIvMjY0Nzc0MTQ2LWRlOTExYTI3LTdmZmItNGQ3YS05ZjFlLTMxMjk0ODkzMDhmNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxN1QyMTQ4MTlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kNDdhYzQzODgzMjhiMDc2NTM1N2Y1Y2EwZDY4NjFkOTEyZDI1YmU2NzRlMmEyNjcwMGNlYzcyY2I1MWYzM2M4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.s2jSPDfb_SRY5ouj1xPfLqMR3-CpLdgxVpd-mD79Eio)
![screenshot-2](https://private-user-images.githubusercontent.com/622192/264797905-828fae64-4eea-4065-b4bf-4f965d7d2ffb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5MzE1OTksIm5iZiI6MTcyMzkzMTI5OSwicGF0aCI6Ii82MjIxOTIvMjY0Nzk3OTA1LTgyOGZhZTY0LTRlZWEtNDA2NS1iNGJmLTRmOTY1ZDdkMmZmYi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxN1QyMTQ4MTlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mNDA3NDQxYWY2ZjgyODMwMTJkOTU5MjZkNjFiMmFmODBiZDdkOTg3ZmM1NDRhZTYwMTdkYjlmOWUxNjM4YzAyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.du0TvApXlP1z6EAiw_VDW-OPCk10pRuGN--py857rX4)
![screenshot-3](https://private-user-images.githubusercontent.com/622192/264797912-c015086f-3db0-4055-9895-0f8a3aaa1934.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5MzE1OTksIm5iZiI6MTcyMzkzMTI5OSwicGF0aCI6Ii82MjIxOTIvMjY0Nzk3OTEyLWMwMTUwODZmLTNkYjAtNDA1NS05ODk1LTBmOGEzYWFhMTkzNC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxN1QyMTQ4MTlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT03NzlhYmZjZTFlOWE0ZThjZjA5ZDgzOTZlMjgwMTU2MDE2NGRkOWE3OGI1ZTZhODg1NzQ5NDNiMDNkN2YzMjhjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.UgimRhJLNtEIVuUp4NkI-OhIlCAo5uKvTtmf6IcEADE)
Building this extension is a bit wonky because of issues I had with langchain.js. I made some hacks, and copied the package locally to reference as a local package. To build this extension:
pnpm build:langchain
pnpm i
pnpm build
To spare you any trouble, I included the dist
folder so you can skip having to build the extension yourself.
The easiest way to install this extension is to clone it directly into your Directus project's extensions
path. Directus should then load it as a bundle extension.
Provide your OpenAI API key either by setting OPENAI_API_KEY
in your Directus configuration (e.g. your .env
), or by pasting your key into the field when configuring the Copilot panel on your Insights dashboard.