@@ -154,14 +154,28 @@ func (ast *Assistant) HookDone(c *gin.Context, context chatctx.Context, input []
154
154
props := map [string ]interface {}{}
155
155
if text , ok := data .Props ["text" ].(string ); ok {
156
156
157
- // Remove <tool> and </tool> tags
158
- text = strings .ReplaceAll (text , "<tool>" , "" )
159
- text = strings .ReplaceAll (text , "</tool>" , "" )
157
+ // Format the text keep only the <tool> and </tool> inner text
158
+ parts := strings .Split (text , "<tool>" )
159
+ if len (parts ) > 1 {
160
+ text = parts [1 ]
161
+ }
162
+
163
+ // Format the text keep only the <tool> and </tool> inner text
164
+ parts = strings .Split (text , "</tool>" )
165
+ if len (parts ) > 1 {
166
+ text = parts [0 ]
167
+ }
168
+
169
+ // Escape %7B and %7b to {, %7D and %7d to }
170
+ text = strings .ReplaceAll (text , "%7B" , "{" )
171
+ text = strings .ReplaceAll (text , "%7b" , "{" )
172
+ text = strings .ReplaceAll (text , "%7D" , "}" )
173
+ text = strings .ReplaceAll (text , "%7d" , "}" )
160
174
161
175
// Parse the text into props
162
176
err := jsoniter .UnmarshalFromString (text , & props )
163
177
if err != nil {
164
- props ["error" ] = err .Error ()
178
+ props ["error" ] = fmt . Sprintf ( "Can not parse the tool call: %s \n --original-- \n %s" , err .Error (), text )
165
179
}
166
180
}
167
181
0 commit comments