MCPcopy Create free account
hub / github.com/di-sukharev/opencommit / assignRoleToPartsAndValidateSendMessageRequest

Function assignRoleToPartsAndValidateSendMessageRequest

out/cli.cjs:79300–79324  ·  view source on GitHub ↗
(parts)

Source from the content-addressed store, hash-verified

79298 newParts.push({ text: partOrString });
79299 } else {
79300 newParts.push(partOrString);
79301 }
79302 }
79303 }
79304 return assignRoleToPartsAndValidateSendMessageRequest(newParts);
79305}
79306function assignRoleToPartsAndValidateSendMessageRequest(parts) {
79307 const userContent = { role: "user", parts: [] };
79308 const functionContent = { role: "function", parts: [] };
79309 let hasUserContent = false;
79310 let hasFunctionContent = false;
79311 for (const part of parts) {
79312 if ("functionResponse" in part) {
79313 functionContent.parts.push(part);
79314 hasFunctionContent = true;
79315 } else {
79316 userContent.parts.push(part);
79317 hasUserContent = true;
79318 }
79319 }
79320 if (hasUserContent && hasFunctionContent) {
79321 throw new GoogleGenerativeAIError("Within a single message, FunctionResponse cannot be mixed with other type of part in the request for sending chat message.");
79322 }
79323 if (!hasUserContent && !hasFunctionContent) {
79324 throw new GoogleGenerativeAIError("No content is provided for sending chat message.");
79325 }
79326 if (hasUserContent) {
79327 return userContent;

Callers 1

formatNewContentFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected