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

Line breaks in free text responses causing answer to be truncated #1526

Open
rbyh opened this issue Jan 24, 2025 · 4 comments
Open

Line breaks in free text responses causing answer to be truncated #1526

rbyh opened this issue Jan 24, 2025 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@rbyh
Copy link
Contributor

rbyh commented Jan 24, 2025

Compare answer and generated tokens:
https://www.expectedparrot.com/content/571cc86a-282b-410b-8d21-530b9577a92d

@rbyh rbyh added the enhancement New feature or request label Jan 24, 2025
@rbyh
Copy link
Contributor Author

rbyh commented Jan 24, 2025

answer:
White breath in the air, Frozen ground crunches below,

generated_tokens:
White breath in the air, Frozen ground crunches below, Winter's silent sleep.

raw_model_response:
{'candidates': [{'content': {'parts': [{'text': "White breath in the air,\nFrozen ground crunches below,\nWinter's silent sleep. \n"}], 'role': 'model'}, 'finish_reason': 1, 'safety_ratings': [{'category': 8, 'probability': 1, 'blocked': False}, {'category': 10, 'probability': 1, 'blocked': False}, {'category': 7, 'probability': 1, 'blocked': False}, {'category': 9, 'probability': 1, 'blocked': False}], 'avg_logprobs': -0.0750277421691201, 'token_count': 0, 'grounding_attributions': []}], 'usage_metadata': {'prompt_token_count': 9, 'candidates_token_count': 22, 'total_token_count': 31, 'cached_content_token_count': 0}, 'model_version': 'gemini-1.5-flash'}

We can see that the raw response does include \n proper line breaks, so the issue is extracting and formatting the response.

@rbyh
Copy link
Contributor Author

rbyh commented Jan 24, 2025

The issue appears to be that this method is looking for the last \n new line character and treating it as a comment, but free text does not include a comment:

if last_newline == -1:

@rbyh
Copy link
Contributor Author

rbyh commented Jan 24, 2025

@johnjosephhorton I think it could be safer/cleaner for the instruction to be to use the word 'comment' (or ## would be better?) to mark where the comment starts. This issue seems most likely to occur with free text questions, but you could imagine line breaks being used in question list or dict responses, especially if text is being quoted in the answer. (We have to let LLMs recite poetry!) I don't think we should just "fix" it for free text by having a special prompt to try to handle some unknown number of line breaks.

@rbyh
Copy link
Contributor Author

rbyh commented Jan 24, 2025

Related edge case issue: if the user adds an instruction to not add a comment in the question text instead of modifying answering instructions or using include_comment=False the issue can occur. But I don't think this is going to happen often.

Another option could be to also have a default comment field for free text questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants