From 53afe146b818342ec31b373f46a0bd94dc36a67a Mon Sep 17 00:00:00 2001
From: femto
Date: Sun, 24 Sep 2023 14:18:03 +0800
Subject: [PATCH 1/8] fix ltm serialize_message
---
metagpt/utils/serialize.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/metagpt/utils/serialize.py b/metagpt/utils/serialize.py
index ffafca8cd..943def839 100644
--- a/metagpt/utils/serialize.py
+++ b/metagpt/utils/serialize.py
@@ -4,7 +4,7 @@
import copy
import pickle
-from typing import Dict, List, Tuple
+from typing import Dict, List
from metagpt.actions.action_output import ActionOutput
from metagpt.schema import Message
@@ -38,7 +38,7 @@ def actionoutout_schema_to_mapping(schema: Dict) -> Dict:
mapping[field] = (List[str], ...)
elif property["type"] == "array" and property["items"]["type"] == "array":
# here only consider the `Tuple[str, str]` situation
- mapping[field] = (List[Tuple[str, str]], ...)
+ mapping[field] = (List[List[str]], ...)
return mapping
From 04cf32e1ac13b376fe8ff64db9ad26b92c59ee9d Mon Sep 17 00:00:00 2001
From: femto
Date: Mon, 25 Sep 2023 13:36:34 +0800
Subject: [PATCH 2/8] fix ltm serialize_message
---
metagpt/utils/serialize.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/metagpt/utils/serialize.py b/metagpt/utils/serialize.py
index 943def839..124176fcb 100644
--- a/metagpt/utils/serialize.py
+++ b/metagpt/utils/serialize.py
@@ -37,7 +37,7 @@ def actionoutout_schema_to_mapping(schema: Dict) -> Dict:
elif property["type"] == "array" and property["items"]["type"] == "string":
mapping[field] = (List[str], ...)
elif property["type"] == "array" and property["items"]["type"] == "array":
- # here only consider the `Tuple[str, str]` situation
+ # here only consider the `List[List[str]]` situation
mapping[field] = (List[List[str]], ...)
return mapping
From 6091f1dd7376987d2dfca6b03130f02300c2507c Mon Sep 17 00:00:00 2001
From: femto
Date: Tue, 26 Sep 2023 12:21:46 +0800
Subject: [PATCH 3/8] fix parse
---
metagpt/actions/design_api.py | 6 ++++++
metagpt/utils/common.py | 4 ++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/metagpt/actions/design_api.py b/metagpt/actions/design_api.py
index f19fcbeaa..75df8b909 100644
--- a/metagpt/actions/design_api.py
+++ b/metagpt/actions/design_api.py
@@ -207,5 +207,11 @@ class WriteDesign(Action):
prompt = prompt_template.format(context=context, format_example=format_example)
# system_design = await self._aask(prompt)
system_design = await self._aask_v1(prompt, "system_design", OUTPUT_MAPPING, format=format)
+ # fix Python package name, we can't system_design.instruct_content.python_package_name = "xxx" since "Python package name" contain space, have to use setattr
+ setattr(
+ system_design.instruct_content,
+ "Python package name",
+ system_design.instruct_content.dict()["Python package name"].strip().strip("'").strip('"'),
+ )
await self._save(context, system_design)
return system_design
diff --git a/metagpt/utils/common.py b/metagpt/utils/common.py
index 65cc15e82..59d179808 100644
--- a/metagpt/utils/common.py
+++ b/metagpt/utils/common.py
@@ -180,7 +180,7 @@ class OutputParser:
if start_index != -1 and end_index != -1:
# Extract the structure part
- structure_text = text[start_index:end_index + 1]
+ structure_text = text[start_index : end_index + 1]
try:
# Attempt to convert the text to a Python data type using ast.literal_eval
@@ -237,7 +237,7 @@ class CodeParser:
logger.error(f"{pattern} not match following text:")
logger.error(text)
# raise Exception
- return ""
+ return text # just assume original text is code
return code
@classmethod
From 8f5deffbf43278296a75b7366fb3fb9185d3c9ce Mon Sep 17 00:00:00 2001
From: voidking
Date: Wed, 27 Sep 2023 18:59:40 +0800
Subject: [PATCH 4/8] update docker image to lastest
---
README.md | 8 ++++----
docs/README_CN.md | 10 +++++-----
docs/README_JA.md | 8 ++++----
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/README.md b/README.md
index 91a5483e0..c573fbfbe 100644
--- a/README.md
+++ b/README.md
@@ -162,9 +162,9 @@ ### Installation by Docker
```bash
# Step 1: Download metagpt official image and prepare config.yaml
-docker pull metagpt/metagpt:v0.3.1
+docker pull metagpt/metagpt:latest
mkdir -p /opt/metagpt/{config,workspace}
-docker run --rm metagpt/metagpt:v0.3.1 cat /app/metagpt/config/config.yaml > /opt/metagpt/config/key.yaml
+docker run --rm metagpt/metagpt:latest cat /app/metagpt/config/config.yaml > /opt/metagpt/config/key.yaml
vim /opt/metagpt/config/key.yaml # Change the config
# Step 2: Run metagpt demo with container
@@ -172,7 +172,7 @@ # Step 2: Run metagpt demo with container
--privileged \
-v /opt/metagpt/config/key.yaml:/app/metagpt/config/key.yaml \
-v /opt/metagpt/workspace:/app/metagpt/workspace \
- metagpt/metagpt:v0.3.1 \
+ metagpt/metagpt:latest \
python startup.py "Write a cli snake game"
# You can also start a container and execute commands in it
@@ -180,7 +180,7 @@ # You can also start a container and execute commands in it
--privileged \
-v /opt/metagpt/config/key.yaml:/app/metagpt/config/key.yaml \
-v /opt/metagpt/workspace:/app/metagpt/workspace \
- metagpt/metagpt:v0.3.1
+ metagpt/metagpt:latest
docker exec -it metagpt /bin/bash
$ python startup.py "Write a cli snake game"
diff --git a/docs/README_CN.md b/docs/README_CN.md
index 1372bf9f4..d06dda620 100644
--- a/docs/README_CN.md
+++ b/docs/README_CN.md
@@ -87,9 +87,9 @@ ### Docker安装
```bash
# 步骤1: 下载metagpt官方镜像并准备好config.yaml
-docker pull metagpt/metagpt:v0.3
+docker pull metagpt/metagpt:latest
mkdir -p /opt/metagpt/{config,workspace}
-docker run --rm metagpt/metagpt:v0.3 cat /app/metagpt/config/config.yaml > /opt/metagpt/config/config.yaml
+docker run --rm metagpt/metagpt:latest cat /app/metagpt/config/config.yaml > /opt/metagpt/config/config.yaml
vim /opt/metagpt/config/config.yaml # 修改config
# 步骤2: 使用容器运行metagpt演示
@@ -97,7 +97,7 @@ # 步骤2: 使用容器运行metagpt演示
--privileged \
-v /opt/metagpt/config:/app/metagpt/config \
-v /opt/metagpt/workspace:/app/metagpt/workspace \
- metagpt/metagpt:v0.3 \
+ metagpt/metagpt:latest \
python startup.py "Write a cli snake game"
# 您也可以启动一个容器并在其中执行命令
@@ -105,7 +105,7 @@ # 您也可以启动一个容器并在其中执行命令
--privileged \
-v /opt/metagpt/config:/app/metagpt/config \
-v /opt/metagpt/workspace:/app/metagpt/workspace \
- metagpt/metagpt:v0.3
+ metagpt/metagpt:latest
docker exec -it metagpt /bin/bash
$ python startup.py "Write a cli snake game"
@@ -123,7 +123,7 @@ ### 自己构建镜像
```bash
# 您也可以自己构建metagpt镜像
git clone https://github.com/geekan/MetaGPT.git
-cd MetaGPT && docker build -t metagpt:v0.3 .
+cd MetaGPT && docker build -t metagpt:custom .
```
## 配置
diff --git a/docs/README_JA.md b/docs/README_JA.md
index 8d6c2fe84..6bd667a94 100644
--- a/docs/README_JA.md
+++ b/docs/README_JA.md
@@ -92,9 +92,9 @@ ### Docker によるインストール
```bash
# ステップ 1: metagpt 公式イメージをダウンロードし、config.yaml を準備する
-docker pull metagpt/metagpt:v0.3.1
+docker pull metagpt/metagpt:latest
mkdir -p /opt/metagpt/{config,workspace}
-docker run --rm metagpt/metagpt:v0.3.1 cat /app/metagpt/config/config.yaml > /opt/metagpt/config/key.yaml
+docker run --rm metagpt/metagpt:latest cat /app/metagpt/config/config.yaml > /opt/metagpt/config/key.yaml
vim /opt/metagpt/config/key.yaml # 設定を変更する
# ステップ 2: コンテナで metagpt デモを実行する
@@ -102,7 +102,7 @@ # ステップ 2: コンテナで metagpt デモを実行する
--privileged \
-v /opt/metagpt/config/key.yaml:/app/metagpt/config/key.yaml \
-v /opt/metagpt/workspace:/app/metagpt/workspace \
- metagpt/metagpt:v0.3.1 \
+ metagpt/metagpt:latest \
python startup.py "Write a cli snake game"
# コンテナを起動し、その中でコマンドを実行することもできます
@@ -110,7 +110,7 @@ # コンテナを起動し、その中でコマンドを実行することもで
--privileged \
-v /opt/metagpt/config/key.yaml:/app/metagpt/config/key.yaml \
-v /opt/metagpt/workspace:/app/metagpt/workspace \
- metagpt/metagpt:v0.3.1
+ metagpt/metagpt:latest
docker exec -it metagpt /bin/bash
$ python startup.py "Write a cli snake game"
From 3942e13c8c22c39f98debf5cd7005edd7509ba19 Mon Sep 17 00:00:00 2001
From: Sirui Hong <34952977+stellaHSR@users.noreply.github.com>
Date: Wed, 4 Oct 2023 23:58:38 +0800
Subject: [PATCH 5/8] Update README.md
update twitter url
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index c573fbfbe..c326190b0 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ # MetaGPT: The Multi-Agent Framework
-
+
From 8e96d51d107bd13a550063ff5de4c9a338061c93 Mon Sep 17 00:00:00 2001
From: Sirui Hong <34952977+stellaHSR@users.noreply.github.com>
Date: Wed, 4 Oct 2023 23:59:07 +0800
Subject: [PATCH 6/8] Update README_CN.md
update twitter info
---
docs/README_CN.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/README_CN.md b/docs/README_CN.md
index d06dda620..7a27a0e59 100644
--- a/docs/README_CN.md
+++ b/docs/README_CN.md
@@ -15,7 +15,7 @@ # MetaGPT: 多智能体框架
-
+
From e822093465809c5e15108f6cfe81d65da060660d Mon Sep 17 00:00:00 2001
From: Sirui Hong <34952977+stellaHSR@users.noreply.github.com>
Date: Wed, 4 Oct 2023 23:59:59 +0800
Subject: [PATCH 7/8] Update README_JA.md
update twitter info
---
docs/README_JA.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/README_JA.md b/docs/README_JA.md
index 6bd667a94..eab69d912 100644
--- a/docs/README_JA.md
+++ b/docs/README_JA.md
@@ -15,7 +15,7 @@ # MetaGPT: マルチエージェントフレームワーク
-
+
From 304a03244c66affc575acadea340f93d9ae25b66 Mon Sep 17 00:00:00 2001
From: zhanglei
Date: Sat, 7 Oct 2023 16:56:19 +0800
Subject: [PATCH 8/8] =?UTF-8?q?add=EF=BC=9A=201.moderation=20tools=202.uni?=
=?UTF-8?q?ttest?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
metagpt/tools/moderation.py | 40 ++++++++++++++++++++++++
tests/metagpt/tools/test_moderation.py | 42 ++++++++++++++++++++++++++
2 files changed, 82 insertions(+)
create mode 100644 metagpt/tools/moderation.py
create mode 100644 tests/metagpt/tools/test_moderation.py
diff --git a/metagpt/tools/moderation.py b/metagpt/tools/moderation.py
new file mode 100644
index 000000000..c56a6afc4
--- /dev/null
+++ b/metagpt/tools/moderation.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@Time : 2023/9/26 14:27
+@Author : zhanglei
+@File : moderation.py
+"""
+from typing import Union
+
+from metagpt.llm import LLM
+
+
+class Moderation:
+ def __init__(self):
+ self.llm = LLM()
+
+ def moderation(self, content: Union[str, list[str]]):
+ resp = []
+ if content:
+ moderation_results = self.llm.moderation(content=content)
+ results = moderation_results.results
+ for item in results:
+ resp.append(item.flagged)
+
+ return resp
+
+ async def amoderation(self, content: Union[str, list[str]]):
+ resp = []
+ if content:
+ moderation_results = await self.llm.amoderation(content=content)
+ results = moderation_results.results
+ for item in results:
+ resp.append(item.flagged)
+
+ return resp
+
+
+if __name__ == "__main__":
+ moderation = Moderation()
+ print(moderation.moderation(content=["I will kill you", "The weather is really nice today", "I want to hit you"]))
diff --git a/tests/metagpt/tools/test_moderation.py b/tests/metagpt/tools/test_moderation.py
new file mode 100644
index 000000000..225acff75
--- /dev/null
+++ b/tests/metagpt/tools/test_moderation.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@Time : 2023/9/26 14:46
+@Author : zhanglei
+@File : test_translate.py
+"""
+
+import pytest
+
+from metagpt.tools.moderation import Moderation
+
+
+@pytest.mark.parametrize(
+ ("content",),
+ [
+ [
+ ["I will kill you", "The weather is really nice today", "I want to hit you"],
+ ]
+ ],
+)
+def test_moderation(content):
+ moderation = Moderation()
+ results = moderation.moderation(content=content)
+ assert isinstance(results, list)
+ assert len(results) == len(content)
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+ ("content",),
+ [
+ [
+ ["I will kill you", "The weather is really nice today", "I want to hit you"],
+ ]
+ ],
+)
+async def test_amoderation(content):
+ moderation = Moderation()
+ results = await moderation.amoderation(content=content)
+ assert isinstance(results, list)
+ assert len(results) == len(content)