Skip to content
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

Readme generator agent #1636

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cookbook/agents/47_readme_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.github import GithubTools

readme_gen_agent = Agent(
model=OpenAIChat(id="gpt-4o"),
name="Readme Generator Agent",
tools=[GithubTools()],
markdown=True,
debug_mode=True,
instructions=[
"You are readme generator agent",
"You'll be given repository url or repository name from user."
"You'll use the `get_repository` tool to get the repository details."
"You have to pass the repo_name as argument to the tool. It should be in the format of owner/repo_name. If given url extract owner/repo_name from it."
"Also call the `get_repository_languages` tool to get the languages used in the repository."
"For now only print the response as given don't convert it to md",
],
)

readme_gen_agent.print_response("Get details of https://github.com/phidatahq/phidata", markdown=True)
25 changes: 25 additions & 0 deletions phi/tools/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(
get_pull_request: bool = True,
get_pull_request_changes: bool = True,
create_issue: bool = True,
get_repository_languages: bool = True,
):
super().__init__(name="github")

Expand All @@ -45,9 +46,15 @@ def __init__(
self.register(self.get_pull_request_changes)
if create_issue:
self.register(self.create_issue)
if get_repository_languages:
self.register(self.get_repository_languages)

def authenticate(self):
"""Authenticate with GitHub using the provided access token."""

if not self.access_token: # Fixes lint type error
raise ValueError("GitHub access token is required")

auth = Auth.Token(self.access_token)
if self.base_url:
logger.debug(f"Authenticating with GitHub Enterprise at {self.base_url}")
Expand Down Expand Up @@ -130,6 +137,24 @@ def get_repository(self, repo_name: str) -> str:
logger.error(f"Error getting repository: {e}")
return json.dumps({"error": str(e)})

def get_repository_languages(self, repo_name: str) -> str:
"""Get the languages used in a repository.

Args:
repo_name (str): The full name of the repository (e.g., 'owner/repo').

Returns:
A JSON-formatted string containing the list of languages.
"""
logger.debug(f"Getting languages for repository: {repo_name}")
try:
repo = self.g.get_repo(repo_name)
languages = repo.get_languages()
return json.dumps(languages, indent=2)
except GithubException as e:
logger.error(f"Error getting repository languages: {e}")
return json.dumps({"error": str(e)})

def list_pull_requests(self, repo_name: str, state: str = "open") -> str:
"""List pull requests for a repository.

Expand Down
Loading