Repository: LAION-AI/Open-Assistant
File: inference/worker/chat_chain.py (Python)

Code before:
    inner_monologue.append("In: " + str(init_prompt))
    inner_monologue.append("Out: " + str(chain_response))

    current_action_thought = ""
    if THOUGHT_SEQ in chain_response:
        current_action_thought = chain_response.split(THOUGHT_SEQ)[1].split("\n")[0]

    # Tool name/assistant prefix, Tool input/assistant response
    prefix, response = extract_tool_and_input(llm_output=chain_response, ai_prefix=ASSISTANT_PREFIX)
    assisted = False if ASSISTANT_PREFIX in prefix else True
    chain_finished = not assisted

    if assisted:
        # model decided to use a tool, so send that thought to the client
        utils.send_response(
            ws,
            inference.PluginIntermediateResponse(
                request_id=work_request_id,
                current_plugin_thought=current_action_thought,
                current_plugin_action_taken=prefix,
                current_plugin_action_input=chain_response,
                current_plugin_action_response=response,
            ),
        )

    while not chain_finished and assisted and achieved_depth < MAX_DEPTH:
        tool_response = use_tool(prefix, response, tools)

        # Save previous chain response for use in final prompt
        prev_chain_response = chain_response
        new_prompt = f"{input_prompt}{eos_token}{V2_ASST_PREFIX}{chain_response}{OBSERVATION_SEQ} {tool_response}"

        new_prompt, chain_response = chain.call(new_prompt)

        inner_monologue.append("In: " + str(new_prompt))
        inner_monologue.append("Out: " + str(chain_response))

        current_action_thought = ""
        if THOUGHT_SEQ in chain_response:
            current_action_thought = chain_response.split(THOUGHT_SEQ)[1].split("\n")[0]

        # Send deep plugin intermediate steps to UI
        utils.send_response(
            ws,
            inference.PluginIntermediateResponse(
                request_id=work_request_id,
                current_plugin_thought=current_action_thought,
                current_plugin_action_taken=prefix,
                current_plugin_action_input=chain_response,
                current_plugin_action_response=response,
            ),

Review comment (suggestion):
This seems to have been a bad merge with main - `MAX_DEPTH` constant doesn't exist anymore, should be using the `plugin_max_depth` parameter

Code after:
    inner_monologue.append("In: " + str(init_prompt))
    inner_monologue.append("Out: " + str(chain_response))

    current_action_thought = ""
    if THOUGHT_SEQ in chain_response:
        current_action_thought = chain_response.split(THOUGHT_SEQ)[1].split("\n")[0]

    # Tool name/assistant prefix, Tool input/assistant response
    prefix, response = extract_tool_and_input(llm_output=chain_response, ai_prefix=ASSISTANT_PREFIX)
    assisted = False if ASSISTANT_PREFIX in prefix else True
    chain_finished = not assisted

    if assisted:
        # model decided to use a tool, so send that thought to the client
        utils.send_response(
            ws,
            inference.PluginIntermediateResponse(
                request_id=work_request_id,
                current_plugin_thought=current_action_thought,
                current_plugin_action_taken=prefix,
                current_plugin_action_input=chain_response,
                current_plugin_action_response=response,
            ),
        )

    while not chain_finished and assisted and achieved_depth < plugin_max_depth:
        tool_response = use_tool(prefix, response, tools)

        # Save previous chain response for use in final prompt
        prev_chain_response = chain_response
        new_prompt = f"{input_prompt}{eos_token}{V2_ASST_PREFIX}{chain_response}{OBSERVATION_SEQ} {tool_response}"

        new_prompt, chain_response = chain.call(new_prompt)

        inner_monologue.append("In: " + str(new_prompt))
        inner_monologue.append("Out: " + str(chain_response))

        current_action_thought = ""
        if THOUGHT_SEQ in chain_response:
            current_action_thought = chain_response.split(THOUGHT_SEQ)[1].split("\n")[0]

        # Send deep plugin intermediate steps to UI
        utils.send_response(
            ws,
            inference.PluginIntermediateResponse(
                request_id=work_request_id,
                current_plugin_thought=current_action_thought,
                current_plugin_action_taken=prefix,
                current_plugin_action_input=chain_response,
                current_plugin_action_response=response,
            ),