File size: 647 Bytes
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
import { getInference } from '$lib/agents/getInference';
import type { ImageToTextArgs, ImageToTextOutput } from '@huggingface/inference';
import type { Tool } from './tool';

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;
	}
};