File size: 812 Bytes
ceb70c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
# SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org>
# SPDX-License-Identifier: Apache-2.0
#

def assistant_response(response_message):
    extracted_tool_calls = []
    
    if getattr(response_message, "tool_calls", None):
        for tool_call in response_message.tool_calls:
            extracted_tool_calls.append(
                {
                    "id": tool_call.id,
                    "type": "function",
                    "function": {
                        "name": tool_call.function.name,
                        "arguments": tool_call.function.arguments
                    }
                }
            )
    
    return {
        "role": "assistant",
        "content": response_message.content or "",
        "tool_calls": extracted_tool_calls if extracted_tool_calls else None
    }