mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-27 18:50:41 +00:00
# What does this PR do? Implements table and detail views for chat completions <img width="1548" alt="image" src="https://github.com/user-attachments/assets/01061b7f-0d47-4b3b-b5ac-2df8f9035ef6" /> <img width="1549" alt="image" src="https://github.com/user-attachments/assets/738d8612-8258-4c2c-858b-bee39030649f" /> ## Test Plan npm run test
33 lines
864 B
TypeScript
33 lines
864 B
TypeScript
/**
|
|
* Formats a tool_call object into a string representation.
|
|
* Example: "functionName(argumentsString)"
|
|
* @param toolCall The tool_call object, expected to have a `function` property
|
|
* with `name` and `arguments`.
|
|
* @returns A formatted string or an empty string if data is malformed.
|
|
*/
|
|
export function formatToolCallToString(toolCall: any): string {
|
|
if (
|
|
!toolCall ||
|
|
!toolCall.function ||
|
|
typeof toolCall.function.name !== "string" ||
|
|
toolCall.function.arguments === undefined
|
|
) {
|
|
return "";
|
|
}
|
|
|
|
const name = toolCall.function.name;
|
|
const args = toolCall.function.arguments;
|
|
let argsString: string;
|
|
|
|
if (typeof args === "string") {
|
|
argsString = args;
|
|
} else {
|
|
try {
|
|
argsString = JSON.stringify(args);
|
|
} catch (error) {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
return `${name}(${argsString})`;
|
|
}
|