chore(wren-ai-service): Try to make evaluation work again
After the code is refactored, the evaluation will not work.
This PR is trying to make the evaluation work again.
But now it reports the error:
looks like engine doesn't load spider test data. I follow the instruction of https://github.com/Canner/WrenAI/tree/main/wren-ai-service/eval#eval-dataset-preparationif-using-spider-10-dataset put the data to wren-ai-service/tools/dev/spider1.0I
{
"valid_generation_results": [],
"invalid_generation_results": [
{
"sql": "SELECT \"c\".\"Continent\", COUNT(\"cm\".\"Id\") AS \"MakerCount\" FROM \"continents\" AS \"c\" LEFT JOIN \"countries\" AS \"co\" ON \"c\".\"ContId\" = \"co\".\"Continent\" LEFT JOIN \"car_makers\" AS \"cm\" ON LOWER(\"co\".\"CountryName\") = LOWER(\"cm\".\"Country\") GROUP BY \"c\".\"Continent\"",
"type": "DRY_RUN",
"error": "Cannot read properties of null (reading 'id')",
"correlation_id": null
}
]
}
Summary by CodeRabbit
Summary by CodeRabbit
-
New Features
- Enhanced pipeline configuration management
- Improved service metadata retrieval
- Streamlined prediction process
- Added new methods for handling queries in the AskPipeline
-
Refactor
- Restructured AskPipeline class
- Updated provider and component initialization
- Modified prediction logic to focus on first dataset item
- Adjusted SQL execution parameter handling
-
Bug Fixes
- Corrected handling of project_id type in SQL execution
-
Documentation
- Improved code organization and clarity
Walkthrough
The changes introduce significant modifications to the AskPipeline class in the wren-ai-service/eval/pipelines.py file, adding new methods and updating the constructor to enhance service initialization. Additionally, the prediction.py file has been adjusted to streamline configuration management by altering import statements. A new method has been added to the ServiceMetadata class in globals.py to facilitate attribute retrieval based on keys. These updates collectively enhance the functionality and organization of the evaluation and prediction modules.
Changes
| File(s) | Change Summary |
|---|---|
wren-ai-service/eval/pipelines.py |
Added AskPipeline class methods (indexing_service, ask_service, dict_to_string), updated constructor to accept pipe_components and settings, restructured _process, and modified the init function to pass new parameters. |
wren-ai-service/eval/prediction.py |
Updated import statements to streamline configuration management, added settings and generate_components, removed previous import of src.providers as provider. |
wren-ai-service/src/globals.py |
Added get method to ServiceMetadata for keyed attribute retrieval. |
Possibly related PRs
-
Canner/WrenAI#1303: Related changes in the
metrics_initiatorfunction andmetricsmethod in theAskPipelineclass. -
Canner/WrenAI#1297: Modifications to the
AskPipelineclass involving new functionalities and enhancements related to SQL generation.
Suggested labels
module/ai-service, ci/ai-service
Suggested reviewers
- paopa
Poem
I’m a rabbit in a code-filled glen,
Hopping through pipelines and scripts again,
New methods bloom like carrots so bright,
With every commit, my heart takes flight,
In ASCII fields I dance with glee—
CodeRabbit sings: “Change is key!”
🥕🐇
📜 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 58f61501aa9c7163c36187c614904a2604727b0a and 9683581fced7f6f387985d27b377b51d0a9cd3ca.
📒 Files selected for processing (2)
-
wren-ai-service/eval/pipelines.py(4 hunks) -
wren-ai-service/eval/prediction.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
wren-ai-service/eval/pipelines.py
4-4: uuid imported but unused
Remove unused import: uuid
(F401)
11-11: json imported but unused
Remove unused import: json
(F401)
15-15: src.config.settings imported but unused
Remove unused import: src.config.settings
(F401)
16-16: src.providers.generate_components imported but unused
Remove unused import: src.providers.generate_components
(F401)
18-18: src.web.v1.services.semantics_preparation.SemanticsPreparationRequest imported but unused
Remove unused import: src.web.v1.services.semantics_preparation.SemanticsPreparationRequest
(F401)
22-22: src.web.v1.services.ask.AskRequest imported but unused
Remove unused import
(F401)
23-23: src.web.v1.services.ask.AskResultRequest imported but unused
Remove unused import
(F401)
24-24: src.web.v1.services.ask.AskResultResponse imported but unused
Remove unused import
(F401)
wren-ai-service/eval/prediction.py
16-16: src.providers.generate_components imported but unused
Remove unused import: src.providers.generate_components
(F401)
🔇 Additional comments (1)
wren-ai-service/eval/pipelines.py (1)
386-394: Add error handling for circular references and unhashable keys.The recursive dictionary to string conversion could fail in several scenarios:
- Circular references could cause infinite recursion
- Unhashable dictionary keys could raise TypeError
Add error handling to handle these cases:
def dict_to_string(self, d: dict, seen=None) -> str: + if seen is None: + seen = set() + if not isinstance(d, dict): return str(d) + # Check for circular references + d_id = id(d) + if d_id in seen: + return "{...}" # Indicate circular reference + seen.add(d_id) + result = "{" - for key, value in d.items(): - result += f"'{key}': {self.dict_to_string(value)}, " + try: + for key, value in d.items(): + result += f"'{key}': {self.dict_to_string(value, seen)}, " + except TypeError as e: + return f"{{Error: {str(e)}}}" + result = result.rstrip(", ") + "}" + seen.remove(d_id) return result
✨ Finishing Touches
- [ ] 📝 Generate Docstrings (Beta)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
🪧 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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. (Beta) -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.