-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Improvements #63
Improvements #63
Conversation
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.
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.
LGTM
Thanks @Jeadie @AntonOsika I would like your confirmation on this one before I merge. |
Thanks for the good work keeping this up with main @Jeadie – and wanting to get it merged! I added feedback on how we can get this in a really good update. What I also propose:
Would you be able to look through my comments, see if you agree with the proposed dataclassses, and if so create a new PR that only updates the types? |
I realised we can just use |
I had the growing suspicion as I worked on this that |
gpt_engineer/models.py
Outdated
class Step(Enum): | ||
CLARIFY = "clarify" | ||
RUN_CLARIFIED = "run_clarified" |
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.
class Step(Enum): | |
CLARIFY = "clarify" | |
RUN_CLARIFIED = "run_clarified" |
I think I will move the support for mulitple models to a new PR, just focus this one on improving typing etc. |
I took the liberty of fixing a couple of simple conflicts (requirements related), please make sure to pull! Also, it seems |
Ping me when I should review! |
Curious about progress @Jeadie |
My idea of introducing dataclass of Messages needs quite some work with appending messages so I'd be happy to reconsider |
Hey! Good ideas here. I'm not sure if we should merge or if we should use the ideas and do a new PR altogether. For example, maybe we want to put messages in its own file and give it classmethods like "to_dict" etc. Regardless: before merging, would be good to look at how e.g. langchain and others handles this. |
I agree |
Looking into Langchain, this is their data structures for their messages, source. class BaseMessage(Serializable):
"""Message object."""
content: str
additional_kwargs: dict = Field(default_factory=dict)
@property
@abstractmethod
def type(self) -> str:
"""Type of the message, used for serialization."""
@property
def lc_serializable(self) -> bool:
"""This class is LangChain serializable."""
return True Subclasses are for various use cases, for example: HumanMessage, AIMessage, FunctionMessage. These messages are based off a It appears to be a similar approach. One difference is the use of a type property instead of a separate type/role enum. For example, in LangChain @property
def type(self) -> str:
"""Type of the message, used for serialization."""
return "human" |
These then get used internally per specific use cases, which provide public methods and uses these message types internally. For example (source) class BaseChatMessageHistory(ABC):
"""Base interface for chat message history
See `ChatMessageHistory` for default implementation.
"""
"""
Example:
.. code-block:: python
class FileChatMessageHistory(BaseChatMessageHistory):
storage_path: str
session_id: str
@property
def messages(self):
with open(os.path.join(storage_path, session_id), 'r:utf-8') as f:
messages = json.loads(f.read())
return messages_from_dict(messages)
def add_message(self, message: BaseMessage) -> None:
messages = self.messages.append(_message_to_dict(message))
with open(os.path.join(storage_path, session_id), 'w') as f:
json.dump(f, messages)
def clear(self):
with open(os.path.join(storage_path, session_id), 'w') as f:
f.write("[]")
"""
messages: List[BaseMessage]
def add_user_message(self, message: str) -> None:
"""Add a user message to the store"""
self.add_message(HumanMessage(content=message))
... |
Makes sense. We really value simplicity so I am inclined to u turn in the name of simplicity here and just have a Message class and use lists like you suggested initially. |
Improvements