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

Chat with your pipelines functionality #56

Open
wants to merge 129 commits into
base: develop
Choose a base branch
from

Conversation

wyennie
Copy link

@wyennie wyennie commented Sep 24, 2024

Summary

This pull request introduces a comprehensive set of features and improvements to the chatbot functionality within the VSCode ZenML extension. The updates enhance user interaction, context management, and overall user experience.

Chat Interface Enhancements:

  • Created chat interface UI.
  • Added support for markdown rendering using markedjs.
  • Integrated Gemini, Anthropic, and OpenAI APIs using TokenJS.

Context Management:

  • Added context for server, stack, components, and environment data.
  • Added functions for gathering context.
  • Connected context to selector for server/stack/components/environment data.
  • Added buttons to the UI to select context.

Pipeline Integration:

  • Added specific pipeline runs and metadata to the chatbot UI.
  • Retrieved log data for pipeline runs from the dashboard API.

UI and UX Improvements:

  • Created a dropdown menu.
  • Overhauled the UI to be more minimalistic.
  • Added a context selector UI.

Contributors

@wyennie
@Nathaniel-Xu
@alan-cho

Summary by CodeRabbit

  • New Features

    • Introduced a dynamic chat interface within the Visual Studio Code extension.
    • Enhanced chat log rendering with improved message styling and filtering.
    • Added dropdowns for selecting chat providers and models, enhancing user interactivity.
    • Implemented commands for opening chat and registering LLM API keys.
    • Expanded functionality with new dependencies for language processing and web interactions.
    • Added support for CSS processing with Tailwind CSS.
    • Introduced a configuration for PostCSS to manage CSS enhancements.
  • Bug Fixes

    • Updated dependencies for improved performance and security.
  • Style

    • Added comprehensive styling for the chat interface to enhance user experience.
  • Documentation

    • Updated documentation to reflect new features and commands.
  • Tests

    • Updated testing requirements for Python to ensure compatibility with new features.

sklarfox and others added 30 commits August 21, 2024 12:25
Co-authored-by: Nathaniel Xu <[email protected]>
Co-authored-by: Alan Cho <[email protected]>
Added functionality to the chat window in the sidebar (activity bar).
User input is now sent to the Gemini API using TokenJS, and the response from the API is displayed in the chat window.

Co-authored-by: Nathaniel Xu <[email protected]>
Co-authored-by: Alan Cho <[email protected]>
Co-authored-by: Nathaniel-Xu <[email protected]>
Co-authored-by: William Yennie <[email protected]>
Co-authored-by: William Yennie <[email protected]>
Co-authored-by: Nathaniel Xu <[email protected]>
Co-authored-by: William Yennie <[email protected]>
Co-authored-by: Nathaniel Xu <[email protected]>
Integrated `marked` library to convert Markdown text to HTML.
Updated `ChatViewProvider` to process and render Markdown in chat message.
Modified `renderChatLog` to parse Markdown before displaying message.
…re files

Renamed ChatViewProvider to ChatDataProvider for consistency with other files
Moved ChatDataProvider class from extension.ts to src/activityBar/chatView
Moved chat.js, chat.html, and chat.css to resources/chat-view
removed typescript error

Co-authored-by: William Yennie <[email protected]>
Added missing semicolons and formatted code
Fixed TypeScript linting issues with type checks and type guards
Improved error handling and logging
…e/chatbot

merge: feature/secrets into feature/chatbot

Integrates updates from the `feature/secrets` branch in sklar-fork into `feature/chatbot`. Includes changes related to chatbot functionality improvements.
@strickvl strickvl changed the title Feature/chatbot Chat with your pipelines functionality Sep 25, 2024
@strickvl strickvl added the enhancement New feature or request label Sep 25, 2024
@wyennie wyennie force-pushed the feature/chatbot branch 2 times, most recently from ff7852b to 39bcbab Compare September 25, 2024 19:09
- Changed `pipelineRuns` property from public to private to better encapsulate internal state.
- Added `getPipelineRuns` method to provide controlled access to the `pipelineRuns` data.
- Included documentation for the `pipelineRuns` property and `getPipelineRuns` method.
…ogic

- Wrapped fs.readFileSync in a try-catch block to handle potential errors and prevent uncaught exceptions.
- Added type guard to ensure proper error message display.
- Updated pagination button logic to ensure correct assignment of next and previous buttons.
…n reference

- Store the bound function reference for `refreshWebview` in a variable `refreshWebviewBound`.
- Update event listener addition and removal to use `refreshWebviewBound`.
…rovider

- Ensure currentModel is initialized using the first model from getAvailableModels() for the 'Gemini' provider.
- This prevents potential issues where currentModel does not match an available model.
…lay in response streaming

- Updated error message in `addMessage` to dynamically include the current provider name instead of hardcoding 'Gemini'.
- Removed the unnecessary 1ms delay in the response streaming loop to improve performance.
- Added a check to ensure `pipelineRunSteps[0]` exists before mapping in `getLogData` to prevent potential undefined access.
- Refactored null checks using optional chaining in `getLogData` for cleaner and more concise code.
- Added error handling for axios GET request in `getPipelineRunLogs` to handle potential request failures and log errors appropriately.
- Added a try-catch block around JSON.parse in the default case of addContext to handle potential parsing errors.
- Logged errors to the console and added a fallback message to systemMessage to inform the user when pipeline run data cannot be parsed.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5860d10 and 30ffa7a.

📒 Files selected for processing (2)
  • resources/chat-view/chat.js (1 hunks)
  • src/views/chatView/utils/ContextUtils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • resources/chat-view/chat.js
🧰 Additional context used
📓 Path-based instructions (1)
src/views/chatView/utils/ContextUtils.ts (1)

Pattern **/*.ts: Review the Typescript code for conformity with industry standards and best practices, highlighting any deviations.

🪛 Biome
src/views/chatView/utils/ContextUtils.ts

[error] 124-124: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/views/chatView/utils/ContextUtils.ts Outdated Show resolved Hide resolved
src/views/chatView/utils/ContextUtils.ts Outdated Show resolved Hide resolved
src/views/chatView/utils/ContextUtils.ts Outdated Show resolved Hide resolved
src/views/chatView/utils/ContextUtils.ts Outdated Show resolved Hide resolved
src/views/chatView/utils/ContextUtils.ts Outdated Show resolved Hide resolved
src/views/chatView/utils/ContextUtils.ts Outdated Show resolved Hide resolved
src/views/chatView/utils/ContextUtils.ts Outdated Show resolved Hide resolved
src/views/chatView/utils/ContextUtils.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
resources/chat-view/chat.js (1)

151-158: Ensure strict sanitization when rendering markdown content

While you're sanitizing the HTML output of marked.parse using DOMPurify, it's important to verify that the configuration prevents potential XSS attacks, especially if currentAssistantMessage contains user-generated content.

Consider setting up DOMPurify with strict policies and configuring marked to disallow embedded HTML:

marked.setOptions({
  gfm: true,
  breaks: true,
  headerIds: false,
  mangle: false,
});

const html = marked.parse(currentAssistantMessage);
const sanitizeHtml = DOMPurify.sanitize(html, { ALLOWED_TAGS: [], ALLOWED_ATTR: [] });

This configuration ensures that only basic text formatting is allowed, mitigating XSS risks.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 30ffa7a and 7d7a106.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (7 hunks)
  • resources/chat-view/chat.html (1 hunks)
  • resources/chat-view/chat.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • resources/chat-view/chat.html
🧰 Additional context used
📓 Path-based instructions (1)
resources/chat-view/chat.js (1)

Pattern **/*.js: Review the JavaScript code for conformity with the Google JavaScript style guide, highlighting any deviations.

🪛 Biome
resources/chat-view/chat.js

[error] 193-193: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

🔇 Additional comments (2)
resources/chat-view/chat.js (2)

110-112: Potential XSS vulnerability: setting innerHTML without sanitization

At line 111, document.getElementById('chatMessages').innerHTML = message.chatLogHtml; is setting innerHTML without sanitization. This could expose the application to Cross-Site Scripting (XSS) attacks if message.chatLogHtml contains malicious content.


209-214: Cannot use vscode.window.showInformationMessage in the webview

The method vscode.window.showInformationMessage is not available in the webview context. Attempting to call it from the webview will result in an error.

resources/chat-view/chat.js Outdated Show resolved Hide resolved
resources/chat-view/chat.js Show resolved Hide resolved
Replaced CDN styles with Tailwind CSS. Configured build process and updated paths to ensure proper loading in the VSCode extension.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Outside diff range and nitpick comments (2)
tailwind.config.js (2)

4-6: Consider custom theme extensions for chat view.

The theme configuration is correctly structured with an empty extend object. This is valid and allows for future extensions. However, consider if any custom theme extensions (e.g., colors, fonts, or spacing) might be beneficial for the chat view's specific design requirements.

