i have this original function that operates fine

def process_move(move, game_board):

global san_moves, sa_number, total_moves, history, user_turn, chat_window, valid_moves, llm_turn, board



try:

    if llm_turn:

        result_label.config(text="It's not your turn to move.")

        return



    if move in game_board.legal_moves:

        game_board.push(move)

        fen_notation = game_board.fen()

        shredder_fen = chess.Board(fen_notation)

        result_label.config(text=f"FEN Notation: {fen_notation}")

        draw_board(game_board)



        if total_moves % 2 == 1:

            sa_number += 1

            san_moves += f"{sa_number}. {move} "

            total_moves += 1

            history = []

            move_list = re.findall(r'\((.*?)\)', str(valid_moves))

            chat_window.delete(1.0, tk.END)

            role = "user"

        else:

            san_moves += f"{move} "

            total_moves += 1



        print("SAN Moves:", san_moves)



        if move_list == ['']:

            message = "Checkmate."

            chat_window.insert(tk.END, f"\nCheckmate")

        else:

            message = f"Check out the state of this board\n\n {shredder_fen}. What should this tell me about the move I need to make. I can only choose moves from this list, {move_list}.\n\n I can only choose moves from this list, {move_list}. Help me pick the best move, and reply with one word, move."

            history.append({"role": role, "content": message})















            interact_with_llm(message)

            print("line 77")



        llm_turn = True

        last_assistant_message = next((item['content'] for item in reversed(history) if item['role'] == 'assistant'), None)







        if last_assistant_message:

            first_word = last_assistant_message.split()[0]

            llm_move = first_word.replace('.', '')

            print(llm_move)

            match = re.search(r'([a-hA-H])(\d)', llm_move)

            print(f"the match is {match}")

            if match:

                # Extract the entire matched substring

                llm_square_notation = match.group(0)

                print(f"the match is {llm_square_notation}")

                # Get attackers for the dynamically determined square

                attackers = board.attackers(chess.WHITE, chess.parse_square(llm_square_notation.lower()))

                print(attackers)

                update_game_board(llm_move)

                llm_turn = False

            else:

                print("Invalid move format.")





except Exception as e:

    print(f"Error in LLM request: {e}")

    chat_window.insert(tk.END, "\nAssistant: Error in LLM request")

except ValueError:

    result_label.config(text="Invalid move")
i tried splitting the function into two functions, like this:

def process_move(move, game_board):

global san_moves, sa_number, total_moves, history, user_turn, chat_window, valid_moves, llm_turn, board



try:

    if llm_turn:

        result_label.config(text="It's not your turn to move.")

        return



    if move in game_board.legal_moves:

        game_board.push(move)

        draw_board(game_board)

        sa_number += 1

        san_moves += f"{sa_number}. {move} "

        total_moves += 1

        move_list = re.findall(r'\((.*?)\)', str(valid_moves))

        print("SAN Moves:", san_moves)



        if move_list == ['']:

            message = "Checkmate."

            chat_window.insert(tk.END, f"\nCheckmate")

        else:

            llm_move_choice()



except ValueError:

    result_label.config(text="Invalid move")
def llm_move_choice():

global san_moves, sa_number, total_moves, history, user_turn, chat_window, valid_moves, llm_turn, board

chat_window.delete(1.0, tk.END)

fen_notation = game_board.fen()

shredder_fen = chess.Board(fen_notation)

result_label.config(text=f"FEN Notation: {fen_notation}")

history = []

role = "user"

move_list = re.findall(r'\((.*?)\)', str(valid_moves))

message = f"Check out the state of this board\n\n {shredder_fen}. What should this tell me about the move I need to make. I can only choose moves from this list, {move_list}.\n\n I can only choose moves from this list, {move_list}. Help me pick the best move, and reply with one word, move."

history.append({"role": role, "content": message})

interact_with_llm(message)

print("line 78")

last_assistant_message = next((item['content'] for item in reversed(history) if item['role'] == 'assistant'), None)

if last_assistant_message:

    first_word = last_assistant_message.split()[0]

    llm_move = first_word.replace('.', '')

    print(f"llm_move from line 83 is {llm_move}")

    match = re.search(r'([a-hA-H])(\d)', llm_move)

    print(f"the match is {match}")

    if match:

        # Extract the entire matched substring

        llm_square_notation = match.group(0)

        print(f"the match is {llm_square_notation}")

        # Get attackers for the dynamically determined square

        attackers = board.attackers(chess.WHITE, chess.parse_square(llm_square_notation.lower()))

        print(attackers)

        update_game_board(llm_move)

        llm_turn = False

    else:

        print("Invalid move format.")





except Exception as e:

    print(f"Error in LLM request: {e}")

    chat_window.insert(tk.END, "\nAssistant: Error in LLM request")

except ValueError:

    result_label.config(text="Invalid move")