Skip to content

Commit fa86ac8

Browse files
Merge pull request #684 from Dhivya-Bharathy/add-github-repo-analyzer-agent
Add GitHub repo analyzer agent
2 parents 15efb0a + e9f23e1 commit fa86ac8

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-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))
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# ===============================
2+
# 1. 📘 Project Title & Purpose
3+
# ===============================
4+
# """
5+
# AI‑Powered Personalized Learning Assistant with Smart Content Chatbot
6+
7+
# This assistant helps users learn any topic by chatting with an AI tutor.
8+
# It uses PraisonAI Agents, OpenAI API, and Transformers to deliver answers clearly.
9+
# """
10+
11+
# ============================
12+
# 2. 📦 Dependencies Required
13+
# ============================
14+
# """
15+
# Required Libraries:
16+
# - praisonaiagents
17+
# - openai
18+
# - transformers
19+
20+
# Make sure to install these in Colab or terminal:
21+
# !pip install praisonaiagents openai transformers
22+
# """
23+
24+
# =====================
25+
# 3. 🧰 Tools Used
26+
# =====================
27+
# """
28+
# ✅ praisonaiagents – Builds the smart tutoring agent
29+
# ✅ openai – Uses OpenAI GPT for accurate answers
30+
# ✅ transformers – Fallback model using GPT-2
31+
# ✅ Python I/O – Simple interactive CLI using input/print
32+
# """
33+
34+
# ============================
35+
# 4. 🔐 Set OpenAI API Key
36+
# ============================
37+
import os
38+
os.environ['OPENAI_API_KEY'] = input('Enter your OpenAI API key: ')
39+
40+
# ================================
41+
# 5. 🧠 Initialize AI Agent + Fallback
42+
# ================================
43+
from praisonaiagents import Agent
44+
from transformers import pipeline as hf_pipeline
45+
import openai
46+
47+
openai.api_key = os.getenv('OPENAI_API_KEY')
48+
hf_chatbot = hf_pipeline('text-generation', model='gpt2')
49+
50+
agent = Agent(instructions='You are a friendly tutor. Answer learner questions clearly and helpfully.')
51+
52+
def chat_with_ai(user_input):
53+
try:
54+
return agent.start(user_input)
55+
except Exception as e:
56+
print('[Fallback GPT-2]', e)
57+
return hf_chatbot(user_input, max_length=100)[0]['generated_text']
58+
59+
# ============================
60+
# 6. 💬 Interactive Chat Loop
61+
# ============================
62+
print("Start chatting with your AI tutor! Type 'exit' to quit.")
63+
while True:
64+
user_input = input('You: ')
65+
if user_input.lower() in ['exit', 'quit']:
66+
print('Goodbye! Happy learning!')
67+
break
68+
response = chat_with_ai(user_input)
69+
print('🤖 Tutor:', response)

0 commit comments

Comments
 (0)