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

[MRG] support mle report <org/repo> command #167

Merged
merged 1 commit into from
Sep 3, 2024
Merged
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
45 changes: 35 additions & 10 deletions mle/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import yaml
import click
import pickle
Expand All @@ -10,10 +11,10 @@
from rich.markdown import Markdown

import mle
import mle.workflow as workflow
from mle.utils import Memory
from mle.model import load_model
from mle.agents import CodeAgent
from mle.workflow import baseline, report
from mle.utils.system import get_config, write_config

console = Console()
Expand Down Expand Up @@ -59,12 +60,40 @@ def start(mode, model):
if not check_config():
return

if mode == 'report':
# Report mode
return report(os.getcwd(), model)
else:
if mode == 'general':
# Baseline mode
return baseline(os.getcwd(), model)
return workflow.baseline(os.getcwd(), model)


@cli.command()
@click.pass_context
@click.argument('repo', required=False)
@click.option('--model', default=None, help='The model to use for the chat.')
def report(ctx, repo, model):
"""
report: generate report with LLM.
"""
if repo is None:
# TODO: support local project report
repo = questionary.text(
"What is your GitHub repository? (e.g., MLSysOps/MLE-agent)"
).ask()

if not re.match(r'.*/.*', repo):
console.log("Invalid github repository, "
"Usage: 'mle report <organization/name>'")
return False

if not check_config():
# build a new project for github report generating
project_name = f"mle-report-{repo.replace('/', '_').lower()}"
ctx.invoke(new, name=project_name)
# enter the new project for report generation
work_dir = os.path.join(os.getcwd(), project_name)
huangyz0918 marked this conversation as resolved.
Show resolved Hide resolved
os.chdir(work_dir)
return workflow.report(work_dir, repo, model)

return workflow.report(os.getcwd(), repo, model)


@cli.command()
Expand Down Expand Up @@ -159,13 +188,9 @@ def integrate():
token = questionary.password(
"What is your GitHub token? (https://github.com/settings/tokens)"
).ask()
repos = questionary.text(
"What are your working repositories? (e.g., MLSysOps/MLE-agent)"
).ask()

config["integration"]["github"] = {
"token": token,
"repositories": repos.split(","),
}
write_config(config)

Expand Down
72 changes: 18 additions & 54 deletions mle/workflow/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"""
import os
import json
import pickle
import datetime
import questionary
from rich.console import Console
from mle.model import load_model
from mle.agents import SummaryAgent
from mle.utils import print_in_box, ask_text, get_config
from mle.utils import print_in_box, ask_text
from mle.utils.system import get_config, write_config


def ask_data(data_str: str):
Expand All @@ -24,70 +24,34 @@ def ask_data(data_str: str):
return f"[green]Dataset:[/green] {data_str}"


def get_current_week_github_activities():
def ask_github_token():
"""
Get user's Github activities on this week.
Ask the user to integrate github.
:return: the github token.
"""
config = get_config()
if not (config.get("integration") and config["integration"].get("github")):
return None
config = get_config() or {}
if "integration" not in config.keys():
config["integration"] = {}

token = config["integration"]["github"]["token"]
repos = config["integration"]["github"]["repositories"]
current_date = datetime.date.today()
if "github" not in config["integration"].keys():
token = questionary.password(
"What is your GitHub token? (https://github.com/settings/tokens)"
).ask()

from mle.integration.github import GitHubIntegration
activities = {}
for repo in repos:
github = GitHubIntegration(repo, token)
start_date = current_date - datetime.timedelta(days=current_date.weekday())
activities[repo] = github.get_user_activity(
username=github.get_user_info()["login"],
start_date=start_date.strftime('%Y-%m-%d'),
)
return activities
config["integration"]["github"] = {"token": token}
write_config(config)

return config["integration"]["github"]["token"]

def get_current_week_google_calendar_activities():
"""
Get user's google calendar events on this week.
"""
config = get_config()
if not (config.get("integration") and config["integration"].get("google_calendar")):
return None

# refresh google calendar activities
token = pickle.loads(config["integration"]["google_calendar"]["token"])
current_date = datetime.date.today()

from mle.integration.google_calendar import GoogleCalendarIntegration
google_calendar = GoogleCalendarIntegration(token)
start_date = current_date - datetime.timedelta(days=current_date.weekday())
end_date = start_date + datetime.timedelta(days=6)
return google_calendar.get_events(
start_date=start_date.strftime('%Y-%m-%d'),
end_date=end_date.strftime('%Y-%m-%d'),
)


def report(work_dir: str, model=None):
def report(work_dir: str, github_repo: str, model=None):
"""
The workflow of the baseline mode.
:return:
"""

console = Console()
model = load_model(work_dir, model)

# fetch activities
# github_activities = get_current_week_github_activities()
# google_calendar_activities = get_current_week_google_calendar_activities()

github_repo = ask_text("Please provide your github repository (organization/name)")
if not github_repo:
print_in_box("The user's github_repo is empty. Aborted", console, title="Error", color="red")
return

summarizer = SummaryAgent(model, github_repo=github_repo)
summarizer = SummaryAgent(model, github_repo=github_repo, github_token=ask_github_token())
github_summary = summarizer.summarize()
print_in_box(json.dumps(github_summary), console, title="Github Summarizer", color="green")
Loading