mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
update gpt4-v
This commit is contained in:
parent
471871b827
commit
295571fafa
4 changed files with 6 additions and 34 deletions
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue