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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions memgpt/agent_store/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class MessageModel(Base):
# openai info
role = Column(String, nullable=False)
text = Column(String) # optional: can be null if function call
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we should probably delete
text = Column(String) # optional: can be null if function call

and replace with
content = Column(JSON) # optional: multi-modal input

which in the pydantic model is Optional[Union[str, List[MultiModalMessagePart]]]

but in the database itself is stored as an optional JSON field

mm_content = Column(JSON) # optional: multi-modal input
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 +193,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
5 changes: 4 additions & 1 deletion memgpt/schemas/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ 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.")
# Field mm_content is only used when role is 'user'. It needs to be mapped to MultiModalMessage
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment here - deprecating text and replacing with a new content that matches OpenAI

mm_content: List[dict] = Field(None, description="Multi modal 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 +225,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
Loading