@sap-ai-sdk/foundation-models
Version:
SAP Cloud SDK for AI is the official Software Development Kit (SDK) for **SAP AI Core**, **SAP Generative AI Hub**, and **Orchestration Service**.
48 lines • 1.57 kB
JavaScript
/**
* @internal
* Check if the accumulator is a AzureOpenAiChatCompletionMessageToolCall.
*/
export function isMessageToolCall(acc) {
return (typeof acc.id === 'string' &&
typeof acc.function.name === 'string' &&
typeof acc.function.arguments === 'string');
}
/**
* Merge a stream of AzureOpenAiChatCompletionMessageToolCallChunk into a single AzureOpenAiChatCompletionMessageToolCall.
* @throws If the final object is missing required fields.
* @internal
*/
export function mergeToolCallChunk(chunk, acc) {
const accumulator = acc
? { ...acc }
: {
type: 'function',
function: {}
};
if (chunk.id) {
accumulator.id = chunk.id;
}
// Merge any extra top‐level props
for (const key of Object.keys(chunk)) {
if (!['index', 'id', 'type', 'function'].includes(key)) {
accumulator[key] = chunk[key];
}
}
if (chunk.function) {
if (chunk.function.name) {
accumulator.function.name = chunk.function.name;
}
if (chunk.function.arguments) {
accumulator.function.arguments =
(accumulator.function.arguments || '') + chunk.function.arguments;
}
// Merge any extra function‐scoped fields
for (const key of Object.keys(chunk.function)) {
if (!['name', 'arguments'].includes(key)) {
accumulator.function[key] = chunk.function[key];
}
}
}
return accumulator;
}
//# sourceMappingURL=tool-calls.js.map