def run_full_turn()

in 2-assistants/3_tools.py [0:0]


def run_full_turn(system_message, tools, messages):

    tool_schemas = [function_to_schema(f) for f in tools]

    response = client.chat.completions.create(
        model=model,
        messages=[{"role": "system", "content": system_message}] + messages,
        tools=tool_schemas,
    )
    message = response.choices[0].message
    messages.append(message)

    if message.content:
        print(color("Assistant:", "yellow"), message.content)

    if not message.tool_calls:
        return message

    # print tool calls
    for tool_call in message.tool_calls:
        name = tool_call.function.name
        args = json.loads(tool_call.function.arguments)
        print(
            color("Assistant:", "yellow"),
            color(f"Executing tool call: {tool_call.function.name}({args})", "magenta"),
        )

    return message