Merge branch 'check_role_zero' into da_change

This commit is contained in:
garylin2099 2024-08-14 22:28:45 +08:00
commit c79a70517f
54 changed files with 376 additions and 216 deletions

View file

@ -10,8 +10,9 @@ import pytest
from metagpt.configs.compress_msg_config import CompressType
from metagpt.configs.llm_config import LLMConfig
from metagpt.const import IMAGES
from metagpt.provider.base_llm import BaseLLM
from metagpt.schema import Message
from metagpt.schema import AIMessage, Message, UserMessage
from tests.metagpt.provider.mock_llm_config import mock_llm_config
from tests.metagpt.provider.req_resp_const import (
default_resp_cont,
@ -163,3 +164,41 @@ def test_compress_messages_long_no_sys_msg(compress_type):
print(compressed)
assert compressed
assert len(compressed[0]["content"]) < len(messages[0]["content"])
def test_format_msg(mocker):
base_llm = MockBaseLLM()
messages = [UserMessage(content="req"), AIMessage(content="rsp")]
formatted_msgs = base_llm.format_msg(messages)
assert formatted_msgs == [{"role": "user", "content": "req"}, {"role": "assistant", "content": "rsp"}]
def test_format_msg_w_images(mocker):
base_llm = MockBaseLLM()
base_llm.config.model = "gpt-4o"
msg_w_images = UserMessage(content="req1")
msg_w_images.add_metadata(IMAGES, ["base64 string 1", "base64 string 2"])
msg_w_empty_images = UserMessage(content="req2")
msg_w_empty_images.add_metadata(IMAGES, [])
messages = [
msg_w_images, # should be converted
AIMessage(content="rsp"),
msg_w_empty_images, # should not be converted
]
formatted_msgs = base_llm.format_msg(messages)
assert formatted_msgs == [
{
"role": "user",
"content": [
{"type": "text", "text": "req1"},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,base64 string 1"}},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,base64 string 2"}},
],
},
{"role": "assistant", "content": "rsp"},
{"role": "user", "content": "req2"},
]
if name == "__main__":
pytest.main([__file__, "-s"])

View file

@ -2,13 +2,14 @@ import asyncio
import json
from datetime import datetime
from metagpt.config2 import config
from metagpt.config2 import Config
from metagpt.const import DEFAULT_WORKSPACE_ROOT, METAGPT_ROOT
from metagpt.logs import logger
from metagpt.roles.di.swe_agent import SWEAgent
from metagpt.tools.libs.terminal import Terminal
from metagpt.tools.swe_agent_commands.swe_agent_utils import load_hf_dataset
config = Config.default()
# Specify by yourself
TEST_REPO_DIR = METAGPT_ROOT / "data" / "test_repo"
DATA_DIR = METAGPT_ROOT / "data/hugging_face"

View file

@ -5,10 +5,12 @@
@Author : alexanderwu
@File : test_document.py
"""
from metagpt.config2 import config
from metagpt.config2 import Config
from metagpt.document import Repo
from metagpt.logs import logger
config = Config.default()
def set_existing_repo(path):
repo1 = Repo.from_path(path)

View file

@ -12,9 +12,11 @@ from pathlib import Path
import pytest
from azure.cognitiveservices.speech import ResultReason, SpeechSynthesizer
from metagpt.config2 import config
from metagpt.config2 import Config
from metagpt.tools.azure_tts import AzureTTS
config = Config.default()
@pytest.mark.asyncio
async def test_azure_tts(mocker):

View file

@ -10,9 +10,11 @@ from unittest.mock import AsyncMock
import pytest
from metagpt.config2 import config
from metagpt.config2 import Config
from metagpt.tools.metagpt_text_to_image import oas3_metagpt_text_to_image
config = Config.default()
@pytest.mark.asyncio
async def test_draw(mocker):

View file

@ -8,10 +8,12 @@
import pytest
from metagpt.config2 import config
from metagpt.config2 import Config
from metagpt.llm import LLM
from metagpt.tools.moderation import Moderation
config = Config.default()
@pytest.mark.asyncio
@pytest.mark.parametrize(

View file

@ -11,7 +11,7 @@ import openai
import pytest
from pydantic import BaseModel
from metagpt.config2 import config
from metagpt.config2 import Config
from metagpt.llm import LLM
from metagpt.tools.openai_text_to_image import (
OpenAIText2Image,
@ -19,6 +19,8 @@ from metagpt.tools.openai_text_to_image import (
)
from metagpt.utils.s3 import S3
config = Config.default()
@pytest.mark.asyncio
async def test_draw(mocker):

View file

@ -20,10 +20,12 @@ from openai.types.chat.chat_completion_message_tool_call import (
Function,
)
from metagpt.config2 import config
from metagpt.config2 import Config
from metagpt.const import API_QUESTIONS_PATH, UT_PY_PATH
from metagpt.tools.ut_writer import YFT_PROMPT_PREFIX, UTGenerator
config = Config.default()
class TestUTWriter:
@pytest.mark.asyncio

View file

@ -29,9 +29,9 @@ from metagpt.utils.common import (
awrite,
check_cmd_exists,
concat_namespace,
extract_and_encode_images,
extract_image_paths,
import_class_inst,
is_support_image_input,
parse_recipient,
print_members,
read_file_block,
@ -231,9 +231,8 @@ def test_extract_image_paths():
assert not extract_image_paths(content)
def test_is_support_image_input():
assert is_support_image_input("gpt-4o-2024-08-06")
assert not is_support_image_input("deepseek-coder")
def test_extract_and_encode_images():
assert not extract_and_encode_images("a non-existing.jpg")
if __name__ == "__main__":

View file

@ -2,7 +2,9 @@
# -*- coding: utf-8 -*-
# @Desc : unittest of repair_llm_raw_output
from metagpt.config2 import config
from metagpt.config2 import Config
config = Config.default()
"""
CONFIG.repair_llm_output should be True before retry_parse_json_text imported.

View file

@ -1,7 +1,7 @@
import json
from typing import Optional, Union
from metagpt.config2 import config
from metagpt.config2 import Config
from metagpt.configs.llm_config import LLMType
from metagpt.const import LLM_API_TIMEOUT
from metagpt.logs import logger
@ -10,6 +10,8 @@ from metagpt.provider.constant import GENERAL_FUNCTION_SCHEMA
from metagpt.provider.openai_api import OpenAILLM
from metagpt.schema import Message
config = Config.default()
OriginalLLM = OpenAILLM if config.llm.api_type == LLMType.OPENAI else AzureOpenAILLM