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

chore(wren-ai-service): minor-updates #1265

Merged
merged 5 commits into from
Feb 5, 2025
Merged

Conversation

cyyeh
Copy link
Member

@cyyeh cyyeh commented Feb 5, 2025

  • return sql generation error(syntax error, timeout, etc.)
  • allow setting engine_timeout in config.yaml
  • remove unused engine in sql_answer pipeline
  • skip sql correction if it's post-process timeout error

Summary by CodeRabbit

  • New Features
    • Introduced a configurable 30-second timeout for engine and SQL operations, ensuring more consistent execution across generation, correction, expansion, and retrieval processes.
    • Enhanced error messaging during SQL processing for clearer feedback.
    • Updated model configurations with refined parameters for improved performance.
    • Streamlined SQL answer processing by simplifying engine references for more efficient operation.

@cyyeh cyyeh added module/ai-service ai-service related ci/ai-service ai-service related labels Feb 5, 2025
Copy link
Contributor

coderabbitai bot commented Feb 5, 2025

Warning

Rate limit exceeded

@cyyeh has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 55 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 1135fc7 and 5d32919.

📒 Files selected for processing (1)
  • wren-ai-service/src/web/v1/services/sql_expansion.py (3 hunks)

Walkthrough

The changes systematically add an engine_timeout parameter (default value 30) to configuration files, service classes, and pipeline functions. Modifications span configuration updates, method signature changes, and revisions to error handling in SQL processing. The updates remove an explicit engine reference in certain pipelines and integrate timeout handling across service initialization and SQL execution flows.

Changes

File(s) Summary of Changes
deployment/kustomizations/base/cm.yaml, docker/config.example.yaml, wren-ai-service/tools/config/…/config.example.yaml, wren-ai-service/tools/config/…/config.full.yaml Added new setting engine_timeout: 30; removed explicit engine reference for sql_answer; updated model configurations and comments.
wren-ai-service/src/config.py, wren-ai-service/src/globals.py Introduced engine_timeout attribute in the Settings class and passed it to service initializations.
wren-ai-service/src/pipelines/generation/… (files: followup_sql_generation.py, relationship_recommendation.py, sql_breakdown.py, sql_correction.py, sql_expansion.py, sql_generation.py) Added optional engine_timeout parameter (default 30.0) to constructors and post_process methods; updated error handling in SQL pipeline flows.
wren-ai-service/src/pipelines/utils/sql.py, wren-ai-service/src/pipelines/retrieval/sql_executor.py Introduced timeout/engine_timeout parameters to run methods and SQL execution functions for configurable query timeouts.
wren-ai-service/src/web/v1/services/ask.py, ask_details.py, sql_expansion.py Consolidated error handling by integrating error message management; removed redundant dry-run filtering methods.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant AskService
    participant Pipeline
    participant PostProcessor
    participant Engine

    Client->>AskService: Send SQL request
    AskService->>Pipeline: Invoke pipeline with engine_timeout=30
    Pipeline->>PostProcessor: Call run(timeout=30)
    PostProcessor->>Engine: Execute SQL with timeout=30
    Engine-->>PostProcessor: Return result or error message
    PostProcessor-->>Pipeline: Return processed data
    Pipeline-->>AskService: Deliver final output
    AskService-->>Client: Send response
Loading

Possibly related PRs

Suggested reviewers

  • paopa

Poem

In a verdant field of code I bound,
Engine timeouts now in place and sound.
With thirty ticks, each query takes its flight,
Errors and delays now vanish from sight.
Hoping through pipelines with joy so true,
This rabbit cheers the changes anew!
🐰


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@cyyeh cyyeh marked this pull request as ready for review February 5, 2025 06:14
Copy link
Contributor

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
wren-ai-service/src/core/engine.py (2)

53-53: Update function docstring to reflect new return type.

The function's return type has changed from Tuple[str, bool] to Tuple[str, str], but this isn't documented.

Add a docstring explaining the return values:

 def add_quotes(sql: str) -> Tuple[str, str]:
+    """Add quotes to SQL identifiers.
+    
+    Args:
+        sql: SQL query string
+    
+    Returns:
+        Tuple[str, str]: (quoted_sql, error_message)
+        - If successful: (quoted_sql, "")
+        - If failed: ("", error_message)
+    """

61-63: Consider using None for success case instead of empty string.

Using an empty string to indicate success is less explicit than using None. This would make the success/failure states more distinguishable.

-    return "", str(e)
+    return None, str(e)

-    return quoted_sql, ""
+    return quoted_sql, None
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d35dae and 1135fc7.

📒 Files selected for processing (18)
  • deployment/kustomizations/base/cm.yaml (1 hunks)
  • docker/config.example.yaml (1 hunks)
  • wren-ai-service/src/config.py (1 hunks)
  • wren-ai-service/src/core/engine.py (1 hunks)
  • wren-ai-service/src/globals.py (8 hunks)
  • wren-ai-service/src/pipelines/generation/followup_sql_generation.py (5 hunks)
  • wren-ai-service/src/pipelines/generation/relationship_recommendation.py (4 hunks)
  • wren-ai-service/src/pipelines/generation/sql_breakdown.py (4 hunks)
  • wren-ai-service/src/pipelines/generation/sql_correction.py (5 hunks)
  • wren-ai-service/src/pipelines/generation/sql_expansion.py (5 hunks)
  • wren-ai-service/src/pipelines/generation/sql_generation.py (5 hunks)
  • wren-ai-service/src/pipelines/generation/utils/sql.py (9 hunks)
  • wren-ai-service/src/pipelines/retrieval/sql_executor.py (5 hunks)
  • wren-ai-service/src/web/v1/services/ask.py (3 hunks)
  • wren-ai-service/src/web/v1/services/ask_details.py (1 hunks)
  • wren-ai-service/src/web/v1/services/sql_expansion.py (3 hunks)
  • wren-ai-service/tools/config/config.example.yaml (1 hunks)
  • wren-ai-service/tools/config/config.full.yaml (1 hunks)
🔇 Additional comments (31)
wren-ai-service/src/config.py (1)

37-39: LGTM! Well-structured configuration addition.

The engine_timeout configuration is logically placed under a new "engine config" section with a reasonable default value.

wren-ai-service/src/core/engine.py (1)

55-57: LGTM! Enhanced error handling with sqlglot.

The addition of error_level=sqlglot.ErrorLevel.RAISE ensures consistent error handling.

wren-ai-service/src/pipelines/retrieval/sql_executor.py (2)

30-31: LGTM! Consistent timeout propagation.

The timeout parameter is properly propagated from DataFetcher to engine.execute_sql.

Also applies to: 39-40


69-70: LGTM! Well-structured configuration storage.

The engine_timeout is properly stored in _configs for use in pipeline execution.

Also applies to: 76-78

wren-ai-service/src/pipelines/generation/sql_correction.py (2)

82-92: LGTM! Enhanced post-processing with timeout.

The timeout parameter is properly integrated into the post-processing step.


114-115: LGTM! Consistent configuration pattern.

The engine_timeout configuration follows the same pattern as in SQLExecutor.

Also applies to: 128-131

wren-ai-service/src/pipelines/generation/sql_expansion.py (2)

75-85: LGTM! Timeout parameter correctly integrated.

The engine_timeout parameter is properly added to the post_process function and correctly passed to post_processor.run.


106-112: LGTM! Proper configuration handling.

The engine_timeout parameter is correctly added to the constructor with a sensible default value and properly stored in _configs.

Also applies to: 125-128

wren-ai-service/src/pipelines/generation/sql_generation.py (2)

94-104: LGTM! Timeout parameter correctly integrated.

The engine_timeout parameter is properly added to the post_process function and correctly passed to post_processor.run.


122-127: LGTM! Proper configuration handling.

The engine_timeout parameter is correctly added to the constructor with a sensible default value and properly stored in _configs.

Also applies to: 140-142

wren-ai-service/src/pipelines/generation/followup_sql_generation.py (2)

106-116: LGTM! Timeout parameter correctly integrated.

The engine_timeout parameter is properly added to the post_process function and correctly passed to post_processor.run.


134-139: LGTM! Proper configuration handling.

The engine_timeout parameter is correctly added to the constructor with a sensible default value and properly stored in _configs.

Also applies to: 152-154

wren-ai-service/src/web/v1/services/ask_details.py (1)

126-127: LGTM! Improved error handling.

The code now uses a more descriptive error_message instead of a boolean flag, providing better error context. The conditional logic correctly handles the error case by falling back to the original SQL when there's an error message.

wren-ai-service/src/pipelines/generation/sql_breakdown.py (3)

138-139: LGTM! The engine_timeout parameter is properly added to the post_process function.

The parameter is correctly passed to the post_processor.run method, enhancing timeout control for SQL processing.


176-177: LGTM! The engine_timeout parameter is properly added to the class constructor.

The default value of 30.0 seconds is reasonable for most SQL operations.


192-192: LGTM! The engine_timeout is properly stored in the configuration.

The timeout value is correctly added to the _configs dictionary for use during pipeline execution.

wren-ai-service/src/pipelines/generation/relationship_recommendation.py (2)

173-173: LGTM! The engine_timeout parameter is properly added to the class constructor.

The default value of 30.0 seconds aligns with other services.


185-187: LGTM! The engine_timeout is properly stored in the configuration.

The timeout value is correctly added to the _configs dictionary for use during pipeline execution.

wren-ai-service/src/web/v1/services/sql_expansion.py (1)

110-110: LGTM! Error handling is improved with better error message propagation.

The changes properly capture and propagate error messages from failed dry run results, enhancing error reporting.

Also applies to: 170-188, 208-209, 212-212

wren-ai-service/src/globals.py (1)

110-111: LGTM! The engine_timeout parameter is consistently added to all relevant services.

The timeout configuration is properly propagated to all SQL processing services, ensuring consistent timeout behavior across the application.

Also applies to: 117-118, 121-122, 134-135, 146-147, 161-162, 170-171, 187-188, 191-192, 219-220, 237-238

wren-ai-service/src/web/v1/services/ask.py (3)

144-144: LGTM! Added error message tracking.

The addition of the error_message variable improves error handling by capturing specific error messages from failed SQL generation attempts.


361-394: Improved error handling with timeout distinction.

The changes enhance error handling by:

  1. Distinguishing between timeout and other errors
  2. Skipping SQL correction for timeout errors
  3. Preserving error messages for better feedback

This aligns with the PR objective to improve SQL generation error handling.


415-415: Enhanced error reporting in response metadata.

The error message is now properly propagated to the response metadata, improving error visibility.

Also applies to: 422-422

wren-ai-service/src/pipelines/generation/utils/sql.py (2)

32-32: Added timeout parameter with sensible default.

The addition of the timeout parameter with a default value of 30.0 seconds aligns with the PR objective to support configurable engine timeouts.

Also applies to: 92-92


61-63: Properly propagated timeout parameter.

The timeout parameter is correctly propagated to the SQL execution methods, ensuring consistent timeout behavior throughout the pipeline.

Also applies to: 99-99

docker/config.example.yaml (1)

142-142: Added engine timeout configuration.

The addition of engine_timeout: 30 in settings provides the configurable timeout functionality mentioned in the PR objectives.

wren-ai-service/tools/config/config.full.yaml (1)

158-158: Consistent timeout configuration across files.

The engine_timeout: 30 setting is consistently defined across configuration files, ensuring uniform behavior.

wren-ai-service/tools/config/config.example.yaml (2)

98-99: SQL Answer Pipeline Engine Removal
The explicit engine: wren_ui setting for the sql_answer pipeline has been removed. This change streamlines the configuration in line with removing the unused engine. Please verify that downstream components correctly default or handle the absence of an explicit engine setting.


158-159: Engine Timeout Parameter Addition
The new engine_timeout: 30 setting within the settings block provides a flexible mechanism for configuring engine operation timeouts. This update aligns well with the PR’s objectives for enhanced timeout management.

deployment/kustomizations/base/cm.yaml (2)

132-134: SQL Answer Pipeline Engine Removal Consistency
In the pipelines section for the wren-ai-service-config, the sql_answer pipeline now omits the explicit engine parameter. This change is consistent with the removal reported in other configuration files. Please confirm that the intended default behavior is maintained across environments.


190-192: Engine Timeout Parameter in ConfigMap
The addition of engine_timeout: 30 in the settings section of the ConfigMap standardizes the timeout configuration for engine operations. This is a positive update that ensures consistent timeout handling across various service components.

@cyyeh cyyeh requested a review from paopa February 5, 2025 06:26
Copy link
Member

@paopa paopa left a comment

Choose a reason for hiding this comment

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

lgtm

@paopa paopa merged commit c00d46d into main Feb 5, 2025
12 checks passed
@paopa paopa deleted the chore/ai-service/minor-updates branch February 5, 2025 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/ai-service ai-service related module/ai-service ai-service related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants