hollo 에 코드도 잘 들어가나? (길이 제한은 있겠지만... )

// Name: OCR
// Description: Capture a screenshot and recognize the text using OpenAI

import "@johnlindquist/kit";
import OpenAI from 'openai';

const clipboardImage = await clipboard.readImage()

if (clipboardImage.byteLength) {
    const apiKey = await env("OPENAI_API_KEY")
    const openai = new OpenAI({
        apiKey: apiKey
    })

    console.log("OCR started")

    const imageBase64 = await clipboardImage.toString('base64')
    const dataUri = `data:image/png;base64,${imageBase64}`

    console.log("base64 done")
    console.log("calling openai...")

    const response = await openai.responses.create({
        model: 'gpt-4.1-mini',
        input: [
            {
                role: 'system',
                content: 'You are a OCR assistant that extracts text from images',
            },
            {
                role: 'user',
                content: [
                    {
                        type: 'input_text',
                        text: 'Extract the text from the image',
                    },
                    {
                        type: 'input_image',
                        image_url: dataUri,
                        detail: 'high',
                    },
                ],
            },
        ],
    });
    console.log("openai done")
    console.log(`writing to clipboard... ${response.output_text}`)

    await clipboard.writeText(response.output_text);

    notify({
        title: "OCR finished",
        message: `Copied text to your clipboard`,
    })
} else {
    notify({
        title: "OCR failed",
        message: `No image found in clipboard`,
    })
}
0

If you have a fediverse account, you can quote this note from your own instance. Search https://social.long-echo.net/@ysh/019648c8-b29e-75b1-9a25-ac18c3c4a5d1 on your instance and quote it. (Note that quoting is not supported in Mastodon.)