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

improve css & svg caching #1278

Merged
merged 2 commits into from
Nov 27, 2024
Merged

improve css & svg caching #1278

merged 2 commits into from
Nov 27, 2024

Conversation

wintonzheng
Copy link
Contributor

@wintonzheng wintonzheng commented Nov 27, 2024

Important

Improves CSS and SVG caching with retry logic, error handling, and flexible expiration in redis.py, agent_functions.py, and base.py.

  • Caching Improvements:
    • RedisCache.set() and BaseCache.set() now accept an optional expiration parameter ex.
  • SVG and CSS Conversion:
    • Added retry logic for _convert_svg_to_string() and _convert_css_shape_to_string() in agent_functions.py.
    • Introduced SVG_SHAPE_CONVERTION_ATTEMPTS and CSS_SHAPE_CONVERTION_ATTEMPTS constants for retry limits.
    • Caches invalid shapes with a short expiration to prevent immediate retries.
  • Error Handling:
    • Handles LLMProviderError specifically in conversion functions in agent_functions.py.
    • Logs detailed error information and retries after a delay.

This description was created by Ellipsis for b9f558f. It will automatically update as commits are pushed.

<!-- ELLIPSIS_HIDDEN -->

> [!IMPORTANT]
> Improves CSS and SVG caching with retry logic, error handling, and flexible expiration in `redis.py`, `agent_functions.py`, and `base.py`.
>
>   - **Caching Improvements**:
>     - `RedisCache.set()` in `redis.py` and `BaseCache.set()` in `base.py` now accept an optional expiration parameter `ex`.
>   - **SVG and CSS Conversion**:
>     - Added retry logic for `_convert_svg_to_string()` and `_convert_css_shape_to_string()` in `agent_functions.py`.
>     - Introduced `SVG_SHAPE_CONVERTION_ATTEMPTS` and `CSS_SHAPE_CONVERTION_ATTEMPTS` constants for retry limits.
>     - Caches invalid shapes with a short expiration to prevent immediate retries.
>   - **Error Handling**:
>     - Handles `LLMProviderError` specifically in conversion functions in `agent_functions.py`.
>     - Logs detailed error information and retries after a delay.
>
> <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=Skyvern-AI%2Fskyvern-cloud&utm_source=github&utm_medium=referral)<sup> for 705326aee2c4da6c2804ba0dff6d1008eba91cbe. It will automatically update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->
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 17ba333 in 48 seconds

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

Workflow ID: wflow_YyEBfmEzgjZSol7I


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.

@@ -16,5 +17,5 @@ async def get(self, key: str) -> Any:
await self.set(key, value)
return value

async def set(self, key: str, value: Any) -> None:
async def set(self, key: str, value: Any, ex: Union[int, timedelta, None] = CACHE_EXPIRE_TIME) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

The set method does not utilize the ex parameter for setting expiration times. Consider using ex to set the TTL for each cache entry, ensuring consistent expiration behavior.

@@ -167,6 +184,9 @@ async def _convert_svg_to_string(
element_id=element_id,
retry=retry,
)
if retry == CSS_SHAPE_CONVERTION_ATTEMPTS - 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

The retry logic for Exception in _convert_svg_to_string uses CSS_SHAPE_CONVERTION_ATTEMPTS instead of SVG_SHAPE_CONVERTION_ATTEMPTS. This seems incorrect and should be corrected for consistency.

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 17ba333 in 2 minutes and 3 seconds

More details
  • Looked at 170 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. skyvern/forge/agent_functions.py:187
  • Draft comment:
    The retry logic for caching invalid shapes is inconsistent. In _convert_svg_to_string, the cache expiration is set to 1 week for general exceptions, while in _convert_css_shape_to_string, it's set to 1 hour. Consider making these consistent.
  • Reason this comment was not posted:
    Comment was on unchanged code.
2. skyvern/forge/agent_functions.py:302
  • Draft comment:
    The retry logic for caching invalid shapes is inconsistent. In _convert_svg_to_string, the cache expiration is set to 1 week for general exceptions, while in _convert_css_shape_to_string, it's set to 1 hour. Consider making these consistent.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_1xiRgP52wQJiDljf


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.

@@ -16,5 +17,5 @@ async def get(self, key: str) -> Any:
await self.set(key, value)
return value

async def set(self, key: str, value: Any) -> None:
async def set(self, key: str, value: Any, ex: Union[int, timedelta, None] = CACHE_EXPIRE_TIME) -> None:
self.cache[key] = value
Copy link
Contributor

Choose a reason for hiding this comment

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

The set method does not utilize the ex parameter for setting expiration times. Consider using ex to set the TTL for each cache entry.

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 b9f558f in 16 seconds

More details
  • Looked at 13 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. skyvern/forge/agent_functions.py:189
  • Draft comment:
    The expiration time for caching invalid shapes is inconsistent between SVG and CSS conversion functions. Consider using timedelta(hours=1) for both to maintain consistency.
  • Reason this comment was not posted:
    Comment was not on a valid diff hunk.

Workflow ID: wflow_TZQLoOHCG8BaAeng


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

@wintonzheng wintonzheng merged commit 0083692 into main Nov 27, 2024
2 checks passed
@wintonzheng wintonzheng deleted the shu/make_redis_ex_an_param branch November 27, 2024 22:54
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.

1 participant