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

Spotlight api #109

Open
wants to merge 20 commits into
base: spotlight
Choose a base branch
from
Open

Spotlight api #109

wants to merge 20 commits into from

Conversation

shreyanshs7
Copy link
Contributor

@shreyanshs7 shreyanshs7 commented Sep 10, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a Django admin interface for future model management.
    • Added a configuration class for the 'spotlight' application.
    • Implemented integration with OpenAI and AWS Bedrock for advanced AI response generation.
    • Created a new Query model to store user queries in the database.
    • Established API views for managing and retrieving recent queries.
    • Introduced structured prompts for AI interactions to enhance user experience.
  • Bug Fixes

    • Improved error handling for AI response generation functions.
  • Documentation

    • Updated environment variables in the configuration template for better service integration.
  • Chores

    • Added new dependencies for AWS and OpenAI integration.

@shreyanshs7 shreyanshs7 changed the base branch from master to spotlight September 10, 2024 17:34
Copy link

coderabbitai bot commented Sep 10, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces a new Django application named "spotlight," which includes various components such as models, views, serializers, and services. Key features include the implementation of a Query model for storing user queries, integration with OpenAI and AWS Bedrock for AI responses, and the establishment of API endpoints for querying and retrieving recent queries. Additionally, the configuration files have been updated to support new dependencies and environment variables, enhancing the application's capabilities and modularity.

Changes

Files Change Summary
apps/spotlight/admin.py, apps/spotlight/apps.py, apps/spotlight/models.py, apps/spotlight/migrations/0001_initial.py, apps/spotlight/serializers.py, apps/spotlight/llm.py, apps/spotlight/service.py, apps/spotlight/views.py, apps/spotlight/urls.py, apps/spotlight/prompts/*.py Introduced new files and classes for managing queries, integrating AI services, and defining prompts. Added a Query model with relevant fields and relationships.
docker-compose.yml.template Added new environment variables for AWS and OpenAI integration.
quickbooks_desktop_api/settings.py Added apps.spotlight to INSTALLED_APPS and commented out existing permission and authentication classes.
quickbooks_desktop_api/urls.py Added a new URL pattern for the spotlight API.
requirements.txt Added new dependencies: boto3 and openai.
apps/spotlight/tests.py Created a placeholder for future test cases.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant QueryView
    participant QueryService
    participant LLM
    participant Database

    User->>QueryView: POST /query
    QueryView->>QueryService: get_suggestions(user_query)
    QueryService->>LLM: get_openai_response(system_prompt)
    LLM-->>QueryService: AI response
    QueryService->>Database: Create new Query instance
    Database-->>QueryService: Confirmation
    QueryService-->>QueryView: Return suggestions
    QueryView-->>User: JSON response with suggestions
Loading

🐰 In the spotlight, bright and clear,
New queries hop, bringing cheer!
With AI friends, they take their flight,
Guiding users, day and night.
A world of prompts, so vast and grand,
Together we’ll explore this land! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 8.915s ⏱️

Copy link

@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.

Caution

Inline review comments failed to post

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (6)
apps/spotlight/models.py (1)

9-23: LGTM!

The Query model is well-defined with appropriate fields, help texts, and foreign key relationships.

Consider adding an index on the workspace_id field if you anticipate a high volume of queries filtering by this field. This can improve the query performance.

You can add the index by modifying the field definition like this:

workspace_id = models.IntegerField(help_text="Workspace id of the organization", db_index=True)
requirements.txt (1)

1-3: LGTM!

The new dependencies, boto3 and openai, are added correctly and pinned to specific versions, which is a good practice.

Consider adding a brief comment above each dependency or group of dependencies to indicate their purpose. This can make the requirements.txt file more maintainable and easier to understand for other developers.

For example:

# AWS SDK for Python
boto3==1.35.14

# OpenAI API client
openai==1.44.0
apps/spotlight/views.py (2)

31-55: LGTM, but use dynamic filter values.

The changes are approved.

However, the filters dictionary is hardcoded with workspace_id and user_id values. Instead, use dynamic values based on the authenticated user and workspace to ensure that the correct queries are returned for each user and workspace.


58-71: LGTM, but use dynamic workspace_id and user_id values.

The changes are approved.

However, the workspace_id and user_id values are hardcoded when creating a new Query. Instead, use dynamic values based on the authenticated user and workspace to ensure that the query is associated with the correct user and workspace.

apps/spotlight/llm.py (2)

29-51: LGTM, but update the exception raising syntax.

The changes are approved.

However, the static analysis tool Ruff suggests using raise ... from err or raise ... from None to distinguish the exception from errors in exception handling.

Apply this diff to update the exception raising syntax:

-    except (openai.OpenAIError, json.JSONDecodeError) as e:
-        raise Exception(message=str(e))
+    except (openai.OpenAIError, json.JSONDecodeError) as err:
+        raise Exception(message=str(err)) from err
Tools
Ruff

51-51: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


55-96: LGTM, but raise an exception instead of printing the error.

The changes are approved.

However, the function prints the error if there is a JSON decoding error. Instead, raise an exception to propagate the error to the calling code and handle it appropriately.

Apply this diff to raise an exception instead of printing the error:

-    except json.JSONDecodeError as e:
-        print(e)
+    except json.JSONDecodeError as err:
+        raise Exception(message=str(err)) from err
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 96fee28 and 8a7a375.

Files selected for processing (16)
  • apps/spotlight/admin.py (1 hunks)
  • apps/spotlight/apps.py (1 hunks)
  • apps/spotlight/llm.py (1 hunks)
  • apps/spotlight/migrations/0001_initial.py (1 hunks)
  • apps/spotlight/models.py (1 hunks)
  • apps/spotlight/prompts/spotlight_prompt.py (1 hunks)
  • apps/spotlight/prompts/support_genie.py (1 hunks)
  • apps/spotlight/serializers.py (1 hunks)
  • apps/spotlight/service.py (1 hunks)
  • apps/spotlight/tests.py (1 hunks)
  • apps/spotlight/urls.py (1 hunks)
  • apps/spotlight/views.py (1 hunks)
  • docker-compose.yml.template (1 hunks)
  • quickbooks_desktop_api/settings.py (2 hunks)
  • quickbooks_desktop_api/urls.py (1 hunks)
  • requirements.txt (1 hunks)
Files skipped from review due to trivial changes (2)
  • apps/spotlight/apps.py
  • apps/spotlight/prompts/support_genie.py
Additional context used
Ruff
apps/spotlight/tests.py

1-1: django.test.TestCase imported but unused

Remove unused import: django.test.TestCase

(F401)

apps/spotlight/admin.py

1-1: django.contrib.admin imported but unused

Remove unused import: django.contrib.admin

(F401)

apps/spotlight/llm.py

51-51: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

Additional comments not posted (10)
apps/spotlight/serializers.py (1)

1-9: LGTM!

The QuerySerializer looks good and serializes the query field from the Query model.

quickbooks_desktop_api/urls.py (1)

22-22: LGTM!

The new URL pattern for the /api/spotlight/ path is added correctly and follows the existing pattern of mapping API paths to their respective app's URLs module.

apps/spotlight/urls.py (1)

1-24: LGTM!

The code changes are approved.

apps/spotlight/migrations/0001_initial.py (1)

1-32: LGTM!

The code changes are approved.

apps/spotlight/service.py (2)

7-36: LGTM!

The code changes are approved.


38-44: LGTM!

The code changes are approved.

docker-compose.yml.template (1)

28-32: Reminder: Populate the environment variable values before deployment.

The following environment variables have been added with empty values:

  • AWS_REGION
  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • OPENAI_API_KEY
  • KNOWLEDGE_BASE_ID

Ensure that these values are populated with the correct credentials before deploying the application. Do not commit the populated values to version control.

quickbooks_desktop_api/settings.py (2)

62-63: LGTM!

The addition of the spotlight and mappings apps to INSTALLED_APPS is necessary for Django to recognize and use these newly created apps.


109-115: Verify the impact and reasoning for commenting out the authentication and permission settings.

The DEFAULT_PERMISSION_CLASSES and DEFAULT_AUTHENTICATION_CLASSES settings in REST_FRAMEWORK have been commented out. This change might have implications on the API's security and access control.

Please verify the following:

  1. What is the reason for commenting out these settings?
  2. How will authentication and permissions be handled after this change?
  3. Have the potential security risks been considered and addressed?
apps/spotlight/prompts/spotlight_prompt.py (1)

1-408: LGTM!

The PROMPT string is a well-structured and comprehensive prompt template for the AI assistant. Here are some positive aspects:

  1. The prompt provides clear instructions for the assistant to interpret user queries and provide relevant suggestions in a JSON format.
  2. It includes a range of predefined actions, navigations, and help suggestions covering relevant topics related to expense management and integrations.
  3. The examples provided are helpful in guiding the assistant's responses based on different types of user queries.
  4. The JSON format specified for the output ensures a consistent and machine-readable structure for the suggestions.

Overall, the prompt template is well-designed and should effectively guide the AI assistant in providing helpful suggestions to users.

Comments failed to post (2)
apps/spotlight/tests.py (1)

1-3: Remove the unused import and add tests.

The file imports TestCase from django.test but does not use it.

Remove the unused import:

-from django.test import TestCase
-
-# Create your tests here.
+# Create your tests here.

Also, consider adding tests for the spotlight app to ensure it functions as expected.

Do you want me to generate the test code or open a GitHub issue to track this task?

Committable suggestion was skipped due to low confidence.

Tools
Ruff

1-1: django.test.TestCase imported but unused

Remove unused import: django.test.TestCase

(F401)

apps/spotlight/admin.py (1)

1-3: Remove the unused import.

The file imports admin from django.contrib but does not use it.

Remove the unused import:

-from django.contrib import admin
-
-# Register your models here.
+# Register your models here.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

# Register your models here.
Tools
Ruff

1-1: django.contrib.admin imported but unused

Remove unused import: django.contrib.admin

(F401)

Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 8.946s ⏱️

Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 9.286s ⏱️

Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 9.159s ⏱️

Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 9.647s ⏱️

@shreyanshs7 shreyanshs7 added the deploy Triggers deployment of active branch to Staging label Sep 12, 2024
Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 9.780s ⏱️

Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 9.145s ⏱️

Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 9.417s ⏱️

Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 9.604s ⏱️

Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 9.521s ⏱️

Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 9.722s ⏱️

@Ashutosh619-sudo Ashutosh619-sudo added deploy Triggers deployment of active branch to Staging and removed deploy Triggers deployment of active branch to Staging labels Sep 12, 2024
Copy link

Tests Skipped Failures Errors Time
60 0 💤 16 ❌ 0 🔥 9.751s ⏱️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy Triggers deployment of active branch to Staging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants