Skip to content

Commit e9f23e1

Browse files
Add GitHub Repo Analyzer Agent example
1 parent cc5e254 commit e9f23e1

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# # -*- coding: utf-8 -*-
2+
# """github_repo_analyzer_agent.ipynb
3+
4+
# Automatically generated by Colab.
5+
6+
# Original file is located at
7+
# https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/github_repo_analyzer_agent.ipynb
8+
9+
# # 🤖 GitHub Repo Analyzer Agent
10+
# AI agent powered by PraisonAI and OpenAI to analyze GitHub repositories using GitHub API.
11+
12+
# [![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/github_repo_analyzer_agent.ipynb)
13+
14+
# # 📦 Install dependencies
15+
# """
16+
17+
# !pip install praisonaiagents openai requests
18+
19+
# """# Tools Used
20+
21+
# 🧠 praisonaiagents – Smart AI agent
22+
23+
# 🔗 openai – GPT-powered responses
24+
25+
# 📂 requests – GitHub repo analysis
26+
27+
# 🖥️ Python I/O – Interactive CLI in notebook
28+
29+
# # 🔐 Set OpenAI API Key
30+
# """
31+
32+
import os
33+
if not os.getenv("OPENAI_API_KEY"):
34+
os.environ["OPENAI_API_KEY"] = input("🔐 Enter your OpenAI API key: ")
35+
36+
# """# 🧠 Imports"""
37+
38+
import requests
39+
import openai
40+
from praisonaiagents import Agent
41+
42+
openai.api_key = os.environ["OPENAI_API_KEY"]
43+
44+
# """# 🤖 Create the Agent"""
45+
46+
agent = Agent(instructions="""
47+
You are a GitHub codebase explainer. When given a repo URL, fetch summary of
48+
its files and provide insightful analysis. Be helpful and concise.
49+
""")
50+
51+
# """# 📂 Fetch GitHub repo file names"""
52+
53+
def fetch_repo_files(repo_url):
54+
api_url = repo_url.replace("https://github.com", "https://api.github.com/repos") + "/contents"
55+
r = requests.get(api_url)
56+
return [f["name"] for f in r.json()] if r.status_code == 200 else []
57+
58+
# """# 💬 Ask Agent"""
59+
60+
def ask_agent(repo_url):
61+
files = fetch_repo_files(repo_url)
62+
if not files:
63+
return "❌ Cannot fetch repo contents."
64+
return agent.start(f"Repo contains files: {files}. Analyze key components and structure.")
65+
66+
# """# 🧪 Run the agent"""
67+
68+
repo = input("🔗 Enter GitHub repository URL: ")
69+
print("\n🧠 Agent Insight:\n", ask_agent(repo))

0 commit comments

Comments
 (0)