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

Adds new GoaT NLP UI along with seamless streaming between frontend and servers #33

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

Conversation

deepnayak
Copy link
Collaborator

@deepnayak deepnayak commented Sep 18, 2024

Summary by Sourcery

Add a new GoaT NLP UI with seamless streaming between frontend and servers, enhancing user interaction. Introduce new chat features like voice input, code highlighting, and model switching. Update the installation guide and add comprehensive tests for the query pipeline components.

New Features:

  • Introduce a new GoaT NLP UI with seamless streaming capabilities between the frontend and servers, enhancing user interaction and data processing.
  • Add a new chat interface with features like voice input support, code syntax highlighting, and model switching for a more interactive user experience.
  • Implement a new sidebar for chat history and user settings, allowing users to manage their chats and preferences easily.
  • Introduce a new testing guide in the documentation to help developers run tests efficiently.

Enhancements:

  • Refactor the query classification logic to improve the accuracy of taxon and assembly identification in user queries.
  • Enhance the chat UI with a responsive design, making it fully functional on both desktop and mobile devices.
  • Improve the chat message handling by adding a debug element for better error tracking and resolution.

Build:

  • Update the build configuration to support the new UI components and ensure compatibility with the latest dependencies.

Documentation:

  • Update the installation guide to include steps for setting up the new UI and running tests.

Tests:

  • Add comprehensive tests for the query pipeline components to ensure the reliability and accuracy of the NLP functionalities.

Copy link

sourcery-ai bot commented Sep 18, 2024

Reviewer's Guide by Sourcery

This pull request introduces a new GoaT NLP UI with seamless streaming between frontend and servers. The changes include updates to the backend Python code for handling queries and processing data, as well as the addition of a new Next.js-based frontend UI with various components for chat functionality, model selection, and user interactions.

File-Level Changes

Change Details Files
Updated backend query processing and data handling
  • Modified prompt templates for query classification and entity identification
  • Added new functions for attribute identification and condition definition
  • Updated the query pipeline to include new steps and improve data flow
src/prompt.py
src/agent/component_helpers.py
src/agent/query_pipeline.py
Implemented new Next.js-based frontend UI
  • Created chat components for message display and input
  • Added user settings and model selection functionality
  • Implemented dark mode and theme switching
  • Created API routes for chat and model management
ui/src/app/page.tsx
ui/src/components/chat/chat-layout.tsx
ui/src/components/chat/chat-list.tsx
ui/src/components/chat/chat-bottombar.tsx
ui/src/components/user-settings.tsx
ui/src/app/api/chat/route.ts
ui/src/app/api/model/route.ts
Enhanced streaming capabilities between frontend and backend
  • Implemented server-sent events for real-time updates
  • Added support for speech-to-text input in the chat interface
  • Created a streaming response handler in the backend
src/app.py
ui/src/app/page.tsx
ui/src/app/hooks/useSpeechRecognition.ts
Added UI components and utilities
  • Created reusable UI components like buttons, dialogs, and dropdowns
  • Implemented utility functions for theming and styling
  • Added emoji picker and code syntax highlighting features
ui/src/components/ui/button.tsx
ui/src/components/ui/dialog.tsx
ui/src/components/ui/dropdown-menu.tsx
ui/src/lib/utils.ts
ui/src/components/code-display-block.tsx
ui/src/components/emoji-picker.tsx

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @deepnayak - I've reviewed your changes - here's some feedback:

Overall Comments:

  • This PR adds a new GoaT NLP UI with streaming functionality between the frontend and servers. It includes significant updates to the chat interface, new components for handling user input and displaying responses, and integration with the GoaT API.
  • The changes introduce a more robust error handling system and improved state management for the chat application. However, it would be beneficial to add more comprehensive documentation for the new components and functions to aid future maintenance and development.
Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 4 issues found
  • 🟡 Documentation: 4 issues found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -29,6 +34,7 @@
LlamaIndexInstrumentor().instrument(tracer_provider=tracer_provider)

app = Flask("goat_nlp")
CORS(app)
Copy link

Choose a reason for hiding this comment

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

🚨 suggestion (security): Specify allowed origins for CORS

For better security, consider specifying allowed origins rather than allowing all origins. This helps prevent unauthorized access from potentially malicious sources.

Suggested change
CORS(app)
CORS(app, resources={r"/*": {"origins": ["https://yourdomain.com", "http://localhost:3000"]}})

@@ -27,6 +28,7 @@
def identify_index(input: str, state: Dict[str, Any]):
index_response = Settings.llm.complete(INDEX_PROMPT.format(query=input)).text
state["index"] = json.loads(extract_json_str(index_response))
state["status"] = "Identify Index"
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider using an enum for status values

Using an enum for status values would provide better type safety and prevent potential typos in status strings. It would also make it easier to manage and update the list of possible statuses.

