Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: multi-line answer is empty from ReAct agent #7690

Closed
vitalyford opened this issue Sep 15, 2023 · 1 comment
Closed

[Bug]: multi-line answer is empty from ReAct agent #7690

vitalyford opened this issue Sep 15, 2023 · 1 comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized

Comments

@vitalyford
Copy link

vitalyford commented Sep 15, 2023

Bug Description

Based on extra_final_response() from llama_index/agent/react/output_parser.py, the answer will be extracted until a new line character is encountered or the end of the string. In cases when the final answer spans across multiple lines, it will return an empty response.

A possible fix is to remove \n| and just keep $. But then what's the usability of $ there? Need to put more thinking into it though if anything else is affected by it; hence, no PR yet. Has someone encountered this before?

Version

0.8.27

Steps to Reproduce

Query a ReAct agent to respond in an enumerated or bullet-list style.

Relevant Logs/Tracbacks

No response

@vitalyford vitalyford added bug Something isn't working triage Issue needs to be triaged/prioritized labels Sep 15, 2023
@dosubot
Copy link

dosubot bot commented Sep 15, 2023

🤖

Hello,

Thank you for bringing this issue to our attention. You're correct in your observation that the extract_final_response() function in llama_index/agent/react/output_parser.py could potentially return an empty response when the final answer spans across multiple lines. This is due to the regular expression pattern used in the function, which stops matching at the first newline character.

Your proposed solution of removing \n| and just keeping $ in the regular expression pattern could potentially fix this issue. This modification would allow the regular expression to match until the end of the string, regardless of newline characters. Here's how the modified function might look:

def extract_final_response(input_text: str) -> Tuple[str, str]:
    pattern = r"\s*Thought:(.*?)Answer:(.*?)(?:$)"

    match = re.search(pattern, input_text, re.DOTALL)
    if not match:
        raise ValueError(
            "Could not extract final answer from input text: {}".format(input_text)
        )

    thought = match.group(1).strip()
    answer = match.group(2).strip()
    return thought, answer

However, please note that this change could have other side effects depending on the structure of your input text. It's important to thoroughly test this modification with different scenarios to ensure it doesn't introduce new issues.

As for the exact structure of the input text that the extract_final_response() function is expected to handle, I wasn't able to find specific documentation within the LlamaIndex codebase. If you could provide more details about the structure of the input text you're working with, it would be helpful in further investigating this issue and proposing a more robust solution.

Best,
Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized
Projects
None yet
Development

No branches or pull requests

1 participant