Skip to content

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

update gpt4-v

better629295571fafaf6
diff --git a/examples/llm_hello_world.py b/examples/llm_hello_world.py
index bf7f170a7..8321b64ca 100644
--- a/examples/llm_hello_world.py
+++ b/examples/llm_hello_world.py
@@ -44,13 +44,11 @@ async def main():
invoice_path = Path(__file__).parent.joinpath("..", "tests", "data", "invoices", "invoice-2.png")
img_base64 = encode_image(invoice_path)
try:
- res = await llm.aask(msg="if this is a invoice, just return True else return False",
- images=[img_base64])
+ res = await llm.aask(msg="if this is a invoice, just return True else return False", images=[img_base64])
assert "true" in res.lower()
- except Exception as exp:
+ except Exception:
pass
-
if __name__ == "__main__":
asyncio.run(main())
diff --git a/metagpt/provider/base_llm.py b/metagpt/provider/base_llm.py
index 7e71b6cc9..db2757ec3 100644
--- a/metagpt/provider/base_llm.py
+++ b/metagpt/provider/base_llm.py
@@ -60,25 +60,12 @@ class BaseLLM(ABC):
"""
if isinstance(images, str):
images = [images]
-<<<<<<< HEAD
content = [{"type": "text", "text": msg}]
-=======
- content = [
- {"type": "text", "text": msg}
- ]
->>>>>>> 9cbc3466 (add gpt4-v)
for image in images:
# image url or image base64
url = image if image.startswith("http") else f"data:image/jpeg;base64,{image}"
# it can with multiple-image inputs
-<<<<<<< HEAD
content.append({"type": "image_url", "image_url": url})
-=======
- content.append({
- "type": "image_url",
- "image_url": url
- })
->>>>>>> 9cbc3466 (add gpt4-v)
return {"role": "user", "content": content}
def _assistant_msg(self, msg: str) -> dict[str, str]:
@@ -144,11 +131,7 @@ class BaseLLM(ABC):
system_msgs: Optional[list[str]] = None,
format_msgs: Optional[list[dict[str, str]]] = None,
images: Optional[Union[str, list[str]]] = None,
-<<<<<<< HEAD
timeout=USE_CONFIG_TIMEOUT,
-=======
- timeout=3,
->>>>>>> 9cbc3466 (add gpt4-v)
stream=True,
) -> str:
if system_msgs:
@@ -159,14 +142,10 @@ class BaseLLM(ABC):
message = []
if format_msgs:
message.extend(format_msgs)
-<<<<<<< HEAD
if isinstance(msg, str):
message.append(self._user_msg(msg, images=images))
else:
message.extend(msg)
-=======
- message.append(self._user_msg(msg, images=images))
->>>>>>> 9cbc3466 (add gpt4-v)
logger.debug(message)
rsp = await self.acompletion_text(message, stream=stream, timeout=self.get_timeout(timeout))
return rsp
diff --git a/metagpt/utils/common.py b/metagpt/utils/common.py
index f49d69d41..532feaab9 100644
--- a/metagpt/utils/common.py
+++ b/metagpt/utils/common.py
@@ -24,12 +24,9 @@ import platform
import re
import sys
import traceback
-<<<<<<< HEAD
from io import BytesIO
-=======
import typing
import base64
->>>>>>> 9cbc3466 (add gpt4-v)
from pathlib import Path
from typing import Any, Callable, List, Literal, Tuple, Union
from urllib.parse import quote, unquote
@@ -749,7 +746,6 @@ def list_files(root: str | Path) -> List[Path]:
return files
-<<<<<<< HEAD
def parse_json_code_block(markdown_text: str) -> List[str]:
json_blocks = re.findall(r"```json(.*?)```", markdown_text, re.DOTALL)
return [v.strip() for v in json_blocks]
@@ -867,8 +863,3 @@ def get_markdown_codeblock_type(filename: str) -> str:
"application/sql": "sql",
}
return mappings.get(mime_type, "text")
-=======
-def encode_image(image_path: Path, encoding: str = "utf-8") -> str:
- with open(str(image_path), "rb") as image_file:
- return base64.b64encode(image_file.read()).decode(encoding)
->>>>>>> 9cbc3466 (add gpt4-v)
diff --git a/tests/metagpt/actions/test_action_node.py b/tests/metagpt/actions/test_action_node.py
index 989e2249c..c2c5024a7 100644
--- a/tests/metagpt/actions/test_action_node.py
+++ b/tests/metagpt/actions/test_action_node.py
@@ -9,7 +9,11 @@ from pathlib import Path
from typing import List, Tuple
import pytest
+<<<<<<< HEAD
from pydantic import BaseModel, Field, ValidationError
+=======
+from pydantic import ValidationError
+>>>>>>> 7f8ae1f2 (update gpt4-v)
from metagpt.actions import Action
from metagpt.actions.action_node import ActionNode, ReviewMode, ReviseMode