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

Create a simple webui with gradio #316

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

Ori-Replication
Copy link

使用gradio创建了一个简单的webui应用。
修改了部分environment和company的代码,为environment新增了两个私有变量,一个用来临时储存history,来展示给用户和接受用户修改,另一个标明environment类型。经测试不会影响正常通过startup途径运行。

@Ori-Replication
Copy link
Author

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.

@geekan
Copy link
Owner

geekan commented Sep 19, 2023

你好。提交的程序请遵守PEP8

@Ori-Replication
Copy link
Author

你好。提交的程序请遵守PEP8

代码已进行修改,请看看是否还有需要调整的地方

metagpt/app.py Outdated

def clear_logs():
with open(PROJECT_ROOT / 'logs/log.txt', 'w') as f:
f.write("")
Copy link
Owner

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,
Copy link
Owner

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",
Copy link
Owner

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

避免使用global成员,只在不得不使用时才使用

Copy link
Author

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,\
Copy link
Owner

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"],\
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面的class改了,但是这里的风格还是非PEP8

Copy link
Author

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"
                )

Copy link
Owner

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需要对应

"""
@Time : 2023/9/19 17:12
@Author : ORI_Replication
@File : app_chs.py
Copy link
Owner

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代码来解决这个问题,因为它的维护成本太高了

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

暂时先取消中文版,等我有时间,后续版本做一下

"""

environment_type: str = Field(default='SoftwareCompany')
short_term_history: str = Field(default_factory=Memory)
Copy link
Owner

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中解决这个会更好

"""

environment_type: str = Field(default='SoftwareCompany')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type同样可以成为一个成员

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在environment没有__init__ 函数,我是否可以进行定义?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ori-Replication 我的意思是:不一定需要使用字符串来表达类型。表达类型的最佳实践是使用类型本身,或者使用enum


class SoftwareCompanyWithHuman(BaseModel):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果改动偏小,我建议与原始SoftwareCompany合并

@geekan
Copy link
Owner

geekan commented Sep 28, 2023

需要解决conflicts

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除中文版

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除SoftwareCompanyWithHuman类

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 修改了short_term_memory的类型,成为了message类型
  2. 将环境类型改为human_interaction变量,如果为True,则不直接将message储存到记忆中与历史中,而是在用户修改后再储存。在app.py中有具体实现方式

@Ori-Replication
Copy link
Author

我不太会解决这个conflict。在这一版中我将新增的一些需求的包加入进来了,但还是显示有冲突,显示我添加的gradio包有冲突。我不太会解决,请问该如何解决?

pytest-mock==3.11.1
open-interpreter==0.1.4; python_version>"3.9"
ta==0.10.2
semantic-kernel==0.3.10.dev0
<<<<<<< main
gradio==2.3.6
=======

>>>>>>> main

需要解决conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants