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

feat: Cache generated responses #336

Merged
merged 5 commits into from
May 27, 2024
Merged

feat: Cache generated responses #336

merged 5 commits into from
May 27, 2024

Conversation

whiterabbit1983
Copy link
Contributor

@whiterabbit1983 whiterabbit1983 commented May 18, 2024

Closes #325

🚀 This description was created by Ellipsis for commit 0529b48

Summary:

Introduces caching for generated responses in the agents-api, including new utility functions, a caching decorator, a database migration for cache storage, and a new dependency.

Key points:

  • Added get_cached_response and set_cached_response functions in /agents-api/agents_api/models/session/ for caching.
  • Implemented cache decorator in /agents-api/agents_api/routers/sessions/session.py to enable caching for the generate method.
  • Created migration script /agents-api/migrations/migrate_1716013793_session_cache.py for session_cache table.
  • Added xxhash dependency in pyproject.toml for generating cache keys.

Generated with ❤️ by ellipsis.dev


🚀 This description was created by Ellipsis for commit ee589df

Summary:

Enhances the agents-api by introducing caching for generated responses, improving performance and efficiency.

Key points:

  • Introduces caching for generated responses in the agents-api to enhance performance and efficiency.
  • Added caching utility functions get_cached_response and set_cached_response in /agents-api/agents_api/models/session/
  • Implemented cache decorator in /agents-api/agents_api/routers/sessions/session.py for the generate method
  • Created migration script /agents-api/migrations/migrate_1716013793_session_cache.py for session_cache table
  • Added xxhash dependency in pyproject.toml for cache keys

Generated with ❤️ by ellipsis.dev

Copy link
Contributor

sweep-ai bot commented May 18, 2024

Sweep: PR Review

agents-api/agents_api/models/session/get_cached_response.py

Introduced a new function get_cached_response to query a session cache using a provided key, and added the necessary import for the cozo_query decorator.

Sweep Found These Issues

  • The function get_cached_response does not handle the case where the key is not found in the session_cache, which could lead to unexpected behavior or errors.
  • def get_cached_response(key: str) -> tuple[str, dict]:
    query = """
    input[key] <- [[$key]]
    ?[key, value] := input[key], *session_cache{key, value}
    """
    return (query, {"key": key})

    View Diff


agents-api/agents_api/models/session/set_cached_response.py

Introduced a new function set_cached_response to cache key-value pairs in a session_cache.

Sweep Found These Issues

  • The function does not handle potential exceptions that may occur during the query execution, which could lead to unhandled errors.
  • def set_cached_response(key: str, value: dict) -> tuple[str, dict]:
    query = """
    ?[key, value] <- [[$key, $value]]
    :insert session_cache {
    key => value
    }
    :returning
    """
    return (query, {"key": key, "value": value})

    View Diff

Potential Issues

Sweep isn't 100% sure if the following are issues or not but they may be worth taking a look at.

  • The function does not validate the input parameters key and value, which could lead to unexpected behavior or security vulnerabilities if invalid data is passed.
  • def set_cached_response(key: str, value: dict) -> tuple[str, dict]:
    query = """
    ?[key, value] <- [[$key, $value]]
    :insert session_cache {
    key => value
    }
    :returning
    """
    return (query, {"key": key, "value": value})

    View Diff

  • The function does not validate the input parameters key and value, which could lead to unexpected behavior or security vulnerabilities if invalid data is passed.
  • def set_cached_response(key: str, value: dict) -> tuple[str, dict]:
    query = """
    ?[key, value] <- [[$key, $value]]
    :insert session_cache {
    key => value
    }
    :returning
    """
    return (query, {"key": key, "value": value})

    View Diff


agents-api/agents_api/routers/sessions/session.py

The changes introduce a caching mechanism using the xxhash library and new functions to store and retrieve cached responses, applied to the generate method of the BaseSession class.

Potential Issues

Sweep isn't 100% sure if the following are issues or not but they may be worth taking a look at.


agents-api/migrations/migrate_1716013793_session_cache.py

The changes introduce a new migration script to create and remove a "session_cache" table with key-value pairs.

Sweep Found These Issues


The following files were not reviewed because our filter identified them as typically non-human-readable or less important files (e.g., dist files, package.json, images). If this is an error, please let us know.

  • agents-api/poetry.lock
  • agents-api/pyproject.toml

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 0529b48 in 2 minutes and 9 seconds

More details
  • Looked at 161 lines of code in 5 files
  • Skipped 1 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_ALt1hiVDIV7A4xm9


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.

@creatorrr creatorrr enabled auto-merge (squash) May 21, 2024 02:08
@creatorrr
Copy link
Contributor

Lgtm

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 857d22f in 3 minutes and 34 seconds

More details
  • Looked at 68 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_ZLFLTaEafTaSQgCz


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.

agents-api/agents_api/routers/sessions/session.py Outdated Show resolved Hide resolved
agents-api/agents_api/routers/sessions/session.py Outdated Show resolved Hide resolved
agents-api/agents_api/routers/sessions/session.py Outdated Show resolved Hide resolved
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 5e36e05 in 2 minutes and 2 seconds

More details
  • Looked at 27 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_gr0rbaliEjp36YPY


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.

@creatorrr creatorrr merged commit c908e3a into dev May 27, 2024
7 of 9 checks passed
@creatorrr creatorrr deleted the f/session-cache branch May 27, 2024 14:54
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 ee589df in 3 minutes and 48 seconds

More details
  • Looked at 49 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_h0z5NvAESTETn6uH


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

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.

Add a xxhash based cache
3 participants