File size: 714 Bytes
988ce90
 
 
 
 
39b5447
57e16da
988ce90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57e16da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { getInference } from "$lib/agents/getInference";
import type {
  ImageToTextArgs,
  ImageToTextOutput,
} from "@huggingface/inference";
import type { Tool } from "$lib/types";

export const imageToTextTool: Tool<
  ImageToTextArgs["data"],
  ImageToTextOutput["generated_text"]
> = {
  name: "imageToText",
  description: "Caption an image.",
  examples: [
    {
      prompt: "Describe the image",
      command: "imageToText(image)",
    },
  ],
  call: async (input) => {
    return (
      await getInference().imageToText(
        {
          data: await input,
          model: "nlpconnect/vit-gpt2-image-captioning",
        },
        { wait_for_model: true }
      )
    ).generated_text;
  },
};