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

Dashboard: Auto-generate panel title and description using AI #74284

Merged

Conversation

nmarrs
Copy link
Contributor

@nmarrs nmarrs commented Sep 1, 2023

What is this feature?

Implements basic panel title and description generation.

Roughly based on the DashGPT hackathon PR but with some cleaned up patterns / refactors to make this functionality more maintainable moving forward :)

TODO

  • Clean up description implementation (remove preview (maybe dependent on feature flag 🤷), make default text input box larger
  • Clean up list of todos in PR :)
  • Biggest technical cleanup IMO is avoiding the special character return ~ system and doing something more robust from the actual API call for getting done status
Generate and description Plugin not configured
2023-09-14 21 41 47 2023-09-14 21 49 03

Which issue(s) does this PR fix?:

Fixes #74241
Fixes #74242

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@nmarrs nmarrs added no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes area/dashgpt Issues related to the dashgpt project area/generativeAI for issues that involve generative AI labels Sep 1, 2023
@nmarrs nmarrs added this to the 10.2.x milestone Sep 1, 2023
@@ -0,0 +1,30 @@
import { css } from '@emotion/css';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is hard... wasnt sure to keep with DashGPT or just try to make it more general to generative AI - i dont feel strongly either way so please feel free to modify any and all naming 😅

import { getDashboardSrv } from '../../services/DashboardSrv';

// TODO: Replace this approach with more stable approach
export const SPECIAL_DONE_TOKEN = '~';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file definitely needs some work - we should move away from hacky special done token in favor of receiving done result from llm plugin API directly

Also we should consider a better way to share this code betwen title / description generation + potentially more use cases (at the very least use an enum instead of passing around "title" and "description" everywhere

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not concentrate all possible "Generative AI calls" in a single place. Instead, every component will contain the prompt to be sent. Then this service will become just a simplification of the llm librarly API, which it creates a signal of: Are we duplicating with no reason? Can we just modify the llm library if we find it hard to use?

IMO, we just should use llm directly with no services in between.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should be able to move the odd logic around detecting if streams are done into the grafana/experimental package so that we don't have to do this oddball logic with it.

@ivanortegaalba
Copy link
Contributor

Taking a look to the implementation, do you think we can create a component to group all the functionalities for the generation?

Something like:

<AutoGenerateWithAI messages={} onGenerateOutput={(result) => setState(result)} onClick={trackUsage} />

@ivanortegaalba
Copy link
Contributor

I did a big refactor to simplify the implementation

  1. I decentralized the prompt generation for title and description. I don't like the service grows when adding more generative AI features. Instead, I created component wrappers that manage the message generation
  2. I moved the llm library usage to the GenAIButton This ensures every place where we use the LLM button, the experience is the same. You can see the components for descriptions and title are only focused on the prompt configuration
  3. I added an status when the plugin is not properly configured

@ivanortegaalba ivanortegaalba changed the title [WIP] Dashgpt: Implement panel title and description generation Dashgpt: Implement panel title and description generation Sep 14, 2023
@ivanortegaalba ivanortegaalba requested review from kaydelaney, L-M-K-B, JoaoSilvaGrafana and mckn and removed request for a team September 14, 2023 19:50
@ivanortegaalba
Copy link
Contributor

I pushed a bunch of changes, the PR should be ready to be reviewed 😄

  • Update to the latest @grafana/experimental
  • I decentralized the prompt generation for title and description. I don't like the service grows when adding more generative AI features. Instead, I created component wrappers that manage the message generation
  • I moved the llm library usage to the GenAIButton This ensures every place where we use the LLM button, the experience is the same. You can see the components for descriptions and title are only focused on the prompt configuration
  • I added a status when the plugin is not properly configured

About the usage of the character to detect the end of the stream, it should be fixed in llms library

@ivanortegaalba
Copy link
Contributor

@nmarrs since I changed quite a lot of code, I'd like to get your review, before merging, because you opened the PR 😄

Copy link
Contributor Author

@nmarrs nmarrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code wise this is looking great IMO for initial POC 👍 I'm not able to approve this as I created PR but consider this APPROVED 💯✅

*/
export function cleanupResponse(response: string) {
return response.replace(SPECIAL_DONE_TOKEN, '').replace(/"/g, '');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love all of the included doc strings here

Copy link
Contributor

@ivanortegaalba ivanortegaalba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by @nmarrs

@ivanortegaalba ivanortegaalba merged commit 8a127c4 into main Sep 19, 2023
18 checks passed
@ivanortegaalba ivanortegaalba deleted the dashgpt-implement-panel-title-and-description-generation branch September 19, 2023 13:40
@ivanortegaalba ivanortegaalba changed the title Dashgpt: Implement panel title and description generation Dashboard: Auto-generate panel title and description using AI Sep 19, 2023
@ivanortegaalba ivanortegaalba added add to changelog and removed no-changelog Skip including change in changelog/release notes labels Sep 19, 2023
Comment on lines +24 to +29
const input = document.getElementById('PanelFrameTitle');
if (input instanceof HTMLInputElement) {
input.value = title;
onPanelConfigChange('title', title);
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nmarrs
why the getElementById here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, pinged wrong person, was supposed to ping @ivanortegaalba

rwwiv pushed a commit that referenced this pull request Oct 2, 2023
* Add "addon" prop to options panel item descriptor; add placeholder generate buttons to panel title + description

* Add basic `ai` icon; add separate wrapping component for panel title generation button

* Add basic panel title generation

* Add basic panel description generation

* Add configuration error state for GenAI button

* Add GenAI button generic component

---------

Co-authored-by: Ivan Ortega <ivanortegaalba@gmail.com>
Co-authored-by: Adela Almasan <adela.almasan@grafana.com>
@zerok zerok modified the milestones: 10.2.x, 10.2.0 Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/dashgpt Issues related to the dashgpt project area/frontend area/generativeAI for issues that involve generative AI no-backport Skip backport of PR
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

DashGPT: Implement panel description generation DashGPT: Implement panel title generation
6 participants