from enum import Enum

class Status(Enum):
    IDENTIFY_INDEX = "Identify Index"

state["status"] = Status.IDENTIFY_INDEX

import { ChatRequestOptions } from "ai";
import { v4 as uuidv4 } from "uuid";

export interface ChatProps {
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider grouping related props to improve maintainability

The ChatProps interface has many properties. Consider grouping related props into sub-objects (e.g., messageProps, inputProps) to improve readability and maintainability. This could make the component easier to use and understand.

export interface ChatProps {
  messageProps: {
    chatId?: string;
    // other message-related props
  };
  inputProps: {
    setSelectedModel: React.Dispatch<React.SetStateAction<string>>;
    // other input-related props
  };
}

'./src/**/*.{ts,tsx}',
],
prefix: "",
theme: {
Copy link

Choose a reason for hiding this comment

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

suggestion: Optimize color definitions using Tailwind's opacity modifiers

There's repetition in color definitions. Consider using Tailwind's color opacity modifiers (e.g., 'primary/80' for 80% opacity) to reduce repetition and make the config more maintainable.

  theme: {
    extend: {
      colors: {
        primary: {
          DEFAULT: '#3490dc',
          '80': 'rgba(52, 144, 220, 0.8)',
          '60': 'rgba(52, 144, 220, 0.6)',
          '40': 'rgba(52, 144, 220, 0.4)',
          '20': 'rgba(52, 144, 220, 0.2)',
        },
      },
    },
    container: {


return (
<div className="relative my-4 overflow-scroll overflow-x-scroll flex flex-col text-start ">
<Button
Copy link

Choose a reason for hiding this comment

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

suggestion: Enhance accessibility of the copy button

Add an aria-label to the copy button to improve accessibility. For example: aria-label="Copy code to clipboard". Also, consider using a more robust solution for managing the copied state, such as a custom hook, instead of setTimeout.

      <Button
        onClick={copyToClipboard}
        variant="ghost"
        aria-label="Copy code to clipboard"

Comment on lines +207 to +212
for entity in entities:
assert (
(entity["scientific_name"].lower() in [x.lower() for x in expected_entities])
or (entity["singular_form"].lower() in [x.lower() for x in expected_entities])
or (entity["plural_form"].lower() in [x.lower() for x in expected_entities])
)
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid loops in tests. (no-loop-in-tests)

ExplanationAvoid complex code, like loops, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +231 to +232
if expected_rank is None:
pytest.skip("No expected rank for this test case")
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +277 to +278
if expected_attribute is None:
pytest.skip("No expected attribute for this test case")
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +309 to +310
if expected_time_from is None and expected_time_to is None:
pytest.skip("No expected time for this test case")
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +344 to +345
if expected_attribute is None or expected_attribute_condition is None:
pytest.skip("No expected attribute for this test case")
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Copy link
Contributor

@rjchallis rjchallis left a comment

Choose a reason for hiding this comment

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

Looking good - a couple of thoughts:

  • It would be great to have a bit of text with the GoaT link - even with the larger font it is still quite hard to spot. An alternative would be to return the link after the explanation so it stays closer to the text box that the user will be focussed on.
  • the models in the ui portion, it seems to need llama2 - is there a way to have this use llama3.1
  • Running this locally I'm having trouble asking questions about the returned result - have you pushed that feature yet?

INSTALL.md Show resolved Hide resolved
src/app.py Outdated Show resolved Hide resolved
ui/ollama-nextjs-ui.gif Outdated Show resolved Hide resolved
ui/public/user.jpg Outdated Show resolved Hide resolved
ui/src/utils/initial-questions.ts Outdated Show resolved Hide resolved
@deepnayak
Copy link
Collaborator Author

Looking good - a couple of thoughts:

  • It would be great to have a bit of text with the GoaT link - even with the larger font it is still quite hard to spot. An alternative would be to return the link after the explanation so it stays closer to the text box that the user will be focussed on.
  • the models in the ui portion, it seems to need llama2 - is there a way to have this use llama3.1
  • Running this locally I'm having trouble asking questions about the returned result - have you pushed that feature yet?
  1. Makes sense, I will push this fix
  2. This actually depends on the model downloaded locally. Basically the UI application makes a GET request to /api/tags which is an OLLAMA endpoint that returns the locally available models.
  3. I have already pushed the change, but I had modified the API response JSON to remove unwanted content, maybe it is cutting out important content. Can you please tell me which queries you were facing issues with? I can try to recreate it locally and check

@rjchallis
Copy link
Contributor

  1. I have already pushed the change, but I had modified the API response JSON to remove unwanted content, maybe it is cutting out important content. Can you please tell me which queries you were facing issues with? I can try to recreate it locally and check

Querying the JSON context is working well now I have the models sorted out

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.

2 participants