pi / packages /ai /src /utils /text.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
98077a8 verified
Raw History Blame Contribute Delete
470 Bytes
import type { ImageContent, TextContent, ThinkingContent, ToolCall } from "../types.ts";
type Content = TextContent | ImageContent | ThinkingContent | ToolCall;
/** Extract and join text from message content. */
export function contentText(content: string | readonly Content[], separator = "\n"): string {
if (typeof content === "string") return content;
return content
.filter((block) => block.type === "text")
.map((block) => block.text)
.join(separator);
}