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

Feature request: Replace \n with a linefeed in the chat answers #14

Open
TimRivoli opened this issue Aug 20, 2023 · 5 comments
Open

Feature request: Replace \n with a linefeed in the chat answers #14

TimRivoli opened this issue Aug 20, 2023 · 5 comments

Comments

@TimRivoli
Copy link

The chat answers have \n instead of line feeds. That could be a simple string replacement and improve the appearance of the answers.

@YoungJeansKR
Copy link

The chat answers have \n instead of line feeds. That could be a simple string replacement and improve the appearance of the answers.

Have you solved it? I am also suffering from the same symptoms.

@sollarp
Copy link
Contributor

sollarp commented Sep 28, 2023

@TimRivoli I can have a look but can you be more specific. Where is this happening?

@lambiengcode lambiengcode pinned this issue Sep 29, 2023
@YoungJeansKR
Copy link

YoungJeansKR commented Sep 30, 2023

@TimRivoli I can have a look but can you be more specific. Where is this happening?

KakaoTalk_20230930_170121567

As shown in the picture above, when gpt answers a question, it does not recognize \n as a line feed and outputs it as is. Do you know a solution?

@sollarp
Copy link
Contributor

sollarp commented Sep 30, 2023

@TimRivoli I can have a look but can you be more specific. Where is this happening?

KakaoTalk_20230930_170121567

As shown in the picture above, when gpt answers a question, it does not recognize \n as a line feed and outputs it as is. Do you know a solution?

Hi, Unfortunately I can't test this code since my API key is some reason does not work in this app. I have tested my key in other apps and works ok with gpt-3.5 but not gpt-4 anyways. Can I ask you to test this with your API key and let me know If it's working. So I could do a proper pull request.

in OpenAIRepositoryImpl change the code at line 83 and 94 and paste this code.

private fun lookupDataFromResponse(jsonString: String): String {
val regex = """"text"\s*:\s*"([^"]+)"""".toRegex()
val matchResult = regex.find(jsonString)

if (matchResult != null && matchResult.groupValues.size > 1) {
    val extractedText = matchResult.groupValues[1]
    return extractedText.replace("\\n\\n", " ").replace("\\n", " ")
}

return " "
}

@YoungJeansKR
Copy link

YoungJeansKR commented Oct 1, 2023

@TimRivoli I can have a look but can you be more specific. Where is this happening?

KakaoTalk_20230930_170121567
As shown in the picture above, when gpt answers a question, it does not recognize \n as a line feed and outputs it as is. Do you know a solution?

Hi, Unfortunately I can't test this code since my API key is some reason does not work in this app. I have tested my key in other apps and works ok with gpt-3.5 but not gpt-4 anyways. Can I ask you to test this with your API key and let me know If it's working. So I could do a proper pull request.

in OpenAIRepositoryImpl change the code at line 83 and 94 and paste this code.

private fun lookupDataFromResponse(jsonString: String): String {
val regex = """"text"\s*:\s*"([^"]+)"""".toRegex()
val matchResult = regex.find(jsonString)

if (matchResult != null && matchResult.groupValues.size > 1) {
    val extractedText = matchResult.groupValues[1]
    return extractedText.replace("\\n\\n", " ").replace("\\n", " ")
}

return " "
}

As a result of testing, it works very well. \n is no longer printed and the replace function works fine. Thank you very much:)

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

No branches or pull requests

3 participants