Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

Merge branch 'dev' into code_intepreter

yzlin891e35b92f1b
diff --cc metagpt/provider/openai_api.py
index 206701efd,3d3251934..4b5393215
--- a/metagpt/provider/openai_api.py
+++ b/metagpt/provider/openai_api.py
@@@ -26,10 -25,10 +26,10 @@@ from tenacity import
from metagpt.configs.llm_config import LLMConfig, LLMType
from metagpt.logs import log_llm_stream, logger
from metagpt.provider.base_llm import BaseLLM
-from metagpt.provider.constant import GENERAL_FUNCTION_SCHEMA, GENERAL_TOOL_CHOICE
+from metagpt.provider.constant import GENERAL_FUNCTION_SCHEMA
from metagpt.provider.llm_provider_registry import register_provider
from metagpt.schema import Message
- from metagpt.utils.common import CodeParser
-from metagpt.utils.common import decode_image
++from metagpt.utils.common import CodeParser, decode_image
from metagpt.utils.cost_manager import CostManager, Costs
from metagpt.utils.exceptions import handle_exception
from metagpt.utils.token_counter import (
diff --cc metagpt/utils/common.py
index 9d6a6bb24,d3a922c5f..2264255dc
--- a/metagpt/utils/common.py
+++ b/metagpt/utils/common.py
@@@ -491,9 -475,32 +504,32 @@@ def write_json_file(json_file: str, dat
folder_path.mkdir(parents=True, exist_ok=True)
with open(json_file, "w", encoding=encoding) as fout:
- json.dump(data, fout, ensure_ascii=False, indent=4, default=to_jsonable_python)
+ json.dump(data, fout, ensure_ascii=False, indent=indent, default=to_jsonable_python)
+ def read_csv_to_list(curr_file: str, header=False, strip_trail=True):
+ """
+ Reads in a csv file to a list of list. If header is True, it returns a
+ tuple with (header row, all rows)
+ ARGS:
+ curr_file: path to the current csv file.
+ RETURNS:
+ List of list where the component lists are the rows of the file.
+ """
+ logger.debug(f"start read csv: {curr_file}")
+ analysis_list = []
+ with open(curr_file) as f_analysis_file:
+ data_reader = csv.reader(f_analysis_file, delimiter=",")
+ for count, row in enumerate(data_reader):
+ if strip_trail:
+ row = [i.strip() for i in row]
+ analysis_list += [row]
+ if not header:
+ return analysis_list
+ else:
+ return analysis_list[0], analysis_list[1:]
+
+
def import_class(class_name: str, module_name: str) -> type:
module = importlib.import_module(module_name)
a_class = getattr(module, class_name)
diff --cc requirements.txt
index dff615bdc,93091d137..6cb25d52b
--- a/requirements.txt
+++ b/requirements.txt
@@@ -65,4 -59,4 +65,5 @@@ networkx~=3.2.
google-generativeai==0.3.2
# playwright==1.40.0 # playwright extras require
anytree
- ipywidgets==8.1.1
-Pillow
++ipywidgets==8.1.1
++Pillow
diff --cc tests/metagpt/provider/test_openai.py
index a49d7e85b,82ab091c5..5895c9eb8
--- a/tests/metagpt/provider/test_openai.py
+++ b/tests/metagpt/provider/test_openai.py
@@@ -1,11 -1,5 +1,12 @@@
import pytest
+from openai.types.chat import (
+ ChatCompletion,
+ ChatCompletionMessage,
+ ChatCompletionMessageToolCall,
+)
+from openai.types.chat.chat_completion import Choice
+from openai.types.chat.chat_completion_message_tool_call import Function
+ from PIL import Image
from metagpt.const import TEST_DATA_PATH
from metagpt.llm import LLM
@@@ -90,18 -87,3 +91,30 @@@ class TestOpenAI
instance = OpenAILLM(mock_llm_config_proxy)
kwargs = instance._make_client_kwargs()
assert "http_client" in kwargs
+
+ def test_get_choice_function_arguments_for_aask_code(self, tool_calls_rsp):
+ instance = OpenAILLM(mock_llm_config_proxy)
+ for i, rsp in enumerate(tool_calls_rsp):
+ code = instance.get_choice_function_arguments(rsp)
+ logger.info(f"\ntest get function call arguments {i}: {code}")
+ assert "code" in code
+ assert "language" in code
+ assert "hello world" in code["code"]
+ logger.info(f'code is : {code["code"]}')
+
+ if "Completed a python code for hello world!" == code["code"]:
+ code["language"] == "markdown"
+ else:
+ code["language"] == "python"
++
++
++async def test_gen_image():
++ llm = LLM()
++ model = "dall-e-3"
++ prompt = 'a logo with word "MetaGPT"'
++ images: list[Image] = await llm.gen_image(model=model, prompt=prompt)
++ assert images[0].size == (1024, 1024)
++
++ images: list[Image] = await llm.gen_image(model=model, prompt=prompt, resp_format="b64_json")
++ assert images[0].size == (1024, 1024)