Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an open source data layer #793

Open
tpatel opened this issue Mar 6, 2024 · 18 comments
Open

Create an open source data layer #793

tpatel opened this issue Mar 6, 2024 · 18 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@tpatel
Copy link
Collaborator

tpatel commented Mar 6, 2024

Chainlit has a feature that enables you to store, analyze and persist your data with Literal.
You can also create your own custom data layer to store the data in your database.

The goal of this ticket is to create an implementation of a custom data layer using a database like postgres or redis.
You can see an example of a custom data layer in this test, although it doesn't connect to a database.

@tpatel tpatel added help wanted Extra attention is needed good first issue Good for newcomers labels Mar 6, 2024
@hayescode
Copy link
Contributor

Only existing version (using chainlit version 0.7.0) can be found here

Will Chainlit Devs assist in this effort or will this be 100% community-driven?

@tpatel
Copy link
Collaborator Author

tpatel commented Mar 7, 2024

@hayescode thanks for sharing this repo. They decided to rebuild a graphql API.
With the custom data layer feature, you should be able to store data in any database without having to build this graphql API, thanks to the interface.

A custom data layer needs:

  1. One class that inherit from chainlit.data.BaseDataLayer
  2. In your chainlit app, you need:
import chainlit.data as cl_data

cl_data._data_layer = MyDataLayer()

This removes the need to stay compatible with the graphql API, the need to maintain a server reachable via your chainlit app. And it enables a direct connection to your DB.

I'm looking into other chainlit tasks at the moment, but I'll be around to review PRs and help!

@AndreasMarcec
Copy link

I'm currently working on my own Data Layer which is based on the BaseDataLayer. Could you please specify which of the features would be mandatory in order to create a valid PR?

@Rajatkhanna801
Copy link

Hi
I want to add MSAL authentication in custom layer. Can anyone help me with that.

@sandangel
Copy link
Contributor

Hi, I'm implementing this PR: #796
Is it possible to share where do we create_thread? I could not find it in the code.

@tpatel
Copy link
Collaborator Author

tpatel commented Mar 12, 2024

I'm currently working on my own Data Layer which is based on the BaseDataLayer. Could you please specify which of the features would be mandatory in order to create a valid PR?

@AndreasMarcec The best would be a complete implementation that overrides all methods from the BaseDataLayer (https://github.com/Chainlit/chainlit/blob/main/backend/chainlit/data/__init__.py#L53). You could start with a partial implementation though, and get help if you're stuck on anything.

@tpatel
Copy link
Collaborator Author

tpatel commented Mar 12, 2024

Hi I want to add MSAL authentication in custom layer. Can anyone help me with that.

@Rajatkhanna801 the best would be to start with the Authentication callback. This is a configuration on a per-app basis. No need for custom data layer if you just need MSAL Authentication.
I'm not familiar with MSAL, feel free to create another issue if you encounter any issue.

@Rajatkhanna801
Copy link

@tpatel
I have already done with MSAL authentication and it is working preety good. Now I am creating custom layer to add data in SQLite database.

@Rajatkhanna801
Copy link

@tpatel I need one help the SQLite database needs to create a user table is there is already predefined model structure for user table?

@hayescode
Copy link
Contributor

hayescode commented Mar 15, 2024

Hi, I'm implementing this PR: #796
Is it possible to share where do we create_thread? I could not find it in the code.

@sandangel the update_thread function is an upsert. I agree it's weird everything else has a create/update/delete but not for threads..

@hayescode
Copy link
Contributor

@tpatel if you could share the DDL for the backend tables I think it would speed up each of our developments. Thanks!

@sandangel
Copy link
Contributor

@hayescode I updated the code to mimic literalai client instead. It's working now, just need a few update on filter.

@hayescode
Copy link
Contributor

@sandangel why did you do that?

@sandangel
Copy link
Contributor

@hayescode I explained in the PR.

@hayescode
Copy link
Contributor

@willydouhard @tpatel @constantinidan implementing a custom data layer is proving difficult with the intertwining of literalai in chainlit/data. Literalai is effectively a dependency as-is even if literalai isn't used and will make long-term support more difficult. For example chainlit expects pagination, thread filters, etc. types from literalai in order to work. These would ideally be in Chainlit.

Will chainlit be refactored to natively support Chainlit functionality?

@hayescode
Copy link
Contributor

I just opened a PR to add a Postgres custom data layer with ADLS support -> #825

@tpatel @willydouhard

@tjroamer
Copy link

Just opened a PR to add a simple file-based SQLite data layer -> #832

No need to set up extra database. By default, the data is persisted in chainlit.db in working dir. The user can use any SQLite database tool to view the DB.

@tpatel @willydouhard

@hayescode
Copy link
Contributor

@tpatel @willydouhard Here's my PR for adding a dialect agnostic SQLAlchemy custom data layer. We've been getting more community contributions on this lately, can we move this to 'In Progress' or 'In Review'?

#836

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
Development

No branches or pull requests

6 participants