mishig HF staff commited on
Commit
d88d726
1 Parent(s): 9a35ef2

Escape single quotes in CURL snippets

Browse files
src/lib/components/InferencePlayground/InferencePlaygroundCodeSnippets.svelte CHANGED
@@ -220,7 +220,11 @@ print(output.choices[0].message)`,
220
  const formattedMessages = ({ sep, start, end }: MessagesJoiner) =>
221
  start +
222
  getMessages()
223
- .map(({ role, content }) => `{ "role": "${role}", "content": "${content}" }`)
 
 
 
 
224
  .join(sep) +
225
  end;
226
 
 
220
  const formattedMessages = ({ sep, start, end }: MessagesJoiner) =>
221
  start +
222
  getMessages()
223
+ .map(({ role, content }) => {
224
+ // escape single quotes since single quotes is used to define http post body inside curl requests
225
+ content = content?.replace(/'/g, "'\\''");
226
+ return `{ "role": "${role}", "content": "${content}" }`;
227
+ })
228
  .join(sep) +
229
  end;
230