Skip to content

Commit

Permalink
fix: Prevent error when parsing invalid json out of tool calls (#6217)
Browse files Browse the repository at this point in the history
  • Loading branch information
cephalization authored Jan 31, 2025
1 parent 71c6c39 commit 0482e87
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/src/pages/trace/SpanDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ function LLMSpanInfo(props: { span: Span; spanAttributes: AttributeObject }) {
const hasOutputMessages = outputMessages.length > 0;
const hasPrompts = prompts.length > 0;
const hasInvocationParams =
Object.keys(JSON.parse(invocation_parameters_str)).length > 0;
Object.keys(safelyParseJSON(invocation_parameters_str).json || {}).length >
0;
const hasPromptTemplateObject = promptTemplateObject != null;

return (
Expand Down Expand Up @@ -1323,6 +1324,10 @@ function LLMMessage({ message }: { message: AttributeMessage }) {
) : null}
{toolCalls.length > 0
? toolCalls.map((toolCall, idx) => {
const parsedArguments = safelyParseJSON(
toolCall?.function?.arguments as string
);

return (
<pre
key={idx}
Expand All @@ -1332,13 +1337,9 @@ function LLMMessage({ message }: { message: AttributeMessage }) {
`}
>
{toolCall?.function?.name as string}(
{typeof toolCall?.function?.arguments === "string"
? JSON.stringify(
JSON.parse(toolCall?.function?.arguments as string),
null,
2
)
: ""}
{parsedArguments.json
? JSON.stringify(parsedArguments.json, null, 2)
: `${toolCall?.function?.arguments}`}
)
</pre>
);
Expand Down

0 comments on commit 0482e87

Please sign in to comment.