add gpt-4v support for aask and AN.fill

This commit is contained in:
better629 2024-01-30 11:59:53 +08:00
parent 9e49e2252d
commit 310687258e
8 changed files with 113 additions and 14 deletions

View file

@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, Union
from metagpt.config2 import config
from metagpt.logs import log_llm_stream, logger
@ -35,6 +35,7 @@ class MockLLM(OpenAILLM):
msg: str,
system_msgs: Optional[list[str]] = None,
format_msgs: Optional[list[dict[str, str]]] = None,
images: Optional[Union[str, list[str]]] = None,
timeout=3,
stream=True,
):
@ -47,7 +48,7 @@ class MockLLM(OpenAILLM):
message = []
if format_msgs:
message.extend(format_msgs)
message.append(self._user_msg(msg))
message.append(self._user_msg(msg, images=images))
rsp = await self.acompletion_text(message, stream=stream, timeout=timeout)
return rsp
@ -66,6 +67,7 @@ class MockLLM(OpenAILLM):
msg: str,
system_msgs: Optional[list[str]] = None,
format_msgs: Optional[list[dict[str, str]]] = None,
images: Optional[Union[str, list[str]]] = None,
timeout=3,
stream=True,
) -> str:
@ -73,7 +75,7 @@ class MockLLM(OpenAILLM):
if system_msgs:
joined_system_msg = "#MSG_SEP#".join(system_msgs) + "#SYSTEM_MSG_END#"
msg_key = joined_system_msg + msg_key
rsp = await self._mock_rsp(msg_key, self.original_aask, msg, system_msgs, format_msgs, timeout, stream)
rsp = await self._mock_rsp(msg_key, self.original_aask, msg, system_msgs, format_msgs, images, timeout, stream)
return rsp
async def aask_batch(self, msgs: list, timeout=3) -> str: