Skip to content

chore(wren-ai-service): update apis #1726

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

Merged
merged 1 commit into from
Jun 6, 2025
Merged

Conversation

cyyeh
Copy link
Member

@cyyeh cyyeh commented Jun 6, 2025

Summary by CodeRabbit

  • New Features

    • Added a new field to track the source of requests ("ui" or "api") across various request and event models, allowing differentiation of requests based on their origin.
  • Refactor

    • Unified and simplified request models by introducing a shared base class, resulting in more consistent request handling and reduced redundancy.
    • Updated metadata and event responses to consistently include the request source information.
  • Bug Fixes

    • Corrected minor inconsistencies in configuration and language handling within request processing.

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

coderabbitai bot commented Jun 6, 2025

Walkthrough

This change introduces a new BaseRequest class for standardizing request models across multiple services, adding a request_from field to track the source of each request ("ui" or "api"). Numerous request and event models are refactored to inherit from BaseRequest, propagating the request_from context through error handling, metadata, and event logging.

Changes

Files/Paths Change Summary
src/web/v1/services/__init__.py Added BaseRequest class with common fields and request_from; updated MetadataTraceable._error_metadata.
src/web/v1/services/ask.py, chart.py, chart_adjustment.py, sql_answer.py, Refactored request classes to inherit from BaseRequest; removed redundant fields; added request_from to flows.
semantics_preparation.py, sql_question.py
src/web/v1/services/instructions.py, question_recommendation.py, Extended event/request models with request_from; updated error handling and event caching to include it.
relationship_recommendation.py, semantics_description.py, sql_corrections.py,
sql_pairs.py

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Service
    participant BaseRequest
    participant Event/Resource
    participant Cache

    Client->>API_Service: Send request (with request_from)
    API_Service->>BaseRequest: Parse request (inherits request_from)
    API_Service->>Event/Resource: Create/update with request_from
    API_Service->>Cache: Store event/resource with request_from
    API_Service-->>Client: Respond (metadata includes request_from)
Loading

Possibly related PRs

Suggested labels

wren-ai-service

Poem

In fields of code, a rabbit hops,
With "request_from" in every stop.
From UI or API, it knows the way,
Through BaseRequest fields, it leaps all day.
Events and errors now recall
Who sent the word, who started it all!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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

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

approved

@cyyeh cyyeh merged commit d63623c into main Jun 6, 2025
12 of 15 checks passed
@cyyeh cyyeh deleted the chore/ai-service/update-apis branch June 6, 2025 09:59
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7f70425 and 54f38d5.

📒 Files selected for processing (13)
  • wren-ai-service/src/web/v1/services/__init__.py (3 hunks)
  • wren-ai-service/src/web/v1/services/ask.py (5 hunks)
  • wren-ai-service/src/web/v1/services/chart.py (2 hunks)
  • wren-ai-service/src/web/v1/services/chart_adjustment.py (3 hunks)
  • wren-ai-service/src/web/v1/services/instructions.py (5 hunks)
  • wren-ai-service/src/web/v1/services/question_recommendation.py (7 hunks)
  • wren-ai-service/src/web/v1/services/relationship_recommendation.py (5 hunks)
  • wren-ai-service/src/web/v1/services/semantics_description.py (4 hunks)
  • wren-ai-service/src/web/v1/services/semantics_preparation.py (3 hunks)
  • wren-ai-service/src/web/v1/services/sql_answer.py (2 hunks)
  • wren-ai-service/src/web/v1/services/sql_corrections.py (5 hunks)
  • wren-ai-service/src/web/v1/services/sql_pairs.py (5 hunks)
  • wren-ai-service/src/web/v1/services/sql_question.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (7)
wren-ai-service/src/web/v1/services/semantics_preparation.py (1)
wren-ai-service/src/web/v1/services/__init__.py (1)
  • BaseRequest (47-60)
wren-ai-service/src/web/v1/services/sql_question.py (1)
wren-ai-service/src/web/v1/services/__init__.py (1)
  • BaseRequest (47-60)
wren-ai-service/src/web/v1/services/sql_answer.py (1)
wren-ai-service/src/web/v1/services/__init__.py (2)
  • BaseRequest (47-60)
  • SSEEvent (33-43)
wren-ai-service/src/web/v1/services/semantics_description.py (3)
wren-ai-service/src/web/v1/services/__init__.py (2)
  • BaseRequest (47-60)
  • MetadataTraceable (7-21)
wren-ai-service/src/web/v1/services/relationship_recommendation.py (3)
  • Resource (21-31)
  • Error (22-24)
  • _handle_exception (44-59)
wren-ai-service/src/web/v1/services/instructions.py (2)
  • Error (24-26)
  • _handle_exception (45-60)
wren-ai-service/src/web/v1/services/chart_adjustment.py (1)
wren-ai-service/src/web/v1/services/__init__.py (3)
  • BaseRequest (47-60)
  • query_id (55-56)
  • query_id (59-60)
wren-ai-service/src/web/v1/services/instructions.py (5)
wren-ai-service/src/web/v1/services/__init__.py (3)
  • BaseRequest (47-60)
  • MetadataTraceable (7-21)
  • with_metadata (8-14)
wren-ai-service/src/web/v1/services/question_recommendation.py (3)
  • Event (22-28)
  • Error (18-20)
  • _handle_exception (43-58)
wren-ai-service/src/web/v1/services/relationship_recommendation.py (2)
  • Error (22-24)
  • _handle_exception (44-59)
wren-ai-service/src/web/v1/services/semantics_description.py (2)
  • Error (19-21)
  • _handle_exception (39-54)
wren-ai-service/src/web/v1/routers/instructions.py (1)
  • DeleteRequest (111-113)
wren-ai-service/src/web/v1/services/sql_pairs.py (2)
wren-ai-service/src/web/v1/services/__init__.py (3)
  • BaseRequest (47-60)
  • MetadataTraceable (7-21)
  • with_metadata (8-14)
wren-ai-service/src/web/v1/routers/sql_pairs.py (1)
  • DeleteRequest (112-114)
🪛 Pylint (3.3.7)
wren-ai-service/src/web/v1/services/semantics_preparation.py

[refactor] 17-17: Too few public methods (1/2)

(R0903)

wren-ai-service/src/web/v1/services/sql_question.py

[refactor] 17-17: Too few public methods (1/2)

(R0903)

wren-ai-service/src/web/v1/services/chart.py

[refactor] 16-16: Too few public methods (1/2)

(R0903)


[refactor] 23-23: Too few public methods (0/2)

(R0903)


[refactor] 28-28: Too few public methods (1/2)

(R0903)

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

[refactor] 17-17: Too few public methods (1/2)

(R0903)

wren-ai-service/src/web/v1/services/relationship_recommendation.py

[refactor] 17-17: Too few public methods (1/2)

(R0903)

wren-ai-service/src/web/v1/services/semantics_description.py

[refactor] 56-56: Too few public methods (1/2)

(R0903)

wren-ai-service/src/web/v1/services/chart_adjustment.py

[refactor] 27-27: Too few public methods (1/2)

(R0903)


[refactor] 34-34: Too few public methods (0/2)

(R0903)


[refactor] 39-39: Too few public methods (1/2)

(R0903)

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

[error] 20-20: Instance of 'MetadataTraceable' has no 'request_from' member

(E1101)


[refactor] 47-47: Too few public methods (1/2)

(R0903)

wren-ai-service/src/web/v1/services/instructions.py

[refactor] 62-62: Too few public methods (1/2)

(R0903)


[refactor] 123-123: Too few public methods (1/2)

(R0903)

wren-ai-service/src/web/v1/services/sql_corrections.py

[refactor] 57-57: Too few public methods (1/2)

(R0903)

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

[refactor] 22-22: Too few public methods (1/2)

(R0903)


[refactor] 32-32: Too few public methods (0/2)

(R0903)


[refactor] 37-37: Too few public methods (1/2)

(R0903)


[refactor] 95-95: Too few public methods (1/2)

(R0903)


[refactor] 102-102: Too few public methods (0/2)

(R0903)


[refactor] 107-107: Too few public methods (1/2)

(R0903)

wren-ai-service/src/web/v1/services/question_recommendation.py

[refactor] 155-155: Too few public methods (1/2)

(R0903)

wren-ai-service/src/web/v1/services/sql_pairs.py

[refactor] 54-54: Too few public methods (1/2)

(R0903)


[refactor] 97-97: Too few public methods (1/2)

(R0903)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: pytest
  • GitHub Check: pytest
  • GitHub Check: Analyze (go)
🔇 Additional comments (50)
wren-ai-service/src/web/v1/services/chart.py (3)

10-10: Import addition looks good.

The BaseRequest import is correctly added to support the inheritance changes.


16-16: Inheritance refactoring is well-implemented.

Both ChartRequest and StopChartRequest now correctly inherit from BaseRequest, which centralizes common fields like project_id, thread_id, configurations, and request_from. This reduces code duplication and follows the DRY principle.

Also applies to: 28-28

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 16-16: Too few public methods (1/2)

(R0903)


94-94: Request tracking metadata correctly added.

The request_from field is properly added to the metadata to track whether the request originated from "ui" or "api", which aligns with the broader standardization effort.

wren-ai-service/src/web/v1/services/semantics_preparation.py (4)

11-11: Import addition is correct.

The BaseRequest import is properly added to support the class inheritance changes.


17-17: Inheritance change follows standardization pattern.

SemanticsPreparationRequest now inherits from BaseRequest, which provides common fields and reduces code duplication. The removed project_id field is now inherited from the base class.

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 17-17: Too few public methods (1/2)

(R0903)


69-69: Request source tracking added consistently.

The request_from field is correctly added to the metadata, maintaining consistency with the tracking pattern established across other services.


94-110: Code formatting improvement.

The cache assignment has been reformatted for better readability while maintaining the same logic and functionality.

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

11-11: Imports correctly updated.

Both BaseRequest and SSEEvent imports are properly added to support the class inheritance and SSE functionality.


17-17: Inheritance change aligns with standardization.

SqlAnswerRequest now inherits from BaseRequest, removing redundant field declarations and leveraging the centralized common fields like project_id, configurations, and request_from.

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 17-17: Too few public methods (1/2)

(R0903)


68-69: Request tracking integrated with existing metadata structure.

The request_from field is properly added to the metadata while preserving the existing nested error structure. This maintains backward compatibility while adding the new tracking capability.

wren-ai-service/src/web/v1/services/sql_question.py (2)

11-11: Import addition is correct.

The BaseRequest import is properly added to support the inheritance changes.


17-17: Inheritance change follows standardization pattern.

SqlQuestionRequest now correctly inherits from BaseRequest, centralizing common fields and reducing code duplication.

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 17-17: Too few public methods (1/2)

(R0903)

wren-ai-service/src/web/v1/services/chart_adjustment.py (2)

10-10: LGTM: Clean inheritance from BaseRequest

The import of BaseRequest and the inheritance changes for ChartAdjustmentRequest and StopChartAdjustmentRequest properly consolidate common request fields and eliminate code duplication.

Also applies to: 27-27, 39-39


107-107: Good addition of request tracking

Adding request_from to the metadata ensures consistent tracking of request origin throughout the service.

wren-ai-service/src/web/v1/services/instructions.py (4)

11-11: Consistent addition of request tracking infrastructure

The import of BaseRequest and MetadataTraceable, along with the addition of request_from to the Event model, follows the established pattern for request source tracking.

Also applies to: 33-33


51-51: Good propagation of request context in error handling

The addition of request_from parameter to _handle_exception and its usage in the Event creation ensures that request origin is tracked even in error scenarios.

Also applies to: 58-58


62-62: Proper inheritance from BaseRequest

Both IndexRequest and DeleteRequest correctly inherit from BaseRequest, removing field duplication and standardizing the request structure.

Also applies to: 123-123

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 62-62: Too few public methods (1/2)

(R0903)


110-110: Complete request tracking implementation

The propagation of request_from through both success and error paths in the index and delete methods ensures comprehensive request origin tracking.

Also applies to: 118-118, 149-149, 156-156

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

1-1: Good addition of request tracking to metadata

The import of type annotations and addition of request_from to _error_metadata enables consistent request source tracking across all services using MetadataTraceable.

Also applies to: 20-20


46-61: Well-designed BaseRequest class

The BaseRequest class effectively consolidates common request fields and provides:

  • Proper encapsulation with private _query_id and public property
  • Sensible defaults (request_from defaulting to "ui")
  • Type safety with Literal constraints for request_from
  • Standard fields needed across all service requests

This eliminates code duplication and standardizes request handling across services.

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 47-47: Too few public methods (1/2)

(R0903)

wren-ai-service/src/web/v1/services/relationship_recommendation.py (4)

11-11: Consistent refactoring to BaseRequest pattern

The import changes, inheritance from BaseRequest for the Input class, and addition of request_from to the Resource model follow the established standardization pattern.

Also applies to: 17-17, 31-31


50-50: Proper error handling with request tracking

The addition of request_from parameter to _handle_exception and its propagation to the cached Resource ensures request origin is tracked in error scenarios.

Also applies to: 57-57


72-72: Good fix: Corrected field name from configuration to configurations

This change fixes a bug where request.configuration.language was incorrectly accessing a non-existent field. The correct field name in BaseRequest is configurations (plural).


82-82: Complete request tracking in recommend method

The propagation of request_from through both success and error paths ensures comprehensive request origin tracking throughout the recommendation lifecycle.

Also applies to: 90-90, 97-97

wren-ai-service/src/web/v1/services/sql_corrections.py (5)

10-10: LGTM: Correct import of BaseRequest components.

The import aligns with the standardization effort to use BaseRequest across all service request models.


27-27: LGTM: Added request_from tracking to Event model.

This addition enables consistent tracking of request origins in event data, supporting the standardization pattern seen across other services.


45-45: LGTM: Proper propagation of request_from in error handling.

The _handle_exception method correctly accepts and stores the request_from parameter, ensuring error events maintain request origin context.

Also applies to: 53-53


57-61: LGTM: Successful refactor to BaseRequest inheritance.

The CorrectionRequest class now inherits from BaseRequest, which removes redundant field definitions (like project_id) and centralizes common request properties. This aligns with the broader standardization effort across all service modules.

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 57-57: Too few public methods (1/2)

(R0903)


117-117: LGTM: Consistent request_from propagation throughout request lifecycle.

The request_from field is properly propagated from the incoming request to both success and error event handling, ensuring complete traceability of request origins.

Also applies to: 126-126, 134-134

wren-ai-service/src/web/v1/services/semantics_description.py (6)

12-12: LGTM: Correct import of BaseRequest components.

The import supports the standardization to use BaseRequest across service request models.


28-28: LGTM: Added request_from tracking to Resource model.

This addition maintains consistency with other services in tracking request origins.


45-45: LGTM: Proper request_from propagation in error handling.

The _handle_exception method correctly accepts and uses the request_from parameter, maintaining request origin context in error scenarios.

Also applies to: 52-52


56-61: LGTM: Successful refactor to BaseRequest inheritance.

The GenerateRequest class now inherits from BaseRequest, removing redundant field definitions and centralizing common request properties.

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 56-56: Too few public methods (1/2)

(R0903)


67-67: LGTM: Corrected configuration field access.

Good catch! The access was corrected from request.configuration.language to request.configurations.language, aligning with the plural field name defined in BaseRequest.


119-119: LGTM: Complete request_from propagation throughout request lifecycle.

The request_from field is properly set on successful completion and propagated to all exception handling paths, ensuring comprehensive request origin tracking.

Also applies to: 126-126, 133-133

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

11-11: LGTM: Correct import of BaseRequest components.

The import supports the standardization effort across all service modules.


22-22: LGTM: Clean refactor to BaseRequest inheritance.

All request classes (AskRequest, StopAskRequest, AskFeedbackRequest, StopAskFeedbackRequest) now inherit from BaseRequest, which removes the need for internal _query_id management and other common fields. This centralizes common request functionality effectively.

Also applies to: 37-37, 95-95, 107-107

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 22-22: Too few public methods (1/2)

(R0903)


184-184: LGTM: Added request_from to metadata for tracking.

The request_from field is now included in the metadata returned by both ask and ask_feedback methods, enabling consistent request origin tracking across the system.

Also applies to: 697-697

wren-ai-service/src/web/v1/services/sql_pairs.py (5)

11-11: LGTM: Correct import of BaseRequest components.

The import aligns with the standardization effort across service modules.


26-26: LGTM: Added request_from tracking to Event model.

This addition maintains consistency with other services for request origin tracking.


43-43: LGTM: Proper request_from propagation in error handling.

The _handle_exception method correctly accepts and uses the request_from parameter for error event creation.

Also applies to: 50-50


54-57: LGTM: Successful refactor to BaseRequest inheritance.

Both IndexRequest and DeleteRequest classes now inherit from BaseRequest, removing redundant field definitions and centralizing common request properties.

Also applies to: 97-100

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 54-54: Too few public methods (1/2)

(R0903)


84-84: LGTM: Proper request_from propagation in most cases.

The request_from field is correctly propagated in the index method and exception handling paths.

Also applies to: 92-92, 125-125

wren-ai-service/src/web/v1/services/question_recommendation.py (7)

12-12: LGTM: Import updated for BaseRequest refactoring

The import correctly brings in the new BaseRequest base class along with other required types.


28-28: LGTM: Added request source tracking

The request_from field properly tracks whether requests originate from the UI or API, with a sensible default value.


49-49: LGTM: Error handling updated to propagate request source

The _handle_exception method correctly accepts and stores the request_from parameter, ensuring error events maintain the original request source context.

Also applies to: 56-56


226-226: LGTM: Request source tracking on successful completion

Properly sets the request_from field on the cached event after successful question recommendation generation.


234-234: LGTM: Consistent error handling with request source

Both exception handlers correctly propagate the request_from field, ensuring error tracking maintains the original request context.

Also applies to: 241-241


155-155:

✅ Verification successful

Verify BaseRequest provides required fields

The inheritance change from BaseModel to BaseRequest aligns with the standardization effort. However, ensure that BaseRequest provides all the fields that were previously available (like project_id and configurations).


🏁 Script executed:

#!/bin/bash
# Verify BaseRequest class definition and its fields
ast-grep --pattern 'class BaseRequest($_) {
  $$$
}'

Length of output: 54


🏁 Script executed:

#!/bin/bash
# Search for BaseRequest class definition across the repository
rg -n "class BaseRequest" --color=never

# If found, show surrounding context for field definitions
if rg -q "class BaseRequest" --color=never; then
  rg -n "class BaseRequest" -A 20 --color=never
else
  echo "No class BaseRequest definition found; checking imports and usage…"
  # Search for BaseRequest references to locate its module
  rg -n "BaseRequest" --color=never
fi

Length of output: 2021


✅ BaseRequest includes required fields
Verified that in wren-ai-service/src/web/v1/services/__init__.py, BaseRequest (lines 47–52) defines both project_id and configurations (among others), so the switch from BaseModel to BaseRequest preserves all needed fields.

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 155-155: Too few public methods (1/2)

(R0903)


173-173:

✅ Verification successful

Verify configuration/configurations field compatibility

The change from input.configuration to input.configurations suggests a field name change in BaseRequest. Ensure that:

  1. configurations has the same interface as the previous configuration field
  2. The .language attribute access (line 192) is still valid
  3. The parameter type compatibility with _validate_question method (line 68 expects Configuration type)

Also applies to: 192-192


🏁 Script executed:

#!/bin/bash
# Check BaseRequest field definitions and Configuration type usage
echo "=== BaseRequest field definitions ==="
ast-grep --pattern 'class BaseRequest($_) {
  $$$
  configurations: $_
  $$$
}'

echo "=== Configuration class definition ==="
ast-grep --pattern 'class Configuration($_) {
  $$$
}'

echo "=== Usage of configurations field ==="
rg -A 3 "\.configurations" --type py

Length of output: 7043


🏁 Script executed:

#!/bin/bash
echo "=== Models directory contents ==="
ls wren-ai-service/src/web/v1/models

echo
echo "=== BaseRequest definition ==="
rg -n "class BaseRequest" -n wren-ai-service/src/web/v1/models

echo
echo "=== Configuration class definition ==="
rg -n "class Configuration" -n wren-ai-service/src/web/v1/models

echo
echo "=== configuration field in BaseRequest ==="
rg -n "configuration" -n wren-ai-service/src/web/v1/models/base_request.py || true

echo
echo "=== configurations field in BaseRequest ==="
rg -n "configurations" -n wren-ai-service/src/web/v1/models/base_request.py || true

Length of output: 1203


🏁 Script executed:

#!/bin/bash
echo "=== Searching for BaseRequest across repository ==="
rg --type py -n "class BaseRequest"

echo
echo "=== Searching for Configuration class across repository ==="
rg --type py -n "class Configuration"

Length of output: 558


🏁 Script executed:

#!/bin/bash
echo "=== BaseRequest snippet ==="
rg -A10 "class BaseRequest" -n wren-ai-service/src/web/v1/services/__init__.py

echo
echo "=== Configuration snippet ==="
rg -A20 "class Configuration" -n wren-ai-service/src/web/v1/services/__init__.py

echo
echo "=== _validate_question signature ==="
rg -A5 -B5 "def _validate_question" -n wren-ai-service/src/web/v1/services/question_recommendation.py

echo
echo "=== Usages around input.configurations ==="
rg -A5 -B5 "input.configurations" -n wren-ai-service/src/web/v1/services/question_recommendation.py

Length of output: 2776


🏁 Script executed:

#!/bin/bash
echo "=== Full _validate_question signature ==="
rg -A20 -B2 "async def _validate_question" -n wren-ai-service/src/web/v1/services/question_recommendation.py

Length of output: 1283


configurations field is correctly wired through the request and validation
All checks pass:

  • BaseRequest defines configurations: Configuration with a default
  • input.configurations.language is valid on the Configuration model
  • _validate_question(..., configuration: Configuration) is invoked positionally with input.configurations

No further changes needed.

@@ -75,6 +64,7 @@ async def sql_question(
"error_type": "",
"error_message": "",
},
"request_from": sql_question_request.request_from,
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Inconsistent placement of request_from field.

The request_from field is added at the top level of the results dictionary, which is inconsistent with the pattern established in other services where it's placed within the metadata subdictionary (lines 63-66). This inconsistency could lead to confusion and processing issues.

Move the field to the metadata for consistency:

         results = {
             "sql_question_result": {},
             "metadata": {
                 "error_type": "",
                 "error_message": "",
+                "request_from": sql_question_request.request_from,
             },
-            "request_from": sql_question_request.request_from,
         }
📝 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
"request_from": sql_question_request.request_from,
results = {
"sql_question_result": {},
"metadata": {
"error_type": "",
"error_message": "",
"request_from": sql_question_request.request_from,
},
}
🤖 Prompt for AI Agents
In wren-ai-service/src/web/v1/services/sql_question.py at line 67, the
request_from field is incorrectly placed at the top level of the results
dictionary. To fix this, move the request_from field inside the existing
metadata subdictionary (lines 63-66) to maintain consistency with other services
and avoid confusion.

Comment on lines +116 to +120
self._cache[request.id] = self.Event(
id=request.id,
status="finished",
request_from=request.request_from,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing trace_id for consistency.

The Event creation in the delete method's success case is missing the trace_id parameter, which is inconsistent with the index method (line 83) and other services.

 self._cache[request.id] = self.Event(
     id=request.id,
     status="finished",
+    trace_id=kwargs.get("trace_id"),
     request_from=request.request_from,
 )
📝 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
self._cache[request.id] = self.Event(
id=request.id,
status="finished",
request_from=request.request_from,
)
self._cache[request.id] = self.Event(
id=request.id,
status="finished",
trace_id=kwargs.get("trace_id"),
request_from=request.request_from,
)
🤖 Prompt for AI Agents
In wren-ai-service/src/web/v1/services/sql_pairs.py around lines 116 to 120, the
Event object created in the delete method is missing the trace_id parameter,
causing inconsistency with the index method and other services. Add the trace_id
attribute from the request to the Event constructor to ensure consistent
tracking and logging.

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