Add Handling of Cache Prompt When Formatting Messages (#3773)

* Add Handling of Cache Prompt When Formatting Messages

* Fix Value for Cache Control

* Fix Value for Cache Control

* Update openhands/core/message.py

Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>

* Fix lint error

* Serialize Messages if Propt Caching Is Enabled

* Remove formatting message change

---------

Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
Co-authored-by: tobitege <10787084+tobitege@users.noreply.github.com>
This commit is contained in:
Cole Murray
2024-09-10 09:34:41 -07:00
committed by GitHub
parent 06ed142191
commit 97a03faf33
3 changed files with 11 additions and 4 deletions

View File

@@ -72,12 +72,14 @@ class Message(BaseModel):
def format_messages(
messages: Union[Message, list[Message]], with_images: bool
messages: Union[Message, list[Message]],
with_images: bool,
with_prompt_caching: bool,
) -> list[dict]:
if not isinstance(messages, list):
messages = [messages]
if with_images:
if with_images or with_prompt_caching:
return [message.model_dump() for message in messages]
converted_messages = []
@@ -113,4 +115,5 @@ def format_messages(
'content': content_str,
}
)
return converted_messages