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

use cached prompt generation #768

Merged
merged 2 commits into from
Sep 3, 2024
Merged

use cached prompt generation #768

merged 2 commits into from
Sep 3, 2024

Conversation

ykeremy
Copy link
Contributor

@ykeremy ykeremy commented Sep 3, 2024

🚀 This description was created by Ellipsis for commit 36863f0

Summary:

This PR implements caching for task generation using user prompt hashes, updating models, routes, schemas, and includes a specific Alembic migration script for schema changes.

Key points:

  • Implements caching for task generation using user prompt hashes.
  • Adds user_prompt_hash and source_task_generation_id to TaskGenerationModel in skyvern/forge/sdk/db/models.py.
  • Updates AgentDB in skyvern/forge/sdk/db/client.py to handle cached task generations.
  • Modifies /generate/task route in skyvern/forge/sdk/routes/agent_protocol.py to check cache before generating tasks.
  • Introduces PROMPT_CACHE_WINDOW_HOURS in skyvern/config.py for cache duration control.
  • Updates skyvern/forge/sdk/schemas/task_generations.py to include user_prompt_hash in TaskGeneration class.
  • Includes Alembic migration script alembic/versions/2024_09_03_0356-0de9150bc624_update_task_generation_table_use_user_.py for database schema update.

Generated with ❤️ by ellipsis.dev

<!-- ELLIPSIS_HIDDEN -->

| 🚀 | This description was created by [Ellipsis](https://www.ellipsis.dev) for commit 35c5b0690e2a719346c9e241e9244349818af3f6  |
|--------|--------|

### Summary:
This PR implements caching for task generation using user prompt hashes, updating models, routes, and schemas for efficiency.

**Key points**:
- Implements caching for task generation using user prompt hashes.
- Adds `user_prompt_hash` and `source_task_generation_id` to `TaskGenerationModel`.
- Updates `AgentDB` to handle cached task generations.
- Modifies `/generate/task` route to check cache before generating tasks.
- Introduces `PROMPT_CACHE_WINDOW_HOURS` for cache duration control.
- Updates `skyvern/forge/sdk/schemas/task_generations.py` to include `user_prompt_hash` in `TaskGeneration` class.
- Includes Alembic migration script for database schema update.

----
Generated with ❤️ by [ellipsis.dev](https://www.ellipsis.dev)

<!-- ELLIPSIS_HIDDEN -->
@ykeremy ykeremy added the sync label Sep 3, 2024
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to ff66020 in 25 seconds

More details
  • Looked at 212 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. skyvern/forge/sdk/db/client.py:1426
  • Draft comment:
    The default value for query_window_hours should be settings.PROMPT_CACHE_WINDOW_HOURS instead of settings.PROMPT_ACTION_HISTORY_WINDOW.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment is about a change made in the diff, specifically the default value of a parameter in a new method. The comment suggests a specific change, which is actionable. However, I need to consider if the suggested change is necessary or if the current default value is appropriate.
    I might be missing the context of why settings.PROMPT_ACTION_HISTORY_WINDOW was chosen as the default. The current default might be intentional and changing it could affect the functionality. Without additional context, it's hard to determine if the suggested change is necessary.
    The comment is actionable and specific, suggesting a change to a default value. Even if the current default is intentional, the comment highlights a potential oversight that should be considered.
    Keep the comment as it is specific to a change made in the diff and suggests an actionable improvement.

Workflow ID: wflow_qTbWeajD7b71DQh2


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@@ -54,6 +55,7 @@
base_router = APIRouter()

LOG = structlog.get_logger()
PROMPT_CACHE_WINDOW_HOURS = 24
Copy link
Contributor

Choose a reason for hiding this comment

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

PROMPT_CACHE_WINDOW_HOURS is already defined in config.py. Consider importing it from there instead of redefining it.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Incremental review on ff66020 in 45 seconds

More details
  • Looked at 211 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. skyvern/forge/sdk/db/client.py:1426
  • Draft comment:
    PROMPT_ACTION_HISTORY_WINDOW is not defined in the provided code. Consider using PROMPT_CACHE_WINDOW_HOURS from skyvern/config.py instead.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment is speculative and assumes a lack of definition for PROMPT_ACTION_HISTORY_WINDOW without evidence. The import of settings suggests that PROMPT_ACTION_HISTORY_WINDOW could be defined there. The comment does not provide actionable feedback based on the diff alone.
    I might be overlooking the possibility that PROMPT_ACTION_HISTORY_WINDOW is indeed undefined in settings, but the comment does not provide evidence for this claim.
    Even if PROMPT_ACTION_HISTORY_WINDOW is undefined, the comment should provide evidence or context to support its claim. Without this, it remains speculative.
    The comment is speculative and not based on evidence from the diff. It should be removed as it does not provide actionable feedback.

Workflow ID: wflow_Imr5sIGXXrYiMbrx


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

# check if there's a same user_prompt within the past x Hours
# in the future, we can use vector db to fetch similar prompts
existing_task_generation = await app.DATABASE.get_task_generation_by_prompt_hash(
user_prompt_hash=user_prompt_hash, query_window_hours=PROMPT_CACHE_WINDOW_HOURS
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using settings.PROMPT_CACHE_WINDOW_HOURS instead of the hardcoded value 24 for consistency and maintainability.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot 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 to me! Incremental review on 36863f0 in 18 seconds

More details
  • Looked at 52 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. alembic/versions/2024_09_03_0356-0de9150bc624_update_task_generation_table_use_user_.py:24
  • Draft comment:
    Consider adding a step to handle existing data for the new columns user_prompt_hash and source_task_generation_id. This could involve setting default values or updating existing rows to prevent issues if these columns are expected to be non-nullable in the application logic.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment is about a potential issue with the new columns being nullable. If the application logic requires non-null values, this could be a valid concern. However, the migration itself doesn't enforce non-null constraints, so the comment might be speculative.
    The comment might be speculative since it assumes application logic requirements that aren't enforced by the migration. The migration allows null values, so existing data won't cause schema issues.
    Even though the migration allows null values, the comment could be useful if the application logic requires non-null values, which isn't clear from the migration alone.
    The comment is speculative about application logic requirements, but it could be useful if non-null values are required. However, based on the rules, speculative comments should be removed.

Workflow ID: wflow_CXWonUP8ApVDo1bS


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@wintonzheng wintonzheng merged commit 0d39e62 into main Sep 3, 2024
2 checks passed
@wintonzheng wintonzheng deleted the shu/cache_prompt branch September 3, 2024 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants