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

Code before:
    try:
        original_prompt = work_request.thread.messages[-1].content
        if not original_prompt:
            raise ValueError("Prompt is empty")

        language = "English"
        plugin = next((p for p in parameters.plugins if p.enabled), None)

        tools_instructions_template, tools = compose_tools_from_plugin(plugin)
        plugin_enabled = len(tools) > 0
        memory: ConversationBufferMemory = build_memory(work_request)

        TEMPLATE = f"""{V2_PROMPTER_PREFIX}{PREFIX}{tools_instructions_template}{SUFFIX}"""
        input_variables = [
            "input",
            "chat_history",
            "language",
            "current_time",
            "action_input_format",
            "custom_instructions",
        ] + (["tools_names"] if plugin_enabled else [])

        # TODO: Consider passing language from the UI here
        prompt_template = PromptTemplate(input_variables=input_variables, template=TEMPLATE)

        custom_instructions = f"""\n{CUSTOM_INSTRUCTIONS_PREFIX.format(
            user_profile=work_request.parameters.user_profile,
            user_response_instructions=work_request.parameters.user_response_instructions,
        )}"""

        if plugin_enabled:
            return handle_plugin_usage(
                original_prompt,
                prompt_template,
                language,
                memory,
                worker_config,
                tokenizer,
                parameters,
                tools,
                plugin,
                work_request.parameters.plugin_max_depth,
                ws,
                work_request.id,
                custom_instructions,
            )

        return handle_standard_usage(
            original_prompt, prompt_template, language, memory, worker_config, tokenizer, custom_instructions
        )
    except Exception as e:

Review comment (suggestion):
Also here - surely if `user_profile` and `user_response_instructions` are empty, we want this value `custom_instructions` to also be an entirely empty string, without the contents of `CUSTOM_INSTRUCTIONS_PREFIX`

Code after:
    try:
        original_prompt = work_request.thread.messages[-1].content
        if not original_prompt:
            raise ValueError("Prompt is empty")

        language = "English"
        plugin = next((p for p in parameters.plugins if p.enabled), None)

        tools_instructions_template, tools = compose_tools_from_plugin(plugin)
        plugin_enabled = len(tools) > 0
        memory: ConversationBufferMemory = build_memory(work_request)

        TEMPLATE = f"""{V2_PROMPTER_PREFIX}{PREFIX}{tools_instructions_template}{SUFFIX}"""
        input_variables = [
            "input",
            "chat_history",
            "language",
            "current_time",
            "action_input_format",
            "custom_instructions",
        ] + (["tools_names"] if plugin_enabled else [])

        # TODO: Consider passing language from the UI here
        prompt_template = PromptTemplate(input_variables=input_variables, template=TEMPLATE)

        custom_instructions = (
            f"""\n{CUSTOM_INSTRUCTIONS_PREFIX.format(
            user_profile=work_request.parameters.user_profile,
            user_response_instructions=work_request.parameters.user_response_instructions,
        )}"""
            if work_request.parameters.user_response_instructions or work_request.parameters.user_profile
            else ""
        )

        if plugin_enabled:
            return handle_plugin_usage(
                original_prompt,
                prompt_template,
                language,
                memory,
                worker_config,
                tokenizer,
                parameters,
                tools,
                plugin,
                work_request.parameters.plugin_max_depth,
                ws,
                work_request.id,
                custom_instructions,
            )