Skip to content

Conversation

@Dhivya-Bharathy
Copy link
Contributor

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

This notebook introduces a GitHub Repo Analyzer Agent powered by PraisonAI and OpenAI.
It fetches a repository’s structure using the GitHub API and summarizes its purpose via AI.
Built for Colab, it works without authentication for public repos and includes fallback handling.

Summary by CodeRabbit

  • New Features
    • Added a Jupyter notebook example for estimating and forecasting vehicle fuel emissions using an AI agent.
    • Introduced a Jupyter notebook that analyzes GitHub repositories and summarizes their structure with an AI agent.
    • Created a Jupyter notebook implementing a personalized learning assistant chatbot with fallback to GPT-2 for robust responses.
    • Added a Python script for a command-line personalized learning assistant chatbot with error handling and fallback AI model support.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 23, 2025

Walkthrough

Four new examples are introduced: three Jupyter notebooks and one Python script. These cover AI agent applications for fuel emission estimation, GitHub repository analysis, and personalized learning assistance, each demonstrating agent configuration, user interaction, and fallback mechanisms. The learning assistant is implemented both as a notebook and a standalone script.

Changes

File(s) Change Summary
examples/cookbooks/Fuel_Emission_Agent_Intelligence_Agent.ipynb Added notebook demonstrating an agent for estimating and forecasting vehicle CO₂ emissions.
examples/cookbooks/github_repo_analyzer_agent.ipynb Added notebook showing an agent that analyzes GitHub repositories and summarizes their contents.
examples/cookbooks/personalized_learning_assistant.ipynb Added notebook implementing a conversational personalized learning assistant with fallback.
examples/python/tools/exa-tool/learning_assistant.py Added script for a CLI-based personalized learning assistant with fallback to GPT-2.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Notebook/Script
    participant Agent
    participant OpenAI API
    participant HuggingFace GPT-2

    User->>Notebook/Script: Provide input/query
    Notebook/Script->>Agent: Send query
    Agent->>OpenAI API: Request completion
    OpenAI API-->>Agent: Return response
    Agent-->>Notebook/Script: Return answer
    Notebook/Script-->>User: Display answer
    alt Agent fails
        Notebook/Script->>HuggingFace GPT-2: Generate fallback response
        HuggingFace GPT-2-->>Notebook/Script: Return fallback answer
        Notebook/Script-->>User: Display fallback answer
    end
Loading

Possibly related PRs

Suggested labels

Review effort 2/5

Poem

In notebooks and scripts we hop anew,
With agents clever, learning grew!
From emissions green to code review,
And tutors wise to guide you through.
If one AI stumbles, another will do—
Rabbits rejoice, for knowledge is true!
🐇✨

✨ 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

@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 significantly broadens the scope of AI agent examples by adding three distinct new agents: a GitHub repository analyzer, a fuel emission estimator, and a personalized learning assistant. While the title specifically highlights the GitHub repo analyzer, the changes encompass a wider range of AI applications, showcasing the versatility of PraisonAI and OpenAI for different problem domains.

Highlights

  • New Feature: GitHub Repo Analyzer Agent: A new Jupyter notebook has been added that introduces an AI agent capable of analyzing GitHub repositories. It fetches repository structure using the GitHub API and summarizes its purpose via AI, designed for public repositories without authentication.
  • New Feature: Fuel Emission Estimator & Forecasting Agent: A new Jupyter notebook is included for an intelligent agent that calculates annual CO₂ emissions based on user driving patterns and vehicle type. It also forecasts how emissions would change with a switch to more fuel-efficient or hybrid vehicles.
  • New Feature: AI-Powered Personalized Learning Assistant: This pull request adds a Jupyter notebook and a corresponding Python script for a personalized learning assistant. This agent acts as a smart content chatbot, providing clear and helpful answers to learner questions, with a fallback mechanism to Hugging Face's GPT-2 if OpenAI is unavailable.
  • Code Structure Enhancement: The changes introduce multiple new examples of AI agents, demonstrating various applications of PraisonAI and OpenAI within the examples/cookbooks and examples/python/tools directories.
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.

@codecov
Copy link

codecov bot commented Jun 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 14.50%. Comparing base (f16fa2d) to head (f073e59).
Report is 177 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #683   +/-   ##
=======================================
  Coverage   14.50%   14.50%           
=======================================
  Files          25       25           
  Lines        2517     2517           
  Branches      357      357           
=======================================
  Hits          365      365           
  Misses       2136     2136           
  Partials       16       16           
Flag Coverage Δ
quick-validation 0.00% <ø> (ø)
unit-tests 14.50% <ø> (ø)

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 adds a new example notebook and a corresponding Python script for creating a personalized learning assistant. The changes involve setting up dependencies, configuring the OpenAI API key, initializing the AI agent, and creating an interactive chat loop. The feedback focuses on improving code readability by adding comments to explain the purpose of setting the environment variable.

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

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

39-39: LGTM! Consider pinning versions for reproducibility.

The dependency installation is correct. For production use, consider pinning specific versions to ensure reproducible builds.

-!pip install praisonaiagents openai requests
+!pip install praisonaiagents>=1.0.0 openai>=1.0.0 requests>=2.25.0

175-179: Good integration function with basic error handling.

The function effectively combines file fetching with agent analysis. The fallback error message is helpful for users.

Consider enhancing the error message to be more informative:

-        return "❌ Cannot fetch repo contents."
+        return "❌ Cannot fetch repo contents. Please check the URL and ensure it's a valid public GitHub repository."
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 51a8a5d and f073e59.

📒 Files selected for processing (4)
  • examples/cookbooks/Fuel_Emission_Agent_Intelligence_Agent.ipynb (1 hunks)
  • examples/cookbooks/github_repo_analyzer_agent.ipynb (1 hunks)
  • examples/cookbooks/personalized_learning_assistant.ipynb (1 hunks)
  • examples/python/tools/exa-tool/learning_assistant.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test-core (3.11)
  • GitHub Check: quick-test
🔇 Additional comments (12)
examples/python/tools/exa-tool/learning_assistant.py (3)

52-58: Well-implemented fallback mechanism.

The error handling and fallback to GPT-2 is properly implemented, ensuring robustness when the primary agent fails.


62-69: Interactive loop implementation is solid.

The while loop with proper exit conditions and user-friendly messaging provides a good user experience.


45-47: [web_search]

What is the recommended way to initialize the OpenAI API key in the latest OpenAI Python library?
examples/cookbooks/Fuel_Emission_Agent_Intelligence_Agent.ipynb (2)

78-81: Good security practice using getpass.

Using getpass for API key input properly protects sensitive credentials from being displayed in plain text.


105-119: Well-structured agent configuration.

The YAML-based agent configuration with clear role, goal, and tools specification follows good practices for agent setup.

examples/cookbooks/personalized_learning_assistant.ipynb (2)

306-311: Well-implemented fallback mechanism.

The chat_with_ai function properly handles exceptions and falls back to GPT-2, ensuring robust operation similar to the Python script version.


755-761: Good interactive chat implementation.

The chat loop with proper exit conditions provides a user-friendly interface for the learning assistant.

examples/cookbooks/github_repo_analyzer_agent.ipynb (5)

83-85: Excellent API key handling!

The implementation correctly avoids hardcoding sensitive credentials and uses interactive input, which is the recommended approach for notebooks.


105-109: Clean and appropriate imports.

All imports are necessary and properly structured. The OpenAI API key assignment follows the environment variable pattern established earlier.


129-132: Well-defined agent with clear instructions.

The agent configuration is appropriate with concise, clear instructions that align with the notebook's purpose.


445-446: Clean and user-friendly execution flow.

The interactive approach is perfect for a notebook demonstration, providing clear prompts and formatted output.


19-19: Verify the Colab badge URL points to the correct branch.

The Colab badge references the main branch of DhivyaBharathy-web/PraisonAI, but this appears to be a fork. Ensure this matches the intended repository structure.

#!/bin/bash
# Verify if the repository and branch exist
curl -s -o /dev/null -w "%{http_code}" https://raw.githubusercontent.com/DhivyaBharathy-web/PraisonAI/main/examples/cookbooks/github_repo_analyzer_agent.ipynb
# 4. 🔐 Set OpenAI API Key
# ============================
import os
os.environ['OPENAI_API_KEY'] = input('Enter your OpenAI API key: ')
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security issue: API key exposure in plain text.

Using input() to collect the OpenAI API key will display it in plain text, which is a security risk. Use getpass module instead for secure password input.

Apply this diff to fix the security issue:

+from getpass import getpass
import os
-os.environ['OPENAI_API_KEY'] = input('Enter your OpenAI API key: ')
+os.environ['OPENAI_API_KEY'] = getpass('🔐 Enter your OpenAI API key: ')
🤖 Prompt for AI Agents
In examples/python/tools/exa-tool/learning_assistant.py at line 38, replace the
use of input() for collecting the OpenAI API key with the getpass module's
getpass() function to prevent the API key from being displayed in plain text.
Import getpass at the top if not already imported, then use getpass.getpass() to
securely prompt the user for the API key and assign it to
os.environ['OPENAI_API_KEY'].
"id": "06ae55aa"
},
"source": [
"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/Fuel_Emission_Agent_Intelligence_Agent.ipynb)"
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

Fix repository reference in Colab badge.

The Colab badge URL points to a personal fork (DhivyaBharathy-web/PraisonAI) instead of the main repository. This should reference the official repository for consistency.

Update the URL to point to the main repository:

-"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/Fuel_Emission_Agent_Intelligence_Agent.ipynb)"
+"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/examples/cookbooks/Fuel_Emission_Agent_Intelligence_Agent.ipynb)"
📝 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
"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/Fuel_Emission_Agent_Intelligence_Agent.ipynb)"
"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/examples/cookbooks/Fuel_Emission_Agent_Intelligence_Agent.ipynb)"
🤖 Prompt for AI Agents
In examples/cookbooks/Fuel_Emission_Agent_Intelligence_Agent.ipynb at line 22,
the Colab badge URL references a personal fork repository. Update the URL to
point to the official main repository by replacing
"DhivyaBharathy-web/PraisonAI" with the correct main repository path to ensure
consistency and proper linking.
"id": "dSQ-cb--A7Ys"
},
"source": [
"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/personalized_learning_assistant.ipynb)\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

Fix repository reference in Colab badge.

Same issue as the fuel emission notebook - the Colab badge points to a personal fork instead of the main repository.

Update the URL to point to the main repository:

-"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/personalized_learning_assistant.ipynb)\n"
+"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/examples/cookbooks/personalized_learning_assistant.ipynb)\n"
📝 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
"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/personalized_learning_assistant.ipynb)\n"
"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/examples/cookbooks/personalized_learning_assistant.ipynb)\n"
🤖 Prompt for AI Agents
In examples/cookbooks/personalized_learning_assistant.ipynb at line 19, the
Colab badge URL incorrectly points to a personal fork repository. Update the URL
to reference the main repository instead by replacing the username and
repository path with the official main repository path in the badge link.
"outputs": [],
"source": [
"import os\n",
"os.environ['OPENAI_API_KEY'] = input('Enter your OpenAI API key: ')"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security issue: Use getpass for API key input.

Unlike the fuel emission notebook which correctly uses getpass, this notebook uses input() which exposes the API key in plain text. This creates inconsistency across examples and a security vulnerability.

Apply this diff to fix the security issue and maintain consistency:

-"os.environ['OPENAI_API_KEY'] = input('Enter your OpenAI API key: ')"
+"from getpass import getpass\n",
+"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['OPENAI_API_KEY'] = input('Enter your OpenAI API key: ')"
"from getpass import getpass\n",
"os.environ['OPENAI_API_KEY'] = getpass('🔐 Enter your OpenAI API key: ')"
🤖 Prompt for AI Agents
In examples/cookbooks/personalized_learning_assistant.ipynb at line 84, replace
the use of input() for entering the OpenAI API key with getpass.getpass() to
securely capture the key without displaying it on the screen. Import getpass if
not already imported, and assign the API key using os.environ['OPENAI_API_KEY']
= getpass.getpass('Enter your OpenAI API key: '). This change will prevent the
API key from being exposed in plain text and align with the security practice
used in the fuel emission notebook.
Comment on lines +152 to +155
"def fetch_repo_files(repo_url):\n",
" api_url = repo_url.replace(\"https://github.com\", \"https://api.github.com/repos\") + \"/contents\"\n",
" r = requests.get(api_url)\n",
" return [f[\"name\"] for f in r.json()] if r.status_code == 200 else []"
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

Enhance the repository file fetching with better error handling and broader coverage.

The current implementation has several limitations that affect the analyzer's effectiveness:

  1. Limited scope: Only fetches root-level files, missing important subdirectories
  2. No error handling: Network issues or malformed URLs will cause failures
  3. No authentication: Limited to public repositories only
  4. Rate limiting: GitHub API limits aren't handled
  5. URL validation: No validation of repository URL format
+import urllib.parse
+from typing import List, Optional

-def fetch_repo_files(repo_url):
-    api_url = repo_url.replace("https://github.com", "https://api.github.com/repos") + "/contents"
-    r = requests.get(api_url)
-    return [f["name"] for f in r.json()] if r.status_code == 200 else []
+def fetch_repo_files(repo_url: str, path: str = "") -> List[str]:
+    """Fetch repository files recursively with proper error handling."""
+    try:
+        # Validate and parse URL
+        if not repo_url.startswith("https://github.com/"):
+            return []
+        
+        api_url = repo_url.replace("https://github.com", "https://api.github.com/repos")
+        if path:
+            api_url += f"/contents/{path}"
+        else:
+            api_url += "/contents"
+            
+        headers = {"Accept": "application/vnd.github.v3+json"}
+        r = requests.get(api_url, headers=headers, timeout=10)
+        
+        if r.status_code != 200:
+            print(f"⚠️ API request failed: {r.status_code}")
+            return []
+            
+        files = []
+        for item in r.json():
+            if item["type"] == "file":
+                files.append(item["path"] if path else item["name"])
+            elif item["type"] == "dir" and len(files) < 50:  # Limit recursion
+                files.extend(fetch_repo_files(repo_url, item["path"]))
+                
+        return files
+        
+    except Exception as e:
+        print(f"❌ Error fetching repository files: {e}")
+        return []
📝 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
"def fetch_repo_files(repo_url):\n",
" api_url = repo_url.replace(\"https://github.com\", \"https://api.github.com/repos\") + \"/contents\"\n",
" r = requests.get(api_url)\n",
" return [f[\"name\"] for f in r.json()] if r.status_code == 200 else []"
import urllib.parse
from typing import List, Optional
def fetch_repo_files(repo_url: str, path: str = "") -> List[str]:
"""Fetch repository files recursively with proper error handling."""
try:
# Validate and parse URL
if not repo_url.startswith("https://github.com/"):
return []
api_url = repo_url.replace("https://github.com", "https://api.github.com/repos")
if path:
api_url += f"/contents/{path}"
else:
api_url += "/contents"
headers = {"Accept": "application/vnd.github.v3+json"}
r = requests.get(api_url, headers=headers, timeout=10)
if r.status_code != 200:
print(f"⚠️ API request failed: {r.status_code}")
return []
files: List[str] = []
for item in r.json():
if item["type"] == "file":
files.append(item["path"] if path else item["name"])
elif item["type"] == "dir" and len(files) < 50: # Limit recursion depth
files.extend(fetch_repo_files(repo_url, item["path"]))
return files
except Exception as e:
print(f"❌ Error fetching repository files: {e}")
return []
🤖 Prompt for AI Agents
In examples/cookbooks/github_repo_analyzer_agent.ipynb around lines 152 to 155,
improve the fetch_repo_files function by adding validation for the repo_url
format to ensure it is a valid GitHub repository URL. Implement error handling
to catch network errors and invalid responses gracefully. Add support for
authentication using a GitHub token to access private repositories and increase
rate limits. Modify the function to recursively fetch files from all
subdirectories, not just the root level, by traversing the contents API
responses. Also, handle GitHub API rate limiting by checking response headers
and retrying or backing off as needed.
@MervinPraison MervinPraison merged commit bdc5a9d into MervinPraison:main Jun 24, 2025
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants