-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Create a simple webui with gradio #316
base: main
Are you sure you want to change the base?
Conversation
Created a simple web ui application using Gradio. Modified some of the code for environment and company, adding two private variables for environment. One is used to temporarily store history for displaying to users and accepting user modifications, and the other indicates the environment type. After testing, it will not affect normal operation through the startup way. |
你好。提交的程序请遵守PEP8 |
代码已进行修改,请看看是否还有需要调整的地方 |
metagpt/app.py
Outdated
|
||
def clear_logs(): | ||
with open(PROJECT_ROOT / 'logs/log.txt', 'w') as f: | ||
f.write("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
place the function in proper file
with open(PROJECT_ROOT / 'logs/log.txt', 'w') as f: | ||
f.write("") | ||
|
||
async def startup(company_name : str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8. 可以尝试使用PyCharm自带的format或者black / flake8
metagpt/app.py
Outdated
investment : float = 6.0, | ||
n_round : int = 5, | ||
code_review : bool = True, | ||
staffs : list = ["ProjectManager", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
避免在函数的入参中初始化list
metagpt/app.py
Outdated
company.invest(investment) | ||
company.start_project(idea) | ||
# report all output to webui | ||
global SoftwareCompany_Company |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
避免使用global成员,只在不得不使用时才使用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我尝试了一下不使用全局变量,发现会比较难实现,可能需要将SoftwareCompany改为单例模式。另外,我参考了一些别的项目的gradio webui设计,发现有的也使用了全局变量。所以我希望能被允许在这里使用全局变量
metagpt/app.py
Outdated
await company.run(n_round) | ||
elif company_name == "SoftwareCompany_With_Human": | ||
await company.continue_run() | ||
return "Role: "+company.environment.short_term_history.role,\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
避免出现长return,而是使用恰当的class装载
metagpt/app.py
Outdated
with gr.Tabs(): | ||
with gr.TabItem("MetaGPT") as generate_tab: | ||
company_choise = gr.Dropdown(label = "Choose the company type",\ | ||
choices = ["SoftwareCompany", "SoftwareCompany_With_Human"],\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上面的class改了,但是这里的风格还是非PEP8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请问这里应该如何修改为PEP8风格?是这样吗?
with gr.TabItem("MetaGPT") as generate_tab:
company_choise = gr.Dropdown(
label = "Choose the company type",
choices = ["SoftwareCompany", "SoftwareCompany_With_Human"],
value = "SoftwareCompany_With_Human"
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ori-Replication 指的是字符串:class驼峰,函数下划线,但是两种风格不能混用。并且字符串与class name需要对应
metagpt/app_chs.py
Outdated
""" | ||
@Time : 2023/9/19 17:12 | ||
@Author : ORI_Replication | ||
@File : app_chs.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一般而言,i18n的最佳方法是独立k个语言文件,或者一个大的EXCEL / JSON,用来做槽位与指定语言的映射。不推荐copy & paste代码来解决这个问题,因为它的维护成本太高了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
暂时先取消中文版,等我有时间,后续版本做一下
metagpt/environment.py
Outdated
""" | ||
|
||
environment_type: str = Field(default='SoftwareCompany') | ||
short_term_history: str = Field(default_factory=Memory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里short_term_history声明Memory,但是在使用Message的方式对待它。或许不声明这个变量,而是在Memory中解决这个会更好
metagpt/environment.py
Outdated
""" | ||
|
||
environment_type: str = Field(default='SoftwareCompany') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type同样可以成为一个成员
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现在environment没有__init__ 函数,我是否可以进行定义?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ori-Replication 我的意思是:不一定需要使用字符串来表达类型。表达类型的最佳实践是使用类型本身,或者使用enum
metagpt/software_company.py
Outdated
|
||
class SoftwareCompanyWithHuman(BaseModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果改动偏小,我建议与原始SoftwareCompany合并
需要解决conflicts |
metagpt/app_chs.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除中文版
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除SoftwareCompanyWithHuman类
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 修改了short_term_memory的类型,成为了message类型
- 将环境类型改为human_interaction变量,如果为True,则不直接将message储存到记忆中与历史中,而是在用户修改后再储存。在app.py中有具体实现方式
我不太会解决这个conflict。在这一版中我将新增的一些需求的包加入进来了,但还是显示有冲突,显示我添加的gradio包有冲突。我不太会解决,请问该如何解决?
|
使用gradio创建了一个简单的webui应用。
修改了部分environment和company的代码,为environment新增了两个私有变量,一个用来临时储存history,来展示给用户和接受用户修改,另一个标明environment类型。经测试不会影响正常通过startup途径运行。