mishig HF staff commited on
Commit
6aa1896
1 Parent(s): 7705415

Better escape of contents of msg

Browse files
src/lib/components/InferencePlayground/InferencePlaygroundCodeSnippets.svelte CHANGED
@@ -58,6 +58,11 @@
58
  messages.unshift(systemMessage);
59
  }
60
 
 
 
 
 
 
61
  return messages;
62
  }
63
 
@@ -69,7 +74,7 @@
69
  const formattedMessages = ({ sep, start, end }: MessagesJoiner) =>
70
  start +
71
  getMessages()
72
- .map(({ role, content }) => `{ role: "${role}", content: "${content?.replace(/"/g, '\\"')}" }`)
73
  .join(sep) +
74
  end;
75
 
@@ -132,7 +137,7 @@ console.log(out.choices[0].message);`,
132
  const formattedMessages = ({ sep, start, end }: MessagesJoiner) =>
133
  start +
134
  getMessages()
135
- .map(({ role, content }) => `{ "role": "${role}", "content": "${content?.replace(/"/g, '\\"')}" }`)
136
  .join(sep) +
137
  end;
138
 
@@ -196,7 +201,7 @@ print(output.choices[0].message)`,
196
  const formattedMessages = ({ sep, start, end }: MessagesJoiner) =>
197
  start +
198
  getMessages()
199
- .map(({ role, content }) => `{ "role": "${role}", "content": "${content?.replace(/"/g, '\\"')}" }`)
200
  .join(sep) +
201
  end;
202
 
 
58
  messages.unshift(systemMessage);
59
  }
60
 
61
+ messages = messages.map(({ role, content }) => ({
62
+ role,
63
+ content: JSON.stringify(content).slice(1, -1),
64
+ }));
65
+
66
  return messages;
67
  }
68
 
 
74
  const formattedMessages = ({ sep, start, end }: MessagesJoiner) =>
75
  start +
76
  getMessages()
77
+ .map(({ role, content }) => `{ role: "${role}", content: "${content}" }`)
78
  .join(sep) +
79
  end;
80
 
 
137
  const formattedMessages = ({ sep, start, end }: MessagesJoiner) =>
138
  start +
139
  getMessages()
140
+ .map(({ role, content }) => `{ "role": "${role}", "content": "${content}" }`)
141
  .join(sep) +
142
  end;
143
 
 
201
  const formattedMessages = ({ sep, start, end }: MessagesJoiner) =>
202
  start +
203
  getMessages()
204
+ .map(({ role, content }) => `{ "role": "${role}", "content": "${content}" }`)
205
  .join(sep) +
206
  end;
207