memos icon indicating copy to clipboard operation
memos copied to clipboard

Error on the openAI integration when using quotes

Open lucianosb opened this issue 3 years ago • 1 comments

Describe the bug

When using quotes in a question for the openAI API, we get an error stating:

Failed to post chat completion, internal={"code":null,"message":"We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please send an email to [email protected] and include any relevant code you'd like help with.

Steps to reproduce

  1. Click on Ask AI
  2. Ask a question with quotes such as: Is "I love you" a positive or negative message?

Screenshots or additional context

No response

lucianosb avatar Mar 06 '23 11:03 lucianosb

maybe should do some reg for user input https://github.com/usememos/memos/blob/595dbdb0ecb1eada129e21f1c1580d86dd256534/web/src/components/AskAIDialog.tsx#L61

perhaps like this:

await api.postChatCompletion(question.replace(/"|“|“/, '\\"')); 

jaywhen avatar Mar 06 '23 16:03 jaywhen