-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix: refactor send_message
API
#1633
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd0a907
fix: fix hanging send_message by wrapping server.step in try/catch + …
cpacker 1ac6c9f
feat: updated MemGPTResponse to take MemGPTMessages in addition to Me…
cpacker 5347b05
refactor: change streaming interface to use new pydantic types inside…
cpacker 572e6ff
Merge branch 'refactor-api' into update-streaming-interface
cpacker 768d7ee
chore: strip comments
cpacker 113cfb8
chore: stray prints
cpacker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from datetime import datetime, timezone | ||
from typing import Literal, Union | ||
|
||
from pydantic import BaseModel, field_serializer | ||
|
||
# MemGPT API style responses (intended to be easier to use vs getting true Message types) | ||
|
||
|
||
class BaseMemGPTMessage(BaseModel): | ||
id: str | ||
date: datetime | ||
|
||
@field_serializer("date") | ||
def serialize_datetime(self, dt: datetime, _info): | ||
return dt.now(timezone.utc).isoformat() | ||
|
||
|
||
class InternalMonologue(BaseMemGPTMessage): | ||
""" | ||
{ | ||
"internal_monologue": msg, | ||
"date": msg_obj.created_at.isoformat() if msg_obj is not None else get_utc_time().isoformat(), | ||
"id": str(msg_obj.id) if msg_obj is not None else None, | ||
} | ||
""" | ||
|
||
internal_monologue: str | ||
|
||
|
||
class FunctionCall(BaseModel): | ||
name: str | ||
arguments: str | ||
|
||
|
||
class FunctionCallMessage(BaseMemGPTMessage): | ||
""" | ||
{ | ||
"function_call": { | ||
"name": function_call.function.name, | ||
"arguments": function_call.function.arguments, | ||
}, | ||
"id": str(msg_obj.id), | ||
"date": msg_obj.created_at.isoformat(), | ||
} | ||
""" | ||
|
||
function_call: FunctionCall | ||
|
||
|
||
class FunctionReturn(BaseMemGPTMessage): | ||
""" | ||
{ | ||
"function_return": msg, | ||
"status": "success" or "error", | ||
"id": str(msg_obj.id), | ||
"date": msg_obj.created_at.isoformat(), | ||
} | ||
""" | ||
|
||
function_return: str | ||
status: Literal["success", "error"] | ||
|
||
|
||
MemGPTMessage = Union[InternalMonologue, FunctionCallMessage, FunctionReturn] | ||
|
||
|
||
# Legacy MemGPT API had an additional type "assistant_message" and the "function_call" was a formatted string | ||
|
||
|
||
class AssistantMessage(BaseMemGPTMessage): | ||
assistant_message: str | ||
|
||
|
||
class LegacyFunctionCallMessage(BaseMemGPTMessage): | ||
function_call: str | ||
|
||
|
||
LegacyMemGPTMessage = Union[InternalMonologue, AssistantMessage, LegacyFunctionCallMessage, FunctionReturn] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
from typing import List | ||
from typing import List, Union | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from memgpt.schemas.memgpt_message import LegacyMemGPTMessage, MemGPTMessage | ||
from memgpt.schemas.message import Message | ||
from memgpt.schemas.usage import MemGPTUsageStatistics | ||
|
||
|
||
# TODO: consider moving into own file | ||
|
||
|
||
class MemGPTResponse(BaseModel): | ||
messages: List[Message] = Field(..., description="The messages returned by the agent.") | ||
# messages: List[Message] = Field(..., description="The messages returned by the agent.") | ||
messages: Union[List[Message], List[MemGPTMessage], List[LegacyMemGPTMessage]] = Field( | ||
..., description="The messages returned by the agent." | ||
) | ||
usage: MemGPTUsageStatistics = Field(..., description="The usage statistics of the agent.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarahwooders this isn't properly connected anywhere yet - probably this should be set to
False
by default, and the Python + REST clients should set it toTrue
manually