compose-chatgpt-kotlin-android-chatbot icon indicating copy to clipboard operation
compose-chatgpt-kotlin-android-chatbot copied to clipboard

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

Open TimRivoli opened this issue 1 year ago • 5 comments

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

TimRivoli avatar Aug 20 '23 23:08 TimRivoli

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.

YoungJeansKR avatar Sep 26 '23 10:09 YoungJeansKR

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

sollarp avatar Sep 28 '23 22:09 sollarp

@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?

YoungJeansKR avatar Sep 30 '23 08:09 YoungJeansKR

@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 " "
}

sollarp avatar Sep 30 '23 21:09 sollarp

@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:)

YoungJeansKR avatar Oct 01 '23 05:10 YoungJeansKR