Skip to content

Commit 752b033

Browse files
committed
chore: boost, basic tool calls proxying, logger revamp
1 parent 2187a57 commit 752b033

File tree

8 files changed

+440
-80
lines changed

8 files changed

+440
-80
lines changed

boost/src/chat.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ class Chat:
1212
tail: ChatNode
1313
llm: Optional['llm.LLM']
1414

15+
@staticmethod
1516
def from_conversation(messages):
1617
tail = ChatNode.from_conversation(messages)
1718
return Chat(tail=tail)
1819

20+
@staticmethod
1921
def from_tail(chat: 'Chat'):
2022
new_tail = ChatNode(role=chat.tail.role, content=chat.tail.content)
2123
return Chat(tail=new_tail)
@@ -52,6 +54,16 @@ def add_message(self, role, content):
5254

5355
return self.tail
5456

57+
def tool_call(self, tool_call):
58+
self.add_message('assistant', '')
59+
self.tail.tool_calls = [tool_call]
60+
return self.tail
61+
62+
def tool(self, id, content):
63+
self.add_message('tool', content)
64+
self.tail.tool_call_id = id
65+
return self.tail
66+
5567
def user(self, content):
5668
return self.add_message('user', content)
5769

boost/src/chat_node.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class ChatNode:
1010
id: str
1111
content: str
1212
role: str
13+
tool_call_id: Optional[str]
14+
tool_calls: Optional[List[dict]]
1315

1416
parent: Optional['ChatNode']
1517
children: List['ChatNode']
@@ -18,6 +20,7 @@ class ChatNode:
1820
value: float
1921
meta: dict
2022

23+
@staticmethod
2124
def from_conversation(messages):
2225
root_message = messages[0]
2326
node = ChatNode(role=root_message['role'], content=root_message['content'])
@@ -44,6 +47,9 @@ def __init__(self, **kwargs):
4447

4548
self.meta = kwargs.get('meta', {})
4649

50+
self.tool_call_id = kwargs.get('tool_call_id', None)
51+
self.tool_calls = kwargs.get('tool_calls', [])
52+
4753
def add_parent(self, new_parent: 'ChatNode'):
4854
# Guard against None and self-reference
4955
if new_parent is None or self == new_parent:
@@ -111,11 +117,19 @@ def parents(self):
111117
return parents[::-1]
112118

113119
def message(self):
114-
return {
120+
result = {
115121
"role": self.role,
116122
"content": self.content,
117123
}
118124

125+
if self.tool_call_id is not None:
126+
result["tool_call_id"] = self.tool_call_id
127+
128+
if self.tool_calls:
129+
result["tool_calls"] = self.tool_calls
130+
131+
return result
132+
119133
def ancestor(self):
120134
node = self
121135
while node.parent:

0 commit comments

Comments
 (0)