If custom theme extensions are needed, you can add them like this:

theme: {
  extend: {
    colors: {
      'chat-primary': '#your-color-here',
      'chat-secondary': '#your-color-here',
    },
    fontFamily: {
      'chat': ['Your-Font-Here', 'sans-serif'],
    },
    // Add other extensions as needed
  },
},

7-7: Consider useful Tailwind plugins for chat functionality.

The empty plugins array is valid. However, consider if any Tailwind plugins could enhance the chat view's functionality or styling. For example, the @tailwindcss/typography plugin could be useful for styling markdown content in chat messages.

If you decide to use plugins, you can add them like this:

module.exports = {
  // ...other config
  plugins: [
    require('@tailwindcss/typography'),
    // Add other plugins as needed
  ],
}

Don't forget to install any plugins you add:

npm install -D @tailwindcss/typography
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 13a0ff5 and 32dccd3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • noxfile.py (1 hunks)
  • package.json (8 hunks)
  • postcss.config.js (1 hunks)
  • resources/chat-view/chat.html (1 hunks)
  • resources/chat-view/styles.css (1 hunks)
  • src/views/chatView/chatRenderer.ts (1 hunks)
  • tailwind.config.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • package.json
  • resources/chat-view/chat.html
  • src/views/chatView/chatRenderer.ts
🧰 Additional context used
📓 Path-based instructions (3)
noxfile.py (1)

Pattern **/*.py: "Review the Python code for conformity with Python best practices and industry standards, highlighting any deviations."

postcss.config.js (1)

Pattern **/*.js: Review the JavaScript code for conformity with the Google JavaScript style guide, highlighting any deviations.

tailwind.config.js (1)

Pattern **/*.js: Review the JavaScript code for conformity with the Google JavaScript style guide, highlighting any deviations.

🔇 Additional comments (2)
tailwind.config.js (2)

1-1: LGTM: Proper type annotation for Tailwind config.

The JSDoc type annotation is correctly used to provide TypeScript support for the Tailwind configuration object.


2-2: LGTM: Correct module export syntax.

The configuration object is properly exported using CommonJS syntax, which is appropriate for Node.js environments and consistent with Tailwind's documentation.

postcss.config.js Outdated Show resolved Hide resolved
tailwind.config.js Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
resources/chat-view/styles.css Outdated Show resolved Hide resolved
resources/chat-view/styles.css Outdated Show resolved Hide resolved
resources/chat-view/styles.css Outdated Show resolved Hide resolved
@wyennie wyennie marked this pull request as draft September 27, 2024 18:18
- Added a check to handle context strings starting with 'Pipeline Run:'.
- Expanded ContextType union to include string for dynamic context handling.
- Retained switch case for other context types and added a default case to log unknown context types.

This ensures that pipeline run contexts are correctly parsed and processed, preventing unknown context type warnings in the console.
- Updated addContext function to handle dynamic pipeline run contexts and log unknown context types.
- Added error handling to getServerData function to ensure it always returns a string, even on failure.
- Enhanced getStackComponentData function with error handling and improved type safety using type guards.
- Added error handling to getEnvironmentData function to handle potential promise rejections.
- Improved getStackData function with error handling and safer property access using type guards.

These changes improve the robustness and maintainability of the utility functions by ensuring they handle errors gracefully and enforce type safety.
- Refactored getLogData:
  - Extracted fetchLogs function.
  - Improved error handling and logging.

- Refactored getPipelineRunLogs:
  - Extracted common logic into fetchLogs.
  - Enhanced type annotations and error handling.

- Refactored getPipelineRunNodes:
  - Added NodeType type.
  - Improved error handling and variable naming.
  - Extracted node filtering logic.

These changes improve robustness, maintainability, and readability.
- Replaced Event constructor with CustomEvent for better compatibility in VSCode webview environment.
- Wrapped case body in braces to prevent variable hoisting issues in switch-case statements.
- Added error handling, logging, and optional watch flag to build_css.
- Removed the redundant dev function.
- Replaced `display: contents;` with `display: flex;` for the `<form>` element to maintain accessibility.
- Changed hardcoded `color: black !important;` to `color: var(--vscode-editor-foreground);` for `ul` elements to ensure theme consistency.
- Removed redundant color properties from `#chatMessages` child elements to allow inheritance and simplify the CSS.
@wyennie wyennie marked this pull request as ready for review September 27, 2024 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants