mirror of
https://github.com/cline/cline.git
synced 2026-09-19 10:13:34 +08:00
* log + options * changeset --------- Co-authored-by: Cline Evaluation <cline@example.com>
32 lines
748 B
TypeScript
32 lines
748 B
TypeScript
import { Anthropic } from "@anthropic-ai/sdk"
|
|
|
|
const formatImagesIntoBlocks = (images?: string[]): Anthropic.ImageBlockParam[] => {
|
|
return images
|
|
? images.map((dataUrl) => {
|
|
// data:image/png;base64,base64string
|
|
const [rest, base64] = dataUrl.split(",")
|
|
const mimeType = rest.split(":")[1].split(";")[0]
|
|
return {
|
|
type: "image",
|
|
source: {
|
|
type: "base64",
|
|
media_type: mimeType,
|
|
data: base64,
|
|
},
|
|
} as Anthropic.ImageBlockParam
|
|
})
|
|
: []
|
|
}
|
|
|
|
export const formatResponse = {
|
|
imageBlocks: (images?: string[]): Anthropic.ImageBlockParam[] => {
|
|
return formatImagesIntoBlocks(images)
|
|
},
|
|
}
|
|
|
|
export function log(isVerbose: boolean, message: string) {
|
|
if (isVerbose) {
|
|
console.log(message)
|
|
}
|
|
}
|