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): improve ai service #1068

Merged
merged 8 commits into from
Dec 27, 2024

Conversation

cyyeh
Copy link
Member

@cyyeh cyyeh commented Dec 26, 2024

  • add demo/run_sql.py to test WrenSQL easily using command line
  • refine chart generation prompt that returns empty chart schema if data is empty

Summary by CodeRabbit

  • New Features

    • Introduced a new function to execute SQL scripts with specified parameters.
    • Added a standalone script for executing SQL queries against MDL JSON files.
  • Bug Fixes

    • Improved error handling for loading MDL files and executing SQL queries.
  • Documentation

    • Clarified chart generation instructions for returning empty schemas based on data suitability.
  • Refactor

    • Updated function signatures for enhanced flexibility and error handling in utility functions.
    • Removed caching decorators from specific functions to improve performance.

@cyyeh cyyeh added module/ai-service ai-service related ci/ai-service ai-service related labels Dec 26, 2024
Copy link
Contributor

coderabbitai bot commented Dec 26, 2024

Walkthrough

This pull request introduces a new SQL execution utility across multiple files in the wren-ai-service project. A new run-sql function is added to the Justfile, accompanied by a corresponding Python script run_sql.py that enables interactive SQL query execution against MDL JSON files. The changes include flexible data source and dataset selection, error handling improvements, and modifications to utility functions to support this new functionality.

Changes

File Change Summary
wren-ai-service/Justfile Added run-sql function to execute SQL script with parameters
wren-ai-service/demo/run_sql.py New script for interactive SQL query execution with MDL JSON files
wren-ai-service/demo/utils.py Updated function signatures, removed caching, improved error handling
wren-ai-service/src/pipelines/generation/utils/chart.py Refined chart generation instructions for empty/unsuitable data

Sequence Diagram

sequenceDiagram
    participant User
    participant Justfile
    participant RunSQLScript
    participant WrenEngine
    
    User->>Justfile: Invoke run-sql with parameters
    Justfile->>RunSQLScript: Execute script with MDL path, data source
    RunSQLScript->>WrenEngine: Load MDL, prepare query
    WrenEngine-->>RunSQLScript: Return query results
    RunSQLScript-->>User: Display interactive SQL prompt
Loading

Possibly related PRs

Suggested reviewers

  • andreashimin
  • wwwy3y3

Poem

🐰 SQL queries hop and dance,
Through MDL files, they take their chance,
With Wren Engine as their guide,
Interactive magic, they'll provide!
A rabbit's code, both swift and bright ✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 48a2839 and b609b0a.

📒 Files selected for processing (1)
  • wren-ai-service/Justfile (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • wren-ai-service/Justfile

🪧 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 requested a review from paopa December 27, 2024 01:27
@cyyeh cyyeh marked this pull request as ready for review December 27, 2024 01:27
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: 1

🧹 Nitpick comments (1)
wren-ai-service/Justfile (1)

68-68: Potential inconsistency with naming convention
The function name use-wren-ui-as-engine consistently uses hyphens, while many lines above use underscores for local commands. This isn't strictly an error, but you might want to confirm or unify the naming style for consistency.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 81e4f2a and 48a2839.

📒 Files selected for processing (4)
  • wren-ai-service/Justfile (1 hunks)
  • wren-ai-service/demo/run_sql.py (1 hunks)
  • wren-ai-service/demo/utils.py (3 hunks)
  • wren-ai-service/src/pipelines/generation/utils/chart.py (1 hunks)
🔇 Additional comments (10)
wren-ai-service/demo/run_sql.py (6)

1-3: Imports are straightforward
The core dependencies argparse and json are relevant and well-structured. Ensure that any additional dependencies used in the code (e.g., pandas) are declared in your project's environment or requirements.txt/pyproject.toml.


7-35: Argument parsing and defaults look good
The arguments --mdl-path, --data-source, and --sample-dataset have sensible defaults and clear help text. This aids both discoverability and usability.


42-51: Robust file loading with error handling
Using FileNotFoundError and json.JSONDecodeError provides a clean user-facing message. Great job ensuring the script gracefully exits upon encountering these errors.


52-74: Handles user input gracefully
Your loop for collecting lines until a semicolon is user-friendly and covers a typical “quit” scenario with 'q'. The immediate exception handling around get_data_from_wren_engine call is also a good practice for interactive scripts.


78-79: Main guard for script execution
The if __name__ == "__main__": main() pattern is correctly used. This supports both direct script usage and importing from other modules.


4-4: Use local imports carefully
Importing from utils assumes demo scripts can access the root-level utils.py. Confirm that your environment and paths are set up so that this local import works properly when packaging or distributing.

wren-ai-service/src/pipelines/generation/utils/chart.py (1)

13-14: Clarifying empty data conditions
Explicitly instructing that an empty schema must be returned when data is unsuitable or empty is an improvement. This ensures consistent behavior for chart generation.

wren-ai-service/demo/utils.py (3)

67-67: Optional dataset parameter
Declaring dataset as optional adds flexibility. Verify there are no unintended side effects when dataset is None, especially in downstream _prepare_duckdb(dataset).


141-141: Clearer error messaging
Using response.text in the assertion for response.status_code is effective for showing raw error information. This makes debugging more straightforward if the response is malformed JSON or non-JSON.


164-164: Consistent assertion style
The status check also uses response.text. Keeping these assertions uniform throughout the file ensures consistent debugging and error reporting.

poetry run python -m src.force_update_config

run-sql mdl_path="" data_source="" sameple_dataset="":
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Typo in parameter name
The parameter is spelled sameple_dataset, instead of sample_dataset. This might cause confusion or errors when referencing the variable.

-run-sql mdl_path="" data_source="" sameple_dataset="":
+run-sql mdl_path="" data_source="" sample_dataset="":
📝 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.

Suggested change
run-sql mdl_path="" data_source="" sameple_dataset="":
run-sql mdl_path="" data_source="" sample_dataset="":

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 f1872a1 into main Dec 27, 2024
10 checks passed
@paopa paopa deleted the chore/ai-service/improve-ai-service branch December 27, 2024 02:56
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