-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: spotlight
Are you sure you want to change the base?
Spotlight api #109
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe 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 Changes
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
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this 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
andopenai
, 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 withworkspace_id
anduser_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 dynamicworkspace_id
anduser_id
values.The changes are approved.
However, the
workspace_id
anduser_id
values are hardcoded when creating a newQuery
. 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
orraise ... 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 errTools
Ruff
51-51: Within an
except
clause, raise exceptions withraise ... from err
orraise ... 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
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 unusedRemove unused import:
django.test.TestCase
(F401)
apps/spotlight/admin.py
1-1:
django.contrib.admin
imported but unusedRemove unused import:
django.contrib.admin
(F401)
apps/spotlight/llm.py
51-51: Within an
except
clause, raise exceptions withraise ... from err
orraise ... 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 thequery
field from theQuery
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
andmappings
apps toINSTALLED_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
andDEFAULT_AUTHENTICATION_CLASSES
settings inREST_FRAMEWORK
have been commented out. This change might have implications on the API's security and access control.Please verify the following:
- What is the reason for commenting out these settings?
- How will authentication and permissions be handled after this change?
- 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:
- The prompt provides clear instructions for the assistant to interpret user queries and provide relevant suggestions in a JSON format.
- It includes a range of predefined actions, navigations, and help suggestions covering relevant topics related to expense management and integrations.
- The examples provided are helpful in guiding the assistant's responses based on different types of user queries.
- 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
fromdjango.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 unusedRemove unused import:
django.test.TestCase
(F401)
apps/spotlight/admin.py (1)
1-3: Remove the unused import.
The file imports
admin
fromdjango.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 unusedRemove unused import:
django.contrib.admin
(F401)
|
|
|
|
|
|
|
|
|
|
|
Summary by CodeRabbit
New Features
Query
model to store user queries in the database.Bug Fixes
Documentation
Chores