Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Modifying schema to support multi modal inputs. #1673

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion memgpt/agent_store/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class MessageModel(Base):

# openai info
role = Column(String, nullable=False)
text = Column(String) # optional: can be null if function call
content = Column(JSON) # optional: multi-modal input. can be null be function call.
model = Column(String) # optional: can be null if LLM backend doesn't require specifying
name = Column(String) # optional: multi-agent only

Expand Down Expand Up @@ -192,6 +192,7 @@ def to_record(self):
role=self.role,
name=self.name,
text=self.text,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, should delete/deprecate text and replace with content which can be None, str (text-only), or List[dict/MultiModalMessagePart] (multi-modal).

mm_content=self.mm_content,
model=self.model,
# tool_calls=[ToolCall(id=tool_call["id"], function=ToolCallFunction(**tool_call["function"])) for tool_call in self.tool_calls] if self.tool_calls else None,
tool_calls=self.tool_calls,
Expand Down
6 changes: 4 additions & 2 deletions memgpt/schemas/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from memgpt.schemas.enums import MessageRole
from memgpt.schemas.memgpt_base import MemGPTBase
from memgpt.schemas.memgpt_message import LegacyMemGPTMessage, MemGPTMessage
from memgpt.schemas.openai.chat_completions import ToolCall
from memgpt.schemas.openai.chat_completions import ToolCall, MultiModalMessage
from memgpt.utils import get_utc_time, is_utc_datetime


Expand Down Expand Up @@ -62,6 +62,7 @@ class Message(BaseMessage):
id: str = BaseMessage.generate_id_field()
role: MessageRole = Field(..., description="The role of the participant.")
text: str = Field(..., description="The text of the message.")
content: Union[str, MultiModalMessage] = Field(None, description="Content entered by the user.")
user_id: str = Field(None, description="The unique identifier of the user.")
agent_id: str = Field(None, description="The unique identifier of the agent.")
model: Optional[str] = Field(None, description="The model used to make the function call.")
Expand Down Expand Up @@ -223,8 +224,9 @@ def to_openai_dict(

elif self.role == "user":
assert all([v is not None for v in [self.text, self.role]]), vars(self)
content = self.mm_content if self.mm_content is not None else self.text
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we do the above (replace text) we should no longer need this

openai_message = {
"content": self.text,
"content": content,
"role": self.role,
}
# Optional field, do not include if null
Expand Down
6 changes: 4 additions & 2 deletions memgpt/schemas/openai/chat_completion_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class SystemMessage(BaseModel):
role: str = "system"
name: Optional[str] = None

class MultiModalMessage(BaseModel):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to expand this to have text and image_url:

image

type: str
image_url: str

class UserMessage(BaseModel):
content: Union[str, List[str]]
content: Union[str, List[MultiModalMessage]]
role: str = "user"
name: Optional[str] = None


class ToolCallFunction(BaseModel):
name: str
arguments: str
Expand Down
6 changes: 4 additions & 2 deletions memgpt/schemas/openai/chat_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class SystemMessage(BaseModel):
role: str = "system"
name: Optional[str] = None

class MultiModalMessage(BaseModel):
type: str
image_url: str

class UserMessage(BaseModel):
content: Union[str, List[str]]
content: Union[str, List[MultiModalMessage]]
role: str = "user"
name: Optional[str] = None


class ToolCallFunction(BaseModel):
name: str = Field(..., description="The name of the function to call")
arguments: str = Field(..., description="The arguments to pass to the function (JSON dump)")
Expand Down
Loading