Skip to content

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

Merged
cyyeh merged 4 commits into
mainfrom
chore/ai-service/minor-updates
Apr 1, 2025
Merged

chore(wren-ai-service): minor updates#1503
cyyeh merged 4 commits into
mainfrom
chore/ai-service/minor-updates

Conversation

@cyyeh
Copy link
Copy Markdown
Member

@cyyeh cyyeh commented Apr 1, 2025

  • update streaming conditions
  • update reasoning prompt

Summary by CodeRabbit

  • New Features

    • Enhanced response explanations by introducing a clearer, structured step-by-step reasoning in outputs.
    • Improved follow-up query handling to ensure responses better reflect user context and guidance.
  • Refactor

    • Streamlined the processing flow for generating and streaming results to provide a more robust and consistent user experience.
    • Updated the logic for handling follow-up statuses in responses, refining control flow for better user interaction.

@cyyeh cyyeh added module/ai-service ai-service related ci/ai-service ai-service related labels Apr 1, 2025
@cyyeh cyyeh requested a review from imAsterSun April 1, 2025 03:09
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 1, 2025

Walkthrough

This pull request updates the SQL reasoning plan instructions and refines the control flow in streaming functions and ask service methods. The changes modify the output formatting for reasoning steps by introducing numbered steps with bold titles and specifying prefixes for table and column names. Additionally, the logic for handling missing query IDs in streaming functions now creates a new asyncio queue rather than yielding an empty result. A new base response model is also introduced to manage follow-up queries and user guidance in the ask service.

Changes

File(s) Change Summary
wren-ai-service/src/pipelines/generation/.../followup_sql_generation_reasoning.py
wren-ai-service/src/pipelines/generation/.../sql_generation_reasoning.py
Updated SQL reasoning plan formatting: each step now begins with a number, a bolded title, and reasoning; added lines to enforce table (table: <name>) and column (column: <table>.<column>) formatting. Modified streaming functions to initialize a new asyncio queue for missing query IDs.
wren-ai-service/src/web/v1/services/ask.py Introduced a new base model _AskResultResponse with an extra optional field (is_followup), with the existing AskResultResponse inheriting from it and excluding this field during serialization. Updated logic in the ask and get_ask_streaming_result methods for follow-up processing.

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant SC as Streaming Callback
    participant UQ as User Queue

    C->>SC: Invoke _streaming_callback with query_id
    alt query_id not in _user_queues
      SC->>UQ: Initialize new asyncio.Queue
      Note right of SC: Continue processing
    else
      SC->>SC: Process request normally
    end
Loading
sequenceDiagram
    participant Client as Client
    participant AS as Ask Service
    participant P as Pipeline

    Client->>AS: Send ask request
    AS->>AS: Check request history (set is_followup flag)
    alt is_followup true
      AS->>P: Route to follow-up pipeline
    else
      AS->>P: Route to primary pipeline
    end
    P-->>AS: Return streaming result
    AS-->>Client: Deliver AskResultResponse
Loading

Possibly related PRs

Suggested reviewers

  • paopa

Poem

I'm a happy rabbit with speedy hops,
Formatting steps that never stop.
Bold titles shine and queues align,
Each new rule makes code divine.
Hopping through changes with a joyful cheer,
Celebrating updates far and near! 🐰✨


📜 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 669bd6d and ebfaf18.

📒 Files selected for processing (1)
  • wren-ai-service/src/web/v1/services/ask.py (16 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: pytest
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
wren-ai-service/src/web/v1/services/ask.py (5)

82-103: Good addition of the base response model for handling followup queries.

The introduction of the _AskResultResponse base class with an is_followup flag provides a clean way to track query context. This supports the PR's objective of updating streaming conditions by establishing a foundation for differentiating between initial queries and followups.


105-106: Field exclusion pattern looks appropriate for backward compatibility.

The derived AskResultResponse class properly excludes the is_followup field from serialization while maintaining the functionality internally. This is a good approach to add new behavior without breaking existing API consumers.


235-235: Setting followup flag based on history presence is correct.

This is a good implementation where the is_followup field is set based on the presence of histories, which is a logical determinant for whether a query is a followup to a previous interaction.


313-313: Consistent application of followup status throughout the workflow.

The consistent application of the is_followup flag across all response status updates ensures that this context is preserved throughout the entire ask pipeline execution, regardless of which path the execution takes. This is important for maintaining state integrity.

Also applies to: 336-336, 347-347, 356-356, 384-384, 402-402, 437-437, 449-449, 517-517, 561-561, 581-581, 599-599


639-663: Enhanced streaming logic with conditional pipeline selection.

The updated get_ask_streaming_result method now intelligently routes streaming requests to the appropriate pipeline based on the query type and followup status. This addresses the PR objective of updating streaming conditions.

The code now checks:

  1. First if it's a "GENERAL" type query
  2. Then if it's in "planning" status
  3. Then uses either the followup or standard SQL generation reasoning pipeline based on the is_followup flag
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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
Copy Markdown
Contributor

@imAsterSun imAsterSun left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@cyyeh cyyeh merged commit 785a4d4 into main Apr 1, 2025
@cyyeh cyyeh deleted the chore/ai-service/minor-updates branch April 1, 2025 04:39
pull Bot pushed a commit to nagyist/WrenAI that referenced this pull request May 4, 2026
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants