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

Send preloaded CODAP document info to LLM (PT-188713175) #24

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lublagg
Copy link
Collaborator

@lublagg lublagg commented Jan 7, 2025

This PR makes the following changes:

  • When the assistant is first initialized, the plugin gets information for each available data context, and sends that info to the LLM
  • Adds a documentChangeNotice handler so that when the plugin receives a notification that the document has changed (a data context has been deleted / created) an updated data context list is sent to the LLM
  • A dataContextChangeNotice handler so that when changes happen within a particular dataContext (attribute named updated, attributes deleted, columns moved, etc), the plugin grabs the new info for that dataContext, and sends it to the LLM
  • CODAP document/dataContext notifications that come in while the LLM is generating a response to a user query are stored in a queue and sent after the LLM is finished processing its run

@lublagg lublagg requested review from bgoldowsky and emcelroy January 7, 2025 20:14
@lublagg lublagg force-pushed the 188713175-provide-codap-context branch from 035d9a9 to 94a7fc2 Compare January 7, 2025 21:07
@lublagg lublagg changed the base branch from 188650872-describe-graph-by-text to main January 7, 2025 21:07
Copy link
Contributor

@emcelroy emcelroy left a comment

Choose a reason for hiding this comment

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

Looks good 👍 I left one small question/comment, but it may not require a change.

try {
self.transcriptStore.addMessage(DEBUG_SPEAKER, {description: "Sending CODAP document information to LLM", content: message});
const messageSent = yield self.apiConnection.beta.threads.messages.create(self.thread.id, {
role: "user",
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to change this role value to "system"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately with the Assistants API they don't allow that role value, only "user" and "assistant."

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Good to know.

Copy link

@bgoldowsky bgoldowsky left a comment

Choose a reason for hiding this comment

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

Mostly working great - I can see the information sent at initialization, and updates sent if I change data in the table. If I ask about the columns in the data, no requests are sent to CODAP and I get a faster response compared to if I ask about the rows, which reqires additional info to be requested from CODAP.

As discussed in Slack:

  • new messages triggered by the handlers result in errors if there is another run active.
  • newly-created data contexts need to have change handlers set up.

await initializePlugin({pluginName: kPluginName, version: kVersion, dimensions});
addDataContextsListListener(handleDocumentChangeNotice);
const dataContexts = await getListOfDataContexts();
dataContexts.values.forEach((ctx: Record<string, any>) => addDataContextChangeListener(ctx.name, handleDataContextChangeNotice));

Choose a reason for hiding this comment

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

This adds a dataContextChangeListener for each context that exists at startup. Do you also need to add one to contexts that are added later, when you're handling the documentchange?

Copy link
Contributor

@emcelroy emcelroy left a comment

Choose a reason for hiding this comment

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

This looks good to me, and seemed to work great in my testing. I left a couple comments about some very minor potential tweaks.


const sendCODAPDocumentInfo = flow(function* (message) {
try {
self.transcriptStore.addMessage(DEBUG_SPEAKER, {description: "Sending CODAP document information to LLM", content: message});
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be using formatJsonMessage(message) instead of just message?


// we don't send case-level information, only info about dataContexts, collections + attributes
// documentation about CODAP Data Interactive API notifications: https://github.com/concord-consortium/codap/wiki/CODAP-Data-Interactive-Plugin-API#codap-initiated-actions
export const notificationsToIgnore = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to put this in src/constants.ts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants