Skip to content

Add Government Services Assistant notebook #686

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

Conversation

Dhivya-Bharathy
Copy link
Contributor

@Dhivya-Bharathy Dhivya-Bharathy commented Jun 25, 2025

This PR adds an AI-powered assistant that helps users find clear, step-by-step information about Chilean government services and procedures.
The assistant uses Firecrawl to fetch official data from ChileAtiende and provides answers in English, with automatic translation.
It features a user-friendly chat interface designed to support citizens, especially seniors, in navigating public services.

Summary by CodeRabbit

  • New Features
    • Introduced an interactive chatbot assistant example for answering questions about Chilean government services.
    • Added support for English-to-Spanish and Spanish-to-English translation within the chatbot.
    • Enabled real-time search and retrieval of information from official Chilean government service pages.
  • Documentation
    • Provided a new Jupyter notebook demonstrating how to use the assistant with translation and web search capabilities.

Copy link
Contributor

coderabbitai bot commented Jun 25, 2025

Warning

Rate limit exceeded

@Dhivya-Bharathy has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 59 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 75463b8 and 390c3e9.

📒 Files selected for processing (1)
  • examples/cookbooks/Government-Services-Assistant.ipynb (1 hunks)

Walkthrough

A new Jupyter notebook example introduces "Tomás," an AI chatbot assistant for answering questions about Chilean government services. The notebook integrates translation utilities and a custom FirecrawlTool class to query and summarize relevant ChileAtiende service pages, enabling English-language interaction with primarily Spanish-language information sources.

Changes

File(s) Change Summary
examples/cookbooks/Chile_Government_Services_Assistant_.ipynb New notebook added: Implements chatbot "Tomás" for Chilean government services; includes translation helpers, FirecrawlTool class, and interactive chat loop.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Notebook
    participant FirecrawlTool
    participant GoogleTranslator

    User->>Notebook: Enter question (in English)
    Notebook->>GoogleTranslator: translate_to_spanish(question)
    GoogleTranslator-->>Notebook: question (in Spanish)
    Notebook->>FirecrawlTool: search(spanish_question)
    FirecrawlTool-->>Notebook: response (in Spanish)
    Notebook->>GoogleTranslator: translate_to_english(response)
    GoogleTranslator-->>Notebook: response (in English)
    Notebook->>User: Display answer (in English)
Loading

Poem

In Chile’s digital garden, Tomás now hops,
Translating your queries with nimble AI chops.
From English to Spanish, and back with a spin,
Government answers, let the searching begin!
With Firecrawl and friends, the help never ends—
A rabbit assistant for all to commend!
🐇✨


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

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @Dhivya-Bharathy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request adds a new, self-contained AI assistant notebook focused on providing clear information about Chilean government services. The assistant is designed for ease of use, integrating web scraping and language translation to deliver relevant answers to user queries.

Highlights

  • New AI Assistant Notebook: This PR introduces a new Jupyter notebook, Chile_Government_Services_Assistant_.ipynb, which implements an AI-powered assistant designed to help users navigate Chilean government services.
  • Firecrawl Integration for Data Retrieval: The assistant leverages the Firecrawl API to search and scrape official information directly from the chileatiende.gob.cl website, ensuring relevant and up-to-date service details.
  • Multilingual Support with Automatic Translation: It features built-in translation capabilities using deep-translator, allowing users to interact in English while the system queries in Spanish and translates the results back to English, enhancing accessibility.
  • User-Friendly Chat Interface: The notebook provides a simple, interactive chat loop, guiding users through inquiries about government procedures in a conversational and step-by-step manner.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

codecov bot commented Jun 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 14.23%. Comparing base (e9f23e1) to head (390c3e9).
Report is 217 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #686      +/-   ##
==========================================
- Coverage   14.50%   14.23%   -0.27%     
==========================================
  Files          25       25              
  Lines        2517     2571      +54     
  Branches      357      367      +10     
==========================================
+ Hits          365      366       +1     
- Misses       2136     2189      +53     
  Partials       16       16              
Flag Coverage Δ
quick-validation 0.00% <ø> (ø)
unit-tests 14.23% <ø> (-0.27%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a new notebook for an AI-powered assistant that helps users find information about Chilean government services. The code includes translation functions, a Firecrawl tool class, and a main chat loop. The code appears functional, but there are opportunities to improve error handling, input validation, and code readability.

Comment on lines 99 to 100
" text = str(text).replace(\"None\", \"\")\n",
" text = re.sub(r'!\\[.*?\\]\\(.*?\\)', '', text)\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider using a more robust method for removing Markdown images, as this regex might not cover all cases.

text = str(text).replace("None", "")
        text = re.sub(r'!\[.*?\]\(.*?\)', '', text)

Comment on lines 133 to 134
" if not search or len(search) < 5:\n",
" return \"Error: Please provide a valid search query (at least 5 characters).\"\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding input validation to check if search is a string to prevent potential errors.

if not search or len(search) < 5:
            return "Error: Please provide a valid search query (at least 5 characters)."

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

🧹 Nitpick comments (2)
examples/cookbooks/Chile_Government_Services_Assistant_.ipynb (2)

132-163: Consider consistent return types for better error handling.

The search method returns different types (None, str) which makes error handling complex. Consider always returning a string with clear indicators for different scenarios.

                 else:
-                    return None
+                    return "No relevant information found for your query."
             else:
-                return None
+                return "No results found. Please try a different search term."

254-254: Simplify complex result validation logic.

The condition for determining valid search results is complex and hard to read. Consider extracting this logic into a helper function.

+def is_valid_result(result):
+    """Check if the search result is valid and not an error."""
+    return (result and 
+            isinstance(result, str) and 
+            result.strip() and 
+            "Error" not in result)
+
     # Only translate if we got a real answer
-    if spanish_answer and isinstance(spanish_answer, str) and spanish_answer.strip() and "Error" not in spanish_answer:
+    if is_valid_result(spanish_answer):
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2f3ce5c and 75463b8.

📒 Files selected for processing (1)
  • examples/cookbooks/Chile_Government_Services_Assistant_.ipynb (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Run tests and collect coverage
  • GitHub Check: quick-test
  • GitHub Check: test-core (3.11)
🔇 Additional comments (4)
examples/cookbooks/Chile_Government_Services_Assistant_.ipynb (4)

24-24: Verify the repository URL in the Colab badge.

The Colab badge URL references "DhivyaBharathy-web/PraisonAI" but the PR is being submitted to "MervinPraison/PraisonAI". Please confirm this is the correct repository reference.


89-104: Good implementation of translation functions with proper error handling.

The translation functions are well-implemented with appropriate error handling and preprocessing. The fallback behavior of returning original text on translation failure is suitable for this chatbot context.


183-196: Well-structured template for formatting search results.

The template provides clear, well-organized formatting for search results with proper markdown structure.


216-220: Clean tool initialization.

The FirecrawlTool initialization properly uses environment variables and predefined constants.

Comment on lines 124 to 130
"class FirecrawlTool:\n",
" def __init__(self, api_key, instruction: str, template: str):\n",
" if not api_key:\n",
" raise ValueError(\"Firecrawl API key not provided.\")\n",
" self.app = FirecrawlApp(api_key=api_key)\n",
" self.instruction = instruction\n",
" self.template = template\n",
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 class and method documentation for better maintainability.

The FirecrawlTool class and its methods lack docstrings. Adding documentation would improve code maintainability and user understanding.

 class FirecrawlTool:
+    """
+    A tool for searching Chilean government services using the Firecrawl API.
+    
+    This class provides functionality to search for information on ChileAtiende
+    government service pages and format the results.
+    """
+    
     def __init__(self, api_key, instruction: str, template: str):
+        """
+        Initialize the FirecrawlTool.
+        
+        Args:
+            api_key (str): Firecrawl API key
+            instruction (str): Search instruction prefix
+            template (str): Template for formatting results
+            
+        Raises:
+            ValueError: If API key is not provided
+        """
📝 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
"class FirecrawlTool:\n",
" def __init__(self, api_key, instruction: str, template: str):\n",
" if not api_key:\n",
" raise ValueError(\"Firecrawl API key not provided.\")\n",
" self.app = FirecrawlApp(api_key=api_key)\n",
" self.instruction = instruction\n",
" self.template = template\n",
class FirecrawlTool:
"""
A tool for searching Chilean government services using the Firecrawl API.
This class provides functionality to search for information on ChileAtiende
government service pages and format the results.
"""
def __init__(self, api_key, instruction: str, template: str):
"""
Initialize the FirecrawlTool.
Args:
api_key (str): Firecrawl API key
instruction (str): Search instruction prefix
template (str): Template for formatting results
Raises:
ValueError: If API key is not provided
"""
if not api_key:
raise ValueError("Firecrawl API key not provided.")
self.app = FirecrawlApp(api_key=api_key)
self.instruction = instruction
self.template = template
🤖 Prompt for AI Agents
In examples/cookbooks/Chile_Government_Services_Assistant_.ipynb around lines
124 to 130, the FirecrawlTool class and its __init__ method lack docstrings. Add
clear and concise docstrings to the class describing its purpose and to the
__init__ method explaining the parameters and their roles to improve
maintainability and user understanding.

Comment on lines 64 to 65
"os.environ['FIRECRAWL_API_KEY'] = \"your api key here\"\n",
"os.environ['OPENAI_API_KEY'] = \"your api key here\""
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

Use secure input method for API keys to prevent accidental commits.

Hardcoded API key placeholders can lead to accidental commits of real keys. Consider using getpass for secure input.

-os.environ['FIRECRAWL_API_KEY'] = "your api key here"
-os.environ['OPENAI_API_KEY'] = "your api key here"
+from getpass import getpass
+
+os.environ['FIRECRAWL_API_KEY'] = getpass("Enter your Firecrawl API key: ")
+os.environ['OPENAI_API_KEY'] = getpass("Enter your OpenAI API key: ")
📝 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
"os.environ['FIRECRAWL_API_KEY'] = \"your api key here\"\n",
"os.environ['OPENAI_API_KEY'] = \"your api key here\""
from getpass import getpass
os.environ['FIRECRAWL_API_KEY'] = getpass("Enter your Firecrawl API key: ")
os.environ['OPENAI_API_KEY'] = getpass("Enter your OpenAI API key: ")
🤖 Prompt for AI Agents
In examples/cookbooks/Chile_Government_Services_Assistant_.ipynb around lines 64
to 65, the API keys are set using hardcoded strings which risks accidental
commits of sensitive information. Replace these hardcoded assignments with
secure input prompts using the getpass module to read the API keys at runtime
without displaying them, preventing exposure in the codebase.

{
"cell_type": "code",
"source": [
"!pip install flask firecrawl praisonaiagents google-genai python-dotenv deep-translator"
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

Remove unused dependencies to reduce footprint.

Several installed packages (flask, praisonaiagents, google-genai, python-dotenv) are not used in the notebook. Consider removing them to minimize dependencies.

-!pip install flask firecrawl praisonaiagents google-genai python-dotenv deep-translator
+!pip install firecrawl deep-translator

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In examples/cookbooks/Chile_Government_Services_Assistant_.ipynb at line 42, the
pip install command includes unused packages such as flask, praisonaiagents,
google-genai, and python-dotenv. Remove these unused dependencies from the
install command to reduce the environment footprint and only keep the necessary
packages like firecrawl and deep-translator.

@Dhivya-Bharathy Dhivya-Bharathy changed the title Add Chile_Government_Services_Assistant notebook Add Government Services Assistant notebook Jun 26, 2025
@Dhivya-Bharathy Dhivya-Bharathy closed this by deleting the head repository Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant