From cb01e42645eeb0580db82ee1c1d875e2fe14fd78 Mon Sep 17 00:00:00 2001 From: geekan Date: Mon, 8 Jan 2024 20:02:37 +0800 Subject: [PATCH 1/4] fix memory --- tests/metagpt/memory/test_longterm_memory.py | 8 +++----- tests/metagpt/memory/test_memory.py | 2 +- tests/metagpt/memory/test_memory_storage.py | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/metagpt/memory/test_longterm_memory.py b/tests/metagpt/memory/test_longterm_memory.py index 0f7a4fac4..a9ef56bad 100644 --- a/tests/metagpt/memory/test_longterm_memory.py +++ b/tests/metagpt/memory/test_longterm_memory.py @@ -10,17 +10,15 @@ import os import pytest from metagpt.actions import UserRequirement -from metagpt.config import CONFIG +from metagpt.config2 import config from metagpt.memory.longterm_memory import LongTermMemory from metagpt.roles.role import RoleContext from metagpt.schema import Message +os.environ.setdefault("OPENAI_API_KEY", config.get_openai_llm().api_key) + def test_ltm_search(): - assert hasattr(CONFIG, "long_term_memory") is True - os.environ.setdefault("OPENAI_API_KEY", CONFIG.openai_api_key) - assert len(CONFIG.openai_api_key) > 20 - role_id = "UTUserLtm(Product Manager)" from metagpt.environment import Environment diff --git a/tests/metagpt/memory/test_memory.py b/tests/metagpt/memory/test_memory.py index 36d7ad488..a072b61de 100644 --- a/tests/metagpt/memory/test_memory.py +++ b/tests/metagpt/memory/test_memory.py @@ -32,7 +32,7 @@ def test_memory(): messages = memory.get_by_action(UserRequirement) assert len(messages) == 2 - messages = memory.get_by_actions([UserRequirement]) + messages = memory.get_by_actions({UserRequirement}) assert len(messages) == 2 messages = memory.try_remember("test message") diff --git a/tests/metagpt/memory/test_memory_storage.py b/tests/metagpt/memory/test_memory_storage.py index 0eb1069d5..e82a82fc8 100644 --- a/tests/metagpt/memory/test_memory_storage.py +++ b/tests/metagpt/memory/test_memory_storage.py @@ -11,12 +11,12 @@ from typing import List from metagpt.actions import UserRequirement, WritePRD from metagpt.actions.action_node import ActionNode -from metagpt.config import CONFIG +from metagpt.config2 import config from metagpt.const import DATA_PATH from metagpt.memory.memory_storage import MemoryStorage from metagpt.schema import Message -os.environ.setdefault("OPENAI_API_KEY", CONFIG.openai_api_key) +os.environ.setdefault("OPENAI_API_KEY", config.get_openai_llm().api_key) def test_idea_message(): From 43d5699894a25628ea36029a3ba78b9a42803f70 Mon Sep 17 00:00:00 2001 From: geekan Date: Mon, 8 Jan 2024 20:14:13 +0800 Subject: [PATCH 2/4] fix tests --- metagpt/context.py | 17 +++++++++++++++-- metagpt/llm.py | 5 +++-- metagpt/memory/brain_memory.py | 2 +- tests/data/rsp_cache.json | 3 ++- tests/metagpt/memory/test_brain_memory.py | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/metagpt/context.py b/metagpt/context.py index 560f6e79a..0ea5d6046 100644 --- a/metagpt/context.py +++ b/metagpt/context.py @@ -10,6 +10,7 @@ from pathlib import Path from typing import Optional from metagpt.config2 import Config +from metagpt.configs.llm_config import LLMType from metagpt.const import OPTIONS from metagpt.provider.base_llm import BaseLLM from metagpt.provider.llm_provider_registry import get_llm @@ -61,9 +62,21 @@ class Context: env.update({k: v for k, v in i.items() if isinstance(v, str)}) return env - def llm(self, name: Optional[str] = None) -> BaseLLM: + def llm(self, name: Optional[str] = None, provider: LLMType = LLMType.OPENAI) -> BaseLLM: """Return a LLM instance""" - llm = get_llm(self.config.get_llm_config(name)) + if provider: + llm_configs = self.config.get_llm_configs_by_type(provider) + if name: + llm_configs = [c for c in llm_configs if c.name == name] + + if len(llm_configs) == 0: + raise ValueError(f"Cannot find llm config with name {name} and provider {provider}") + # return the first one if name is None, or return the only one + llm_config = llm_configs[0] + else: + llm_config = self.config.get_llm_config(name) + + llm = get_llm(llm_config) if llm.cost_manager is None: llm.cost_manager = self.cost_manager return llm diff --git a/metagpt/llm.py b/metagpt/llm.py index 9a473e306..f9a5aaedb 100644 --- a/metagpt/llm.py +++ b/metagpt/llm.py @@ -8,10 +8,11 @@ from typing import Optional +from metagpt.configs.llm_config import LLMType from metagpt.context import context from metagpt.provider.base_llm import BaseLLM -def LLM(name: Optional[str] = None) -> BaseLLM: +def LLM(name: Optional[str] = None, provider: LLMType = LLMType.OPENAI) -> BaseLLM: """get the default llm provider if name is None""" - return context.llm(name) + return context.llm(name=name, provider=provider) diff --git a/metagpt/memory/brain_memory.py b/metagpt/memory/brain_memory.py index 73a000beb..044b0b359 100644 --- a/metagpt/memory/brain_memory.py +++ b/metagpt/memory/brain_memory.py @@ -29,7 +29,7 @@ class BrainMemory(BaseModel): historical_summary: str = "" last_history_id: str = "" is_dirty: bool = False - last_talk: str = None + last_talk: Optional[str] = None cacheable: bool = True llm: Optional[BaseLLM] = Field(default=None, exclude=True) diff --git a/tests/data/rsp_cache.json b/tests/data/rsp_cache.json index acc45c280..0ed13593e 100644 --- a/tests/data/rsp_cache.json +++ b/tests/data/rsp_cache.json @@ -153,5 +153,6 @@ "Do not refer to the context of the previous conversation records, start the conversation anew.\n\nFormation: \"Capacity and role\" defines the role you are currently playing;\n\t\"[LESSON_BEGIN]\" and \"[LESSON_END]\" tags enclose the content of textbook;\n\t\"Statement\" defines the work detail you need to complete at this stage;\n\t\"Answer options\" defines the format requirements for your responses;\n\t\"Constraint\" defines the conditions that your responses must comply with.\n\nCapacity and role: You are a {teaching_language} Teacher, named Lily, your goal is writing a {language} teaching plan part by part. the constraint is writing in {language}. \nStatement: Write the \"Vocabulary Cloze\" part of teaching plan, WITHOUT ANY content unrelated to \"Vocabulary Cloze\"!!\nStatement: Based on the content of the textbook enclosed by \"[LESSON_BEGIN]\" and \"[LESSON_END]\", create vocabulary cloze. The cloze should include 10 {language} questions with {teaching_language} answers, and it should also include 10 {teaching_language} questions with {language} answers. The key-related vocabulary and phrases in the textbook content must all be included in the exercises.\nAnswer options: Enclose the teaching plan content with \"[TEACHING_PLAN_BEGIN]\" and \"[TEACHING_PLAN_END]\" tags.\nAnswer options: Using proper markdown format from second-level header format.\nConstraint: Writing in Chinese.\n[LESSON_BEGIN]\n\n UNIT 1 Making New Friends\n TOPIC 1 Welcome to China!\n Section A\n\n 1a Listen and number the following names.\n Jane Mari Kangkang Michael\n Look, listen and understand. Then practice the conversation.\n Work in groups. Introduce yourself using\n I ’m ... Then practice 1a\n with your own hometown or the following places.\n\n 1b Listen and number the following names\n Jane Michael Maria Kangkang\n 1c Work in groups. Introduce yourself using I ’m ... Then practice 1a with your own hometown or the following places.\n China the USA the UK Hong Kong Beijing\n\n 2a Look, listen and understand. Then practice the conversation\n Hello! \n Hello! \n Hello! \n Hello! Are you Maria? \n No, I’m not. I’m Jane.\n Oh, nice to meet you, Jane\n Nice to meet you, too.\n Hi, Maria!\n Hi, Kangkang!\n Welcome to China!\n Thanks.\n\n 2b Work in groups. Make up a conversation with your own name and the\n following structures.\n A: Hello! / Good morning! / Hi! I’m ... Are you ... ?\n B: ...\n\n 3a Listen, say and trace\n Aa Bb Cc Dd Ee Ff Gg\n\n 3b Listen and number the following letters. Then circle the letters with the same sound as Bb.\n Aa Bb Cc Dd Ee Ff Gg\n\n 3c Match the big letters with the small ones. Then write them on the lines.\n \n[LESSON_END]": "[TEACHING_PLAN_BEGIN]\n\n## 词汇填空\n\n### 语言填空\n1. 你好! 你是玛丽亚吗?\n - 不,我不是。我是简。\n - 哦,很高兴认识你,简。\n - 我也很高兴认识你。\n\n2. 你好! / 早上好! / 嗨! 我是... 你是...吗?\n - ...\n\n3. Aa Bb Cc Dd Ee Ff Gg\n\n4. 匹配大写字母和小写字母。然后在线上写出它们。\n\n5. ...\n\n### {language}填空\n1. 1a 听录音,给以下名字编号。\n - 简 玛丽 康康 迈克尔\n\n2. 1b 听录音,给以下名字编号。\n - 简 迈克尔 玛丽亚 康康\n\n3. 1c 分组活动。使用“我是...”介绍自己。然后用你自己的家乡或以下地方练习1a。\n - 中国 美国 英国 香港 北京\n\n4. 2a 看,听,理解。然后练习对话。\n - 你好!\n - 你好!\n - 你好!\n - 你好! 你是玛丽亚吗?\n - 不,我不是。我是简。\n - 哦,很高兴认识你,简。\n - 我也很高兴认识你。\n - 你好,玛丽亚!\n - 你好,康康!\n - 欢迎来到中国!\n - 谢谢。\n\n5. 2b 分组活动。编写一个包含你自己名字和以下结构的对话。\n - A: 你好! / 早上好! / 嗨! 我是... 你是...吗?\n - B: ...\n\n[TEACHING_PLAN_END]", "Do not refer to the context of the previous conversation records, start the conversation anew.\n\nFormation: \"Capacity and role\" defines the role you are currently playing;\n\t\"[LESSON_BEGIN]\" and \"[LESSON_END]\" tags enclose the content of textbook;\n\t\"Statement\" defines the work detail you need to complete at this stage;\n\t\"Answer options\" defines the format requirements for your responses;\n\t\"Constraint\" defines the conditions that your responses must comply with.\n\nCapacity and role: You are a {teaching_language} Teacher, named Lily, your goal is writing a {language} teaching plan part by part. the constraint is writing in {language}. \nStatement: Write the \"Choice Questions\" part of teaching plan, WITHOUT ANY content unrelated to \"Choice Questions\"!!\nStatement: Based on the content of the textbook enclosed by \"[LESSON_BEGIN]\" and \"[LESSON_END]\", create choice questions. 10 questions.\nAnswer options: Enclose the teaching plan content with \"[TEACHING_PLAN_BEGIN]\" and \"[TEACHING_PLAN_END]\" tags.\nAnswer options: Using proper markdown format from second-level header format.\nConstraint: Writing in Chinese.\n[LESSON_BEGIN]\n\n UNIT 1 Making New Friends\n TOPIC 1 Welcome to China!\n Section A\n\n 1a Listen and number the following names.\n Jane Mari Kangkang Michael\n Look, listen and understand. Then practice the conversation.\n Work in groups. Introduce yourself using\n I ’m ... Then practice 1a\n with your own hometown or the following places.\n\n 1b Listen and number the following names\n Jane Michael Maria Kangkang\n 1c Work in groups. Introduce yourself using I ’m ... Then practice 1a with your own hometown or the following places.\n China the USA the UK Hong Kong Beijing\n\n 2a Look, listen and understand. Then practice the conversation\n Hello! \n Hello! \n Hello! \n Hello! Are you Maria? \n No, I’m not. I’m Jane.\n Oh, nice to meet you, Jane\n Nice to meet you, too.\n Hi, Maria!\n Hi, Kangkang!\n Welcome to China!\n Thanks.\n\n 2b Work in groups. Make up a conversation with your own name and the\n following structures.\n A: Hello! / Good morning! / Hi! I’m ... Are you ... ?\n B: ...\n\n 3a Listen, say and trace\n Aa Bb Cc Dd Ee Ff Gg\n\n 3b Listen and number the following letters. Then circle the letters with the same sound as Bb.\n Aa Bb Cc Dd Ee Ff Gg\n\n 3c Match the big letters with the small ones. Then write them on the lines.\n \n[LESSON_END]": "[TEACHING_PLAN_BEGIN]\n\n## 选择题\n\n1. 在1a部分,听到的名字按顺序应该是?\n - A. Jane B. Mari C. Kangkang D. Michael\n\n2. 在1b部分,听到的名字按顺序应该是?\n - A. Jane B. Michael C. Maria D. Kangkang\n\n3. 在2a部分,对话中提到了哪些地方?\n - A. 中国 B. 美国 C. 英国 D. 香港\n\n4. 在3b部分,与Bb发音相同的字母是?\n - A. Aa B. Cc C. Dd D. Gg\n\n5. 在3c部分,大写字母和小写字母的正确匹配是?\n - A. Aa - a B. Bb - b C. Cc - c D. Dd - d\n\n6. 在1a部分,听到的名字按顺序应该是?\n - A. Jane B. Mari C. Kangkang D. Michael\n\n7. 在1b部分,听到的名字按顺序应该是?\n - A. Jane B. Michael C. Maria D. Kangkang\n\n8. 在2a部分,对话中提到了哪些地方?\n - A. 中国 B. 美国 C. 英国 D. 香港\n\n9. 在3b部分,与Bb发音相同的字母是?\n - A. Aa B. Cc C. Dd D. Gg\n\n10. 在3c部分,大写字母和小写字母的正确匹配是?\n - A. Aa - a B. Bb - b C. Cc - c D. Dd - d\n\n[TEACHING_PLAN_END]", "Do not refer to the context of the previous conversation records, start the conversation anew.\n\nFormation: \"Capacity and role\" defines the role you are currently playing;\n\t\"[LESSON_BEGIN]\" and \"[LESSON_END]\" tags enclose the content of textbook;\n\t\"Statement\" defines the work detail you need to complete at this stage;\n\t\"Answer options\" defines the format requirements for your responses;\n\t\"Constraint\" defines the conditions that your responses must comply with.\n\nCapacity and role: You are a {teaching_language} Teacher, named Lily, your goal is writing a {language} teaching plan part by part. the constraint is writing in {language}. \nStatement: Write the \"Grammar Questions\" part of teaching plan, WITHOUT ANY content unrelated to \"Grammar Questions\"!!\nStatement: Based on the content of the textbook enclosed by \"[LESSON_BEGIN]\" and \"[LESSON_END]\", create grammar questions. 10 questions.\nAnswer options: Enclose the teaching plan content with \"[TEACHING_PLAN_BEGIN]\" and \"[TEACHING_PLAN_END]\" tags.\nAnswer options: Using proper markdown format from second-level header format.\nConstraint: Writing in Chinese.\n[LESSON_BEGIN]\n\n UNIT 1 Making New Friends\n TOPIC 1 Welcome to China!\n Section A\n\n 1a Listen and number the following names.\n Jane Mari Kangkang Michael\n Look, listen and understand. Then practice the conversation.\n Work in groups. Introduce yourself using\n I ’m ... Then practice 1a\n with your own hometown or the following places.\n\n 1b Listen and number the following names\n Jane Michael Maria Kangkang\n 1c Work in groups. Introduce yourself using I ’m ... Then practice 1a with your own hometown or the following places.\n China the USA the UK Hong Kong Beijing\n\n 2a Look, listen and understand. Then practice the conversation\n Hello! \n Hello! \n Hello! \n Hello! Are you Maria? \n No, I’m not. I’m Jane.\n Oh, nice to meet you, Jane\n Nice to meet you, too.\n Hi, Maria!\n Hi, Kangkang!\n Welcome to China!\n Thanks.\n\n 2b Work in groups. Make up a conversation with your own name and the\n following structures.\n A: Hello! / Good morning! / Hi! I’m ... Are you ... ?\n B: ...\n\n 3a Listen, say and trace\n Aa Bb Cc Dd Ee Ff Gg\n\n 3b Listen and number the following letters. Then circle the letters with the same sound as Bb.\n Aa Bb Cc Dd Ee Ff Gg\n\n 3c Match the big letters with the small ones. Then write them on the lines.\n \n[LESSON_END]": "[TEACHING_PLAN_BEGIN]\n\n## Grammar Questions\n\n1. 请问在1a中,学生需要做什么?\n2. 请问在1b中,学生需要做什么?\n3. 请问在2a中,学生需要做什么?\n4. 请问在2b中,学生需要做什么?\n5. 请问在3a中,学生需要做什么?\n6. 请问在3b中,学生需要做什么?\n7. 请问在3c中,学生需要做什么?\n8. 请问在1a中,学生需要听什么?\n9. 请问在2a中,学生需要看什么?\n10. 请问在3a中,学生需要说什么?\n\n[TEACHING_PLAN_END]", - "Do not refer to the context of the previous conversation records, start the conversation anew.\n\nFormation: \"Capacity and role\" defines the role you are currently playing;\n\t\"[LESSON_BEGIN]\" and \"[LESSON_END]\" tags enclose the content of textbook;\n\t\"Statement\" defines the work detail you need to complete at this stage;\n\t\"Answer options\" defines the format requirements for your responses;\n\t\"Constraint\" defines the conditions that your responses must comply with.\n\nCapacity and role: You are a {teaching_language} Teacher, named Lily, your goal is writing a {language} teaching plan part by part. the constraint is writing in {language}. \nStatement: Write the \"Translation Questions\" part of teaching plan, WITHOUT ANY content unrelated to \"Translation Questions\"!!\nStatement: Based on the content of the textbook enclosed by \"[LESSON_BEGIN]\" and \"[LESSON_END]\", create translation questions. The translation should include 10 {language} questions with {teaching_language} answers, and it should also include 10 {teaching_language} questions with {language} answers.\nAnswer options: Enclose the teaching plan content with \"[TEACHING_PLAN_BEGIN]\" and \"[TEACHING_PLAN_END]\" tags.\nAnswer options: Using proper markdown format from second-level header format.\nConstraint: Writing in Chinese.\n[LESSON_BEGIN]\n\n UNIT 1 Making New Friends\n TOPIC 1 Welcome to China!\n Section A\n\n 1a Listen and number the following names.\n Jane Mari Kangkang Michael\n Look, listen and understand. Then practice the conversation.\n Work in groups. Introduce yourself using\n I ’m ... Then practice 1a\n with your own hometown or the following places.\n\n 1b Listen and number the following names\n Jane Michael Maria Kangkang\n 1c Work in groups. Introduce yourself using I ’m ... Then practice 1a with your own hometown or the following places.\n China the USA the UK Hong Kong Beijing\n\n 2a Look, listen and understand. Then practice the conversation\n Hello! \n Hello! \n Hello! \n Hello! Are you Maria? \n No, I’m not. I’m Jane.\n Oh, nice to meet you, Jane\n Nice to meet you, too.\n Hi, Maria!\n Hi, Kangkang!\n Welcome to China!\n Thanks.\n\n 2b Work in groups. Make up a conversation with your own name and the\n following structures.\n A: Hello! / Good morning! / Hi! I’m ... Are you ... ?\n B: ...\n\n 3a Listen, say and trace\n Aa Bb Cc Dd Ee Ff Gg\n\n 3b Listen and number the following letters. Then circle the letters with the same sound as Bb.\n Aa Bb Cc Dd Ee Ff Gg\n\n 3c Match the big letters with the small ones. Then write them on the lines.\n \n[LESSON_END]": "[TEACHING_PLAN_BEGIN]\n\n## Translation Questions\n\n### {language} Questions with {teaching_language} Answers\n1. 你能听懂这些名字吗? (Can you understand these names?)\n - 能,我能听懂。 (Yes, I can understand.)\n2. 请用“我是...”介绍一下你自己。 (Please introduce yourself using \"I am...\")\n - 我是... (I am...)\n3. 你能用这些结构编一个对话吗? (Can you make up a conversation with these structures?)\n - 能,我能编一个对话。 (Yes, I can make up a conversation.)\n4. 你能说出这些字母的名字吗? (Can you say the names of these letters?)\n - 能,我能说出来。 (Yes, I can say them.)\n5. 你能把大写字母和小写字母配对吗? (Can you match the uppercase letters with the lowercase letters?)\n - 能,我能配对。 (Yes, I can match them.)\n\n### {teaching_language} Questions with {language} Answers\n1. Can you understand these names?\n - Yes, I can understand.\n2. Please introduce yourself using \"I am...\"\n - I am...\n3. Can you make up a conversation with these structures?\n - Yes, I can make up a conversation.\n4. Can you say the names of these letters?\n - Yes, I can say them.\n5. Can you match the uppercase letters with the lowercase letters?\n - Yes, I can match them.\n\n[TEACHING_PLAN_END]" + "Do not refer to the context of the previous conversation records, start the conversation anew.\n\nFormation: \"Capacity and role\" defines the role you are currently playing;\n\t\"[LESSON_BEGIN]\" and \"[LESSON_END]\" tags enclose the content of textbook;\n\t\"Statement\" defines the work detail you need to complete at this stage;\n\t\"Answer options\" defines the format requirements for your responses;\n\t\"Constraint\" defines the conditions that your responses must comply with.\n\nCapacity and role: You are a {teaching_language} Teacher, named Lily, your goal is writing a {language} teaching plan part by part. the constraint is writing in {language}. \nStatement: Write the \"Translation Questions\" part of teaching plan, WITHOUT ANY content unrelated to \"Translation Questions\"!!\nStatement: Based on the content of the textbook enclosed by \"[LESSON_BEGIN]\" and \"[LESSON_END]\", create translation questions. The translation should include 10 {language} questions with {teaching_language} answers, and it should also include 10 {teaching_language} questions with {language} answers.\nAnswer options: Enclose the teaching plan content with \"[TEACHING_PLAN_BEGIN]\" and \"[TEACHING_PLAN_END]\" tags.\nAnswer options: Using proper markdown format from second-level header format.\nConstraint: Writing in Chinese.\n[LESSON_BEGIN]\n\n UNIT 1 Making New Friends\n TOPIC 1 Welcome to China!\n Section A\n\n 1a Listen and number the following names.\n Jane Mari Kangkang Michael\n Look, listen and understand. Then practice the conversation.\n Work in groups. Introduce yourself using\n I ’m ... Then practice 1a\n with your own hometown or the following places.\n\n 1b Listen and number the following names\n Jane Michael Maria Kangkang\n 1c Work in groups. Introduce yourself using I ’m ... Then practice 1a with your own hometown or the following places.\n China the USA the UK Hong Kong Beijing\n\n 2a Look, listen and understand. Then practice the conversation\n Hello! \n Hello! \n Hello! \n Hello! Are you Maria? \n No, I’m not. I’m Jane.\n Oh, nice to meet you, Jane\n Nice to meet you, too.\n Hi, Maria!\n Hi, Kangkang!\n Welcome to China!\n Thanks.\n\n 2b Work in groups. Make up a conversation with your own name and the\n following structures.\n A: Hello! / Good morning! / Hi! I’m ... Are you ... ?\n B: ...\n\n 3a Listen, say and trace\n Aa Bb Cc Dd Ee Ff Gg\n\n 3b Listen and number the following letters. Then circle the letters with the same sound as Bb.\n Aa Bb Cc Dd Ee Ff Gg\n\n 3c Match the big letters with the small ones. Then write them on the lines.\n \n[LESSON_END]": "[TEACHING_PLAN_BEGIN]\n\n## Translation Questions\n\n### {language} Questions with {teaching_language} Answers\n1. 你能听懂这些名字吗? (Can you understand these names?)\n - 能,我能听懂。 (Yes, I can understand.)\n2. 请用“我是...”介绍一下你自己。 (Please introduce yourself using \"I am...\")\n - 我是... (I am...)\n3. 你能用这些结构编一个对话吗? (Can you make up a conversation with these structures?)\n - 能,我能编一个对话。 (Yes, I can make up a conversation.)\n4. 你能说出这些字母的名字吗? (Can you say the names of these letters?)\n - 能,我能说出来。 (Yes, I can say them.)\n5. 你能把大写字母和小写字母配对吗? (Can you match the uppercase letters with the lowercase letters?)\n - 能,我能配对。 (Yes, I can match them.)\n\n### {teaching_language} Questions with {language} Answers\n1. Can you understand these names?\n - Yes, I can understand.\n2. Please introduce yourself using \"I am...\"\n - I am...\n3. Can you make up a conversation with these structures?\n - Yes, I can make up a conversation.\n4. Can you say the names of these letters?\n - Yes, I can say them.\n5. Can you match the uppercase letters with the lowercase letters?\n - Yes, I can match them.\n\n[TEACHING_PLAN_END]", + "The given text repeatedly describes Lily as a girl. It emphasizes that Lily is a girl multiple times. The content consistently refers to Lily as a girl.\nTranslate the above summary into a English title of less than 5 words.": "\"Emphasizing Lily's Gender\"" } \ No newline at end of file diff --git a/tests/metagpt/memory/test_brain_memory.py b/tests/metagpt/memory/test_brain_memory.py index 1f587d9f7..c06b5cf1a 100644 --- a/tests/metagpt/memory/test_brain_memory.py +++ b/tests/metagpt/memory/test_brain_memory.py @@ -46,7 +46,7 @@ def test_extract_info(input, tag, val): @pytest.mark.asyncio -@pytest.mark.parametrize("llm", [LLM(provider=LLMType.OPENAI), LLM(provider=LLMType.METAGPT)]) +@pytest.mark.parametrize("llm", [LLM(provider=LLMType.OPENAI)]) # , LLM(provider=LLMType.METAGPT) async def test_memory_llm(llm): memory = BrainMemory() for i in range(500): From 43c72c7d78f3a011d56c4bba64a06593a90755aa Mon Sep 17 00:00:00 2001 From: geekan Date: Mon, 8 Jan 2024 20:23:21 +0800 Subject: [PATCH 3/4] refine code --- tests/metagpt/provider/test_ollama_api.py | 4 ---- tests/metagpt/provider/test_open_llm_api.py | 4 ---- 2 files changed, 8 deletions(-) diff --git a/tests/metagpt/provider/test_ollama_api.py b/tests/metagpt/provider/test_ollama_api.py index 41f02bf2c..5d942598b 100644 --- a/tests/metagpt/provider/test_ollama_api.py +++ b/tests/metagpt/provider/test_ollama_api.py @@ -7,7 +7,6 @@ from typing import Any, Tuple import pytest -from metagpt.config import CONFIG from metagpt.provider.ollama_api import OllamaLLM from tests.metagpt.provider.mock_llm_config import mock_llm_config @@ -17,9 +16,6 @@ messages = [{"role": "user", "content": prompt_msg}] resp_content = "I'm ollama" default_resp = {"message": {"role": "assistant", "content": resp_content}} -CONFIG.ollama_api_base = "http://xxx" -CONFIG.max_budget = 10 - async def mock_ollama_arequest(self, stream: bool = False, **kwargs) -> Tuple[Any, Any, bool]: if stream: diff --git a/tests/metagpt/provider/test_open_llm_api.py b/tests/metagpt/provider/test_open_llm_api.py index f74bc9c49..fc7b510cc 100644 --- a/tests/metagpt/provider/test_open_llm_api.py +++ b/tests/metagpt/provider/test_open_llm_api.py @@ -13,14 +13,10 @@ from openai.types.chat.chat_completion_chunk import Choice as AChoice from openai.types.chat.chat_completion_chunk import ChoiceDelta from openai.types.completion_usage import CompletionUsage -from metagpt.config import CONFIG from metagpt.provider.open_llm_api import OpenLLM from metagpt.utils.cost_manager import Costs from tests.metagpt.provider.mock_llm_config import mock_llm_config -CONFIG.max_budget = 10 -CONFIG.calc_usage = True - resp_content = "I'm llama2" default_resp = ChatCompletion( id="cmpl-a6652c1bb181caae8dd19ad8", From e7543ab923b7688365965668b18e8ff2cf2e3cb2 Mon Sep 17 00:00:00 2001 From: geekan Date: Mon, 8 Jan 2024 22:10:11 +0800 Subject: [PATCH 4/4] refine cli --- metagpt/startup.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/metagpt/startup.py b/metagpt/startup.py index cacf68113..cd5b4dac7 100644 --- a/metagpt/startup.py +++ b/metagpt/startup.py @@ -1,11 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- import asyncio +import shutil from pathlib import Path import typer from metagpt.config2 import config +from metagpt.const import METAGPT_ROOT app = typer.Typer(add_completion=False) @@ -64,9 +66,9 @@ def generate_repo( asyncio.run(company.run(n_round=n_round)) -@app.command() +@app.command("", help="Start a new project.") def startup( - idea: str = typer.Argument(..., help="Your innovative idea, such as 'Create a 2048 game.'"), + idea: str = typer.Argument(None, help="Your innovative idea, such as 'Create a 2048 game.'"), investment: float = typer.Option(default=3.0, help="Dollar amount to invest in the AI company."), n_round: int = typer.Option(default=5, help="Number of rounds for the simulation."), code_review: bool = typer.Option(default=True, help="Whether to use code review."), @@ -87,8 +89,17 @@ def startup( "unlimited. This parameter is used for debugging the workflow.", ), recover_path: str = typer.Option(default=None, help="recover the project from existing serialized storage"), + init_config: bool = typer.Option(default=False, help="Initialize the configuration file for MetaGPT."), ): """Run a startup. Be a boss.""" + if init_config: + copy_config_to() + return + + if idea is None: + typer.echo("Missing argument 'IDEA'. Run 'metagpt --help' for more information.") + raise typer.Exit() + return generate_repo( idea, investment, @@ -105,5 +116,23 @@ def startup( ) +def copy_config_to(config_path=METAGPT_ROOT / "config" / "config2.yaml"): + """Initialize the configuration file for MetaGPT.""" + target_path = Path.home() / ".metagpt" / "config2.yaml" + + # 创建目标目录(如果不存在) + target_path.parent.mkdir(parents=True, exist_ok=True) + + # 如果目标文件已经存在,则重命名为 .bak + if target_path.exists(): + backup_path = target_path.with_suffix(".bak") + target_path.rename(backup_path) + print(f"Existing configuration file backed up at {backup_path}") + + # 复制文件 + shutil.copy(str(config_path), target_path) + print(f"Configuration file initialized at {target_path}") + + if __name__ == "__main__": app()