Skip to content

Commit

Permalink
fix(tool content): escape back ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMcIntosh committed Jun 18, 2024
1 parent e3c15e1 commit 41cb5fe
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/components/ChatContent/ToolsContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const Chevron: React.FC<{ open: boolean }> = ({ open }) => {
const Result: React.FC<{ children: string }> = ({ children }) => {
const lines = children.split("\n");
const [open, setOpen] = React.useState(false);
if (lines.length < 3 || open)
if (lines.length < 4 || open)
return <Markdown className={styles.tool_result}>{children}</Markdown>;
const toShow = lines.slice(0, 3).join("\n") + "\n ";
const toShow = lines.slice(0, 6).join("\n") + "\n ";
return (
<Button
variant="ghost"
Expand All @@ -45,6 +45,7 @@ const ToolMessage: React.FC<{
toolCall: ToolCall;
result?: ToolResult;
}> = ({ toolCall, result }) => {
const results = result?.content ?? "";
const name = toolCall.function.name ?? "";

const argsString = React.useMemo(() => {
Expand All @@ -65,15 +66,15 @@ const ToolMessage: React.FC<{

const functionCalled = "```python\n" + name + "(" + argsString + ")\n```";

if (!result?.content) {
return <Markdown>{functionCalled}</Markdown>;
}
const escapedBackticks = results.replace(/`+/g, (match) => {
if (match === "```") return match;
return "\\" + "`";
});

// show more
const content = functionCalled + "\n" + escapedBackticks;
return (
<Flex gap="2" direction="column">
<Markdown>{functionCalled}</Markdown>
<Result>{result.content}</Result>
<Result>{content}</Result>
</Flex>
);
};
Expand Down

0 comments on commit 41cb5fe

Please sign in to comment.