-
-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
239 additions
and
115 deletions.
There are no files selected for viewing
Empty file.
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,47 @@ | ||
""" | ||
shared functions for format transforms | ||
""" | ||
from axolotl.core.chat.messages import MessageContents, Messages | ||
|
||
|
||
def wrap_tools(message: Messages): | ||
# loop over message.content by index to find tool calls, we need to wrap each with tags, | ||
# so be wary of indexing issues when changing the list while iterating. | ||
# iterate over the range in reverse order to avoid index shifting | ||
for i in range(len(message.content) - 1, -1, -1): | ||
if message.content[i].type == "tool_call": | ||
# append a </tool_call> MessageContents text tag after | ||
message.content.insert( | ||
i + 1, | ||
MessageContents( | ||
type="text", value="</tool_call>\n", weight=message.weight | ||
), | ||
) | ||
# make sure the actual tool call content ends with a newline | ||
message.content[i].has_newline = True | ||
# prepend a <tool_call> MessageContents text tag before | ||
message.content.insert( | ||
i, | ||
MessageContents( | ||
type="text", value="<tool_call>\n", weight=message.weight | ||
), | ||
) | ||
elif message.content[i].type == "tool_response": | ||
# append a </tool_call> MessageContents text tag after | ||
message.content.insert( | ||
i + 1, | ||
MessageContents( | ||
type="text", value="</tool_response>\n", weight=message.weight | ||
), | ||
) | ||
# make sure the actual tool response content ends with a newline | ||
message.content[i].has_newline = True | ||
# prepend a <tool_call> MessageContents text tag before | ||
message.content.insert( | ||
i, | ||
MessageContents( | ||
type="text", value="<tool_response>\n", weight=message.weight | ||
), | ||
) | ||
|
||
return message |
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.