Skip to content

Conversation

@cyyeh
Copy link
Member

@cyyeh cyyeh commented Jul 22, 2025

Summary by CodeRabbit

  • New Features

    • Added automatic cleanup of excessive newlines in generated prompts for improved readability.
    • Introduced display of the current date and time in prompts where applicable.
  • Improvements

    • Enhanced formatting and clarity of SQL data and reasoning instructions in generated outputs.
    • Prompts now consistently return cleaned-up text, ensuring a more polished user experience.
  • Bug Fixes

    • Resolved issues with inconsistent prompt formatting due to unprocessed newlines.

@cyyeh cyyeh requested a review from yichieh-lu July 22, 2025 01:53
@cyyeh cyyeh added module/ai-service ai-service related ci/ai-service ai-service related labels Jul 22, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 22, 2025

Walkthrough

A new utility function, clean_up_new_lines, is introduced to normalize excessive newlines in prompt strings. This function is applied across multiple pipeline prompt functions to ensure consistent prompt formatting. Additionally, the SQL answer generation pipeline is updated to include current time context, with supporting changes in configuration and service layers.

Changes

File(s) Change Summary
src/pipelines/common.py Added clean_up_new_lines function and regex for normalizing newlines.
src/pipelines/generation/chart_adjustment.py
src/pipelines/generation/chart_generation.py
src/pipelines/generation/data_assistance.py
src/pipelines/generation/followup_sql_generation.py
src/pipelines/generation/followup_sql_generation_reasoning.py
src/pipelines/generation/intent_classification.py
src/pipelines/generation/misleading_assistance.py
src/pipelines/generation/question_recommendation.py
src/pipelines/generation/relationship_recommendation.py
src/pipelines/generation/semantics_description.py
src/pipelines/generation/sql_question.py
src/pipelines/generation/sql_generation_reasoning.py
src/pipelines/generation/sql_regeneration.py
src/pipelines/generation/sql_tables_extraction.py
src/pipelines/retrieval/db_schema_retrieval.py
src/pipelines/generation/user_guide_assistance.py
Modified prompt functions to apply clean_up_new_lines to prompt output before returning.
src/pipelines/generation/sql_answer.py
src/pipelines/generation/sql_correction.py
src/pipelines/generation/sql_generation.py
Updated prompt and run functions to handle current_time parameter and apply prompt cleanup.
src/pipelines/generation/utils/sql.py Updated SQL reasoning and rules instructions for prompt generation.
src/pipelines/retrieval/sql_functions.py Removed private helper function _param_expr from SqlFunction class constructor.
src/web/v1/services/init.py Added show_current_time method to Configuration.Timezone for timezone-aware current time formatting.
src/web/v1/services/sql_answer.py Passed current_time to SQL answer pipeline using configuration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebService
    participant Configuration
    participant SQLAnswerPipeline
    participant PromptBuilder
    participant Utility

    User->>WebService: Request SQL answer
    WebService->>Configuration: Get current time (show_current_time)
    Configuration-->>WebService: Current time string
    WebService->>SQLAnswerPipeline: run(query, sql, sql_data, language, current_time, ...)
    SQLAnswerPipeline->>PromptBuilder: run(...)
    PromptBuilder-->>SQLAnswerPipeline: { "prompt": raw_prompt }
    SQLAnswerPipeline->>Utility: clean_up_new_lines(raw_prompt)
    Utility-->>SQLAnswerPipeline: cleaned_prompt
    SQLAnswerPipeline-->>WebService: { "prompt": cleaned_prompt }
    WebService-->>User: Response with cleaned prompt
Loading

Estimated code review effort

3 (~45 minutes)

Possibly related PRs

Suggested labels

wren-ai-service

Suggested reviewers

  • yichieh-lu

Poem

Hopping through code, I tidy the lines,
Three newlines at most—now everything shines!
With prompts all neat and time in the mix,
My whiskers twitch for these clever new tricks.
🐇✨
—A rabbit, who loves a well-groomed prompt

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/ai-service/improve-text2sql

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @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.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f78e4a5 and 7cdba88.

📒 Files selected for processing (24)
  • wren-ai-service/src/pipelines/common.py (2 hunks)
  • wren-ai-service/src/pipelines/generation/chart_adjustment.py (3 hunks)
  • wren-ai-service/src/pipelines/generation/chart_generation.py (2 hunks)
  • wren-ai-service/src/pipelines/generation/data_assistance.py (2 hunks)
  • wren-ai-service/src/pipelines/generation/followup_sql_generation.py (3 hunks)
  • wren-ai-service/src/pipelines/generation/followup_sql_generation_reasoning.py (3 hunks)
  • wren-ai-service/src/pipelines/generation/intent_classification.py (3 hunks)
  • wren-ai-service/src/pipelines/generation/misleading_assistance.py (2 hunks)
  • wren-ai-service/src/pipelines/generation/question_recommendation.py (2 hunks)
  • wren-ai-service/src/pipelines/generation/relationship_recommendation.py (2 hunks)
  • wren-ai-service/src/pipelines/generation/semantics_description.py (2 hunks)
  • wren-ai-service/src/pipelines/generation/sql_answer.py (5 hunks)
  • wren-ai-service/src/pipelines/generation/sql_correction.py (2 hunks)
  • wren-ai-service/src/pipelines/generation/sql_generation.py (3 hunks)
  • wren-ai-service/src/pipelines/generation/sql_generation_reasoning.py (3 hunks)
  • wren-ai-service/src/pipelines/generation/sql_question.py (2 hunks)
  • wren-ai-service/src/pipelines/generation/sql_regeneration.py (3 hunks)
  • wren-ai-service/src/pipelines/generation/sql_tables_extraction.py (2 hunks)
  • wren-ai-service/src/pipelines/generation/user_guide_assistance.py (2 hunks)
  • wren-ai-service/src/pipelines/generation/utils/sql.py (4 hunks)
  • wren-ai-service/src/pipelines/retrieval/db_schema_retrieval.py (2 hunks)
  • wren-ai-service/src/pipelines/retrieval/sql_functions.py (0 hunks)
  • wren-ai-service/src/web/v1/services/__init__.py (2 hunks)
  • wren-ai-service/src/web/v1/services/sql_answer.py (1 hunks)
🧠 Learnings (16)
📓 Common learnings
Learnt from: wwwy3y3
PR: Canner/WrenAI#1585
File: wren-ui/src/pages/api/v1/generate_sql.ts:98-106
Timestamp: 2025-04-24T16:10:43.308Z
Learning: In the generate_sql API, allow users to specify language codes not predefined in the WrenAILanguage enum, passing them through directly rather than strictly validating against the enum.
wren-ai-service/src/pipelines/retrieval/db_schema_retrieval.py (1)

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: wwwy3y3
PR: #1585
File: wren-ui/src/pages/api/v1/generate_sql.ts:98-106
Timestamp: 2025-04-24T16:10:43.308Z
Learning: In the generate_sql API, allow users to specify language codes not predefined in the WrenAILanguage enum, passing them through directly rather than strictly validating against the enum.

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

💤 Files with no reviewable changes (1)
  • wren-ai-service/src/pipelines/retrieval/sql_functions.py
🧰 Additional context used
🧠 Learnings (16)
📓 Common learnings
Learnt from: wwwy3y3
PR: Canner/WrenAI#1585
File: wren-ui/src/pages/api/v1/generate_sql.ts:98-106
Timestamp: 2025-04-24T16:10:43.308Z
Learning: In the generate_sql API, allow users to specify language codes not predefined in the WrenAILanguage enum, passing them through directly rather than strictly validating against the enum.
wren-ai-service/src/pipelines/retrieval/db_schema_retrieval.py (1)

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: wwwy3y3
PR: #1585
File: wren-ui/src/pages/api/v1/generate_sql.ts:98-106
Timestamp: 2025-04-24T16:10:43.308Z
Learning: In the generate_sql API, allow users to specify language codes not predefined in the WrenAILanguage enum, passing them through directly rather than strictly validating against the enum.

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

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

Learnt from: cyyeh
PR: #1763
File: wren-ai-service/src/pipelines/generation/semantics_description.py:31-33
Timestamp: 2025-06-20T02:37:21.292Z
Learning: In the wren-ai-service codebase, when adding new fields like "alias" to the output of functions that use Pydantic models for validation, the user prefers not to update the corresponding Pydantic model definitions to include these new fields.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: pytest
  • GitHub Check: pytest
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (38)
wren-ai-service/src/pipelines/common.py (2)

1-1: LGTM! Well-defined regex pattern for newline normalization.

The regex pattern correctly identifies sequences of 3+ consecutive newlines for cleanup.

Also applies to: 108-109


111-112: LGTM! Clean utility function implementation.

The function correctly normalizes excessive newlines by limiting consecutive newlines to exactly three, which standardizes prompt formatting.

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

1-1: LGTM! Appropriate imports for timezone functionality.

The datetime and pytz imports are standard and necessary for the new timezone-aware time formatting.

Also applies to: 5-5

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

102-102: LGTM! Correct integration of current time context.

The addition of the current_time parameter properly integrates timezone-aware current time into the SQL answer generation pipeline. Note this depends on fixing the method placement issue in the Configuration class.

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

17-21: LGTM! Correct import addition for newline cleanup functionality.

The import of clean_up_new_lines is properly integrated with existing imports from the common module.


322-323: LGTM! Consistent implementation of prompt cleanup pattern.

The modification correctly applies the clean_up_new_lines function to normalize excessive newlines in the prompt output, following the standardized pattern across the codebase.

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

14-14: LGTM! Necessary import for prompt cleanup functionality.

The import of clean_up_new_lines is correctly added to support the prompt normalization feature.


55-59: LGTM! Consistent prompt cleanup implementation.

The function correctly applies the standardized cleanup pattern, storing the prompt builder result first and then returning the cleaned prompt string to normalize newline formatting.

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

16-16: LGTM: Consistent prompt cleanup implementation

The import and usage of clean_up_new_lines follows the standardized pattern being applied across pipeline modules. The implementation correctly normalizes newlines while maintaining the existing function interface.

Also applies to: 55-56

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

13-13: LGTM: Proper prompt normalization implementation

The changes correctly implement the standardized prompt cleanup pattern. The function maintains its original signature and behavior while adding newline normalization.

Also applies to: 65-70

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

13-13: LGTM: Standard prompt cleanup pattern applied correctly

The implementation correctly follows the established pattern for prompt normalization. All parameters are properly passed to prompt_builder.run() and the result is appropriately cleaned before returning.

Also applies to: 75-85

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

13-13: LGTM: Consistent prompt cleanup implementation

The changes properly implement the standardized prompt normalization pattern. The existing query processing logic is preserved while adding newline cleanup functionality.

Also applies to: 65-70

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

14-14: LGTM: Proper prompt normalization applied

The implementation correctly follows the standardized pattern for prompt cleanup. The function maintains its original behavior while adding newline normalization to ensure consistent prompt formatting.

Also applies to: 64-69

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

13-13: LGTM: Clean import addition for prompt normalization.

The import of clean_up_new_lines aligns with the systematic refactoring to standardize prompt formatting across pipeline modules.


65-74: LGTM: Consistent prompt cleaning implementation.

The refactoring correctly introduces an intermediate variable and applies clean_up_new_lines to normalize excessive newlines. This maintains the same external behavior while ensuring consistent prompt formatting across the system.

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

16-16: LGTM: Proper import addition for prompt cleaning.

The clean_up_new_lines import is correctly added alongside the existing build_table_ddl import, following the systematic refactoring pattern.


279-290: LGTM: Consistent prompt normalization implementation.

The prompt function correctly implements the standardized pattern with an intermediate variable and applies clean_up_new_lines for consistent formatting. The external function behavior remains unchanged.

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

13-13: LGTM: Consistent import addition for prompt cleaning utility.

The import follows the established pattern across pipeline modules for standardizing prompt formatting.


77-85: LGTM: Proper implementation of prompt normalization.

The refactoring correctly implements the standardized pattern with intermediate variable and clean_up_new_lines application, maintaining external function behavior while ensuring consistent prompt formatting.

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

14-14: LGTM: Standard import for prompt cleaning utility.

The import addition is consistent with the systematic refactoring across pipeline generation modules.


64-65: LGTM: Consistent prompt cleaning implementation.

Even with the simpler function signature, the implementation correctly follows the established pattern of using an intermediate variable and applying clean_up_new_lines for consistent prompt formatting.

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

13-13: LGTM: Proper import addition maintaining import organization.

The clean_up_new_lines import is correctly added alongside the existing retrieve_metadata import from the same module, maintaining good import organization.


101-116: LGTM: Consistent prompt cleaning with complex parameters.

Despite the more complex parameter set, the implementation correctly follows the established pattern with intermediate variable and clean_up_new_lines application. This maintains consistency across all pipeline generation modules.

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

14-14: LGTM! Consistent import and prompt formatting standardization.

The import of clean_up_new_lines and the modification to the prompt function align perfectly with the systematic refactoring to standardize prompt string formatting across pipeline modules. The change maintains the function signature while adding beneficial newline normalization.

Also applies to: 36-43

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

13-13: LGTM! Consistent application of prompt formatting pattern.

The changes follow the established pattern for standardizing prompt string formatting. The import and modification to the prompt function are implemented correctly and maintain API compatibility.

Also applies to: 101-110

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

13-13: LGTM! Clean import consolidation and consistent prompt processing.

The modification consolidates the import from src.pipelines.common and applies the standard prompt formatting pattern correctly. The implementation maintains all existing functionality while adding the beneficial newline normalization.

Also applies to: 97-112

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

13-13: LGTM! Consistent prompt formatting implementation.

The changes maintain the established pattern for standardizing prompt string formatting. The import and function modification are implemented correctly with no breaking changes to the API.

Also applies to: 55-60

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

13-13: LGTM! Consistent completion of prompt formatting standardization.

The changes complete the systematic refactoring pattern seen across all pipeline modules. The import and prompt function modification are implemented correctly, maintaining API compatibility while adding standardized newline normalization.

This consistent application across all reviewed files demonstrates a well-coordinated effort to improve prompt formatting throughout the codebase.

Also applies to: 110-125

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

14-14: Good addition of clean_up_new_lines import.

The import follows the established pattern for improving prompt formatting consistency across the codebase.


69-73: Excellent implementation of prompt normalization.

The changes correctly implement the standardized pattern for prompt processing:

  • Store raw prompt builder output in local variable
  • Apply clean_up_new_lines to normalize excessive newlines
  • Return cleaned prompt in expected dictionary format

This aligns with the broader effort to standardize prompt formatting across all generation pipeline modules.

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

198-198: Good improvement to reasoning plan format.

Changing from always showing the last step as SQL generation to showing only bullet points makes the reasoning plan more focused and readable.


213-213: Excellent preference for CTEs over subqueries.

This change promotes better SQL readability and maintainability. CTEs are generally easier to understand and debug compared to nested subqueries.


235-236: Well-structured alias usage guidelines.

The restriction to use aliases only in the final SELECT clause, with values derived from database schema comments, provides better consistency and makes the intent clearer. This is a good refinement from the previous more permissive approach.


265-265: Improved function selection guidance.

Changing from "must use" to "must only choose appropriate functions" promotes more selective and contextually relevant function usage, which should lead to better SQL quality.

wren-ai-service/src/pipelines/generation/sql_answer.py (4)

13-13: Good import additions for enhanced functionality.

The imports for clean_up_new_lines and Configuration support the new prompt normalization and temporal context features.

Also applies to: 15-15


45-49: Excellent improvement to prompt template structure.

The changes provide better organization:

  • Separating columns and rows makes the data structure clearer than embedding the full dictionary
  • Adding current_time provides valuable temporal context for generating more accurate answers

These changes should improve the quality of SQL-to-answer generation.


59-76: Well-implemented prompt processing with temporal context.

The function signature update and implementation correctly:

  • Add current_time parameter to support temporal context
  • Follow the established pattern for prompt normalization using clean_up_new_lines
  • Maintain backward compatibility through proper parameter ordering

156-156: Smart default value implementation for current_time.

Using Configuration().show_current_time() as the default value ensures the pipeline always has current temporal context when not explicitly provided, while still allowing override when needed.

Also applies to: 168-168

@cyyeh cyyeh merged commit f299806 into main Jul 22, 2025
15 checks passed
@cyyeh cyyeh deleted the chore/ai-service/improve-text2sql branch July 22, 2025 02:26
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 wren-ai-service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants