File size: 775 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
27
28
import { getInference } from '$lib/agents/getInference';
import type { TextToImageArgs, TextToImageOutput } from '@huggingface/inference';
import type { Tool } from './tool';

export const textToImageTool: Tool<TextToImageArgs['inputs'], TextToImageOutput> = {
	name: 'textToImage',
	description: 'Generate an image from a text prompt.',
	examples: [
		{
			prompt: 'Generate an image of a cat wearing a top hat',
			command: "textToImage('cat wearing a top hat')"
		},
		{
			prompt: 'Draw a brown dog on a beach',
			command: "textToImage('drawing of a brown dog on a beach')"
		}
	],
	call: async (input) => {
		return await getInference().textToImage(
			{
				inputs: await input,
				model: 'stabilityai/stable-diffusion-2'
			},
			{ wait_for_model: true }
		);
	}
};