dotnet-smartcomponents / smartcomponents

Experimental, end-to-end AI features for .NET apps
693 stars 61 forks source link

AI DataGrid Component #18

Open DjeeBay opened 8 months ago

DjeeBay commented 8 months ago

Just an idea here where a user could describe in a texterea what and how the data should be presented (sorted by, sum of columns, filters, drawing a chart, export)

This way the end user can display the data he wants and the developer doesn't have to code all those features that are common and easy for an AI to make.

Could also be a feature to translate the user description to SQL under the hood so the developer can use it to get the data from the database. Developer will need to be very aware about security concerns though.

For instance an input could be : "Show me the countries with the population, the average age of population and display the sum of the population column. Display it on a datagrid and a pie chart."

SteveSandersonMS commented 8 months ago

That's a cool idea, thanks for submitting it.

In fact there's a whole area of AI research dedicated to this problem already, known as text-to-sql. It's very possible to resolve queries that are phrased in a way that translates nicely to SQL concepts.

One big challenge in this area, however, is that very often users will pose questions that don't have an objective answer (or where the "objective" answer depends on definitions in the user's mind that aren't found in the data). This can lead to getting misleading or wrong query results, which in turn could cause business problems. As a simple example, imagine a DB table with [customer_name, country_name, amount_spent] columns, and the user asks "List the 5 top-spending customers in Asia". The model may think it knows the names of all countries in Asia, but it might have a different definion of "Asia" than you think, or it might phrase/spell the country names differently than you expected (e.g., Timor-Leste vs Timor Leste, not to mention the politics around disputed country names). As such, the generated "where" clause has very little chance of matching what you want.

So, as long as the user has pretty lenient expectations around correctness, this can definitely be made to work. And in many cases can be really useful. You just have to school the user very aggressively not to trust the output as a basis for business decisions, and that any important query needs human expert review.

quicksln commented 7 months ago

Hello There,

I found this topic after I created a discussion topic, just linked both https://github.com/dotnet-smartcomponents/smartcomponents/discussions/47

It should be possible, and we could look at potential solutions from at least two perspectives.

First: As @DjeeBay suggested, it involves potential SQL creation and dynamic dataset bindings, which I think is doable but quite complex as @SteveSandersonMS mentioned.

Second: Is to implement a Smart Component for Quick Grid Search and Filtering, which will be based on an already fetched dataset. I understand it can also be challenging because of the dynamic nature of what we are binding to the grid, but creating an intermediate JSON layer could do the trick in theory.

What do you think about that?

DjeeBay commented 7 months ago

In fact if the data is already fetched you can finally have the Excel Copilot experience. The end user should be aware that the results depend on his prompt's quality AND the fact that AI can hallucinate.

quicksln commented 7 months ago

I completely agree that users should be aware of this AI feature. However, I believe, it is the developers' responsibility to inform users when a solution incorporates AI-enhanced Smart Components.

The Excel Copilot Experience would be excellent, but I have something simpler in mind. Please take a look at the attached screen capture of the proof of concept (it's far from the final solution)

Untitled Project

This sample operates on already-fetched data, so we are not sending information about the database to AI. It's not possible to "hack AI" to harm our database via prompt - I think the worst-case scenario dataset result would be empty.

The AI doesn’t know anything about the actual data, except of the view model schema, making it quite safe. It could be wrap in general method, something like this:

public static async Task<IQueryable<T>> FilterByAsync(string userPrompt, IQueryable<T> dataSource, CancellationToken cancellationToken)

It was fun to work on this sample. I am very curious about whether such a component would be useful. Please let me know what you think.