feat: merge mgx_ops

This commit is contained in:
莘权 马 2024-04-30 11:41:37 +08:00
commit 81540fe4d9
13 changed files with 719 additions and 55 deletions

View file

@ -0,0 +1,78 @@
import asyncio
import threading
from metagpt.environment.mgx.mgx_env import MGXEnv
from metagpt.roles import (
Architect,
Engineer,
ProductManager,
ProjectManager,
QaEngineer,
)
from metagpt.roles.di.data_analyst import DataAnalyst
from metagpt.roles.di.team_leader import TeamLeader
from metagpt.schema import Message
async def main(requirement, enable_human_input=False):
env = MGXEnv()
env.add_roles(
[
TeamLeader(),
ProductManager(),
Architect(),
ProjectManager(),
Engineer(n_borg=5, use_code_review=False),
QaEngineer(),
DataAnalyst(tools=["<all>"]),
]
)
if enable_human_input:
# simulate human sending messages in chatbox
send_human_input(env)
env.publish_message(Message(content=requirement))
while not env.is_idle:
await env.run()
def send_human_input(env):
"""
Simulate sending message in chatbox
Note in local environment, the message is consumed only after current round of env.run is finished
"""
def send_messages():
while True:
message = input("Enter a message any time: ")
env.publish_message(Message(content=message))
# Start a thread for sending messages
send_thread = threading.Thread(target=send_messages, args=())
send_thread.start()
GAME_REQ = "create a 2048 game"
SIMPLE_REQ = "print statistic summary of sklearn iris dataset"
WINE_REQ = "Run data analysis on sklearn Wine recognition dataset, include a plot, and train a model to predict wine class (20% as validation), and show validation accuracy."
PAPER_LIST_REQ = """
Get data from `paperlist` table in https://papercopilot.com/statistics/iclr-statistics/iclr-2024-statistics/,
and save it to a csv file. paper title must include `multiagent` or `large language model`. *notice: print key variables*
"""
ECOMMERCE_REQ = """
Get products data from website https://scrapeme.live/shop/ and save it as a csv file.
**Notice: Firstly parse the web page encoding and the text HTML structure;
The first page product name, price, product URL, and image URL must be saved in the csv;**
"""
data_path = "data/titanic"
train_path = f"{data_path}/split_train.csv"
eval_path = f"{data_path}/split_eval.csv"
TITANIC_REQ = f"This is a titanic passenger survival dataset, your goal is to predict passenger survival outcome. The target column is Survived. Perform data analysis, data preprocessing, feature engineering, and modeling to predict the target. Report accuracy on the eval data. Train data path: '{train_path}', eval data path: '{eval_path}'."
if __name__ == "__main__":
# NOTE: Change the requirement to the one you want to test
# Set enable_human_input to True if you want to simulate sending messages in chatbox
asyncio.run(main(requirement=SIMPLE_REQ, enable_human_input=False))

View file

@ -1,7 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import annotations
import os
import pytest
from github import Auth, Github
from pydantic import BaseModel
from metagpt.tools.libs.git import git_checkout, git_clone
@ -13,10 +17,15 @@ class SWEBenchItem(BaseModel):
repo: str
def get_env(key):
return os.environ.get(key)
@pytest.mark.asyncio
@pytest.mark.parametrize(
["url", "commit_id"], [("https://github.com/sqlfluff/sqlfluff.git", "d19de0ecd16d298f9e3bfb91da122734c40c01e5")]
)
@pytest.mark.skip
async def test_git(url: str, commit_id: str):
repo_dir = await git_clone(url)
assert repo_dir
@ -27,5 +36,67 @@ async def test_git(url: str, commit_id: str):
repo.delete_repository()
@pytest.mark.skip
def test_login():
auth = Auth.Login(get_env("GITHUB_USER"), get_env("GITHUB_PWD"))
g = Github(auth=auth)
repo = g.get_repo("geekan/MetaGPT")
topics = repo.get_topics()
assert topics
open_issues = repo.get_issues(state="open")
issues = [i for i in open_issues]
assert issues
@pytest.mark.skip
@pytest.mark.asyncio
async def test_new_issue():
issue = await GitRepository.create_issue(
repo_name="iorisa/MetaGPT",
title="This is a new issue",
body="This is the issue body",
access_token=get_env("GITHUB_PERSONAL_ACCESS_TOKEN"),
)
print(issue)
assert issue.number
pass
@pytest.mark.skip
@pytest.mark.asyncio
async def test_new_pr():
body = """
>>> SUMMARY
>>> Change HTTP library used to send requests
>>>
>>> TESTS
>>> - [x] Send 'GET' request
>>> - [x] Send 'POST' request with/without body
"""
pr = await GitRepository.create_pull(
repo_name="iorisa/MetaGPT",
base="send18",
head="fixbug/gbk",
title="Test pr",
body=body,
access_token=get_env("GITHUB_PERSONAL_ACCESS_TOKEN"),
)
print(pr)
assert pr
@pytest.mark.skip
def test_auth():
access_token = get_env("GITHUB_PERSONAL_ACCESS_TOKEN")
auth = Auth.Token(access_token)
g = Github(auth=auth)
u = g.get_user()
v = u.get_repos(visibility="public")
a = [i.full_name for i in v]
assert a
print(a)
pass
if __name__ == "__main__":
pytest.main([__file__, "-s"])