generate-image
Create images from text prompts using HuggingFace Inference API with FLUX.1-schnell model via Together. Specify prompt and inference steps to generate visual content.
Instructions
HuggingFace Inference API를 사용해 텍스트 프롬프트로 이미지를 생성합니다. (FLUX.1-schnell via Together)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | 이미지 생성 프롬프트 | |
| num_inference_steps | No | 추론 스텝 수 (기본값: 4, 최대: 10) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes |
Implementation Reference
- src/index.ts:409-479 (handler)The handler function for 'generate-image', which uses the HuggingFace InferenceClient to generate an image from a text prompt.
async ({ prompt, num_inference_steps }) => { const token = process.env.HF_TOKEN if (!token) { return { content: [ { type: 'text' as const, text: 'HF_TOKEN 환경변수가 설정되지 않았습니다. Hugging Face 토큰을 설정해주세요.' } ], isError: true, structuredContent: { content: [ { type: 'text' as const, text: 'HF_TOKEN 환경변수가 설정되지 않았습니다. Hugging Face 토큰을 설정해주세요.' } ] } } } try { const client = new InferenceClient(token) const blob = (await client.textToImage({ provider: HF_PROVIDER as 'together', model: HF_MODEL, inputs: prompt, parameters: { num_inference_steps } })) as Blob | string const base64 = await blobToBase64(blob) return { content: [ { type: 'image' as const, data: base64, mimeType: 'image/png' } ], structuredContent: { content: [ { type: 'image' as const, data: base64, mimeType: 'image/png' } ] } } } catch (err) { const message = err instanceof Error ? err.message : String(err) return { content: [ { type: 'text' as const, text: `이미지 생성에 실패했습니다: ${message}` } ], isError: true, structuredContent: { content: [ { type: 'text' as const, text: `이미지 생성에 실패했습니다: ${message}` } ] } } } } - src/index.ts:379-408 (schema)Input and output schema definition for the 'generate-image' tool using Zod.
{ description: 'HuggingFace Inference API를 사용해 텍스트 프롬프트로 이미지를 생성합니다. (FLUX.1-schnell via Together)', inputSchema: z.object({ prompt: z.string().describe('이미지 생성 프롬프트'), num_inference_steps: z .number() .int() .min(1) .max(10) .optional() .default(4) .describe('추론 스텝 수 (기본값: 4, 최대: 10)') }), outputSchema: z.object({ content: z.array( z.union([ z.object({ type: z.literal('image'), data: z.string(), mimeType: z.string() }), z.object({ type: z.literal('text'), text: z.string() }) ]) ) }) }, - src/index.ts:377-480 (registration)Tool registration for 'generate-image' using server.registerTool.
server.registerTool( 'generate-image', { description: 'HuggingFace Inference API를 사용해 텍스트 프롬프트로 이미지를 생성합니다. (FLUX.1-schnell via Together)', inputSchema: z.object({ prompt: z.string().describe('이미지 생성 프롬프트'), num_inference_steps: z .number() .int() .min(1) .max(10) .optional() .default(4) .describe('추론 스텝 수 (기본값: 4, 최대: 10)') }), outputSchema: z.object({ content: z.array( z.union([ z.object({ type: z.literal('image'), data: z.string(), mimeType: z.string() }), z.object({ type: z.literal('text'), text: z.string() }) ]) ) }) }, async ({ prompt, num_inference_steps }) => { const token = process.env.HF_TOKEN if (!token) { return { content: [ { type: 'text' as const, text: 'HF_TOKEN 환경변수가 설정되지 않았습니다. Hugging Face 토큰을 설정해주세요.' } ], isError: true, structuredContent: { content: [ { type: 'text' as const, text: 'HF_TOKEN 환경변수가 설정되지 않았습니다. Hugging Face 토큰을 설정해주세요.' } ] } } } try { const client = new InferenceClient(token) const blob = (await client.textToImage({ provider: HF_PROVIDER as 'together', model: HF_MODEL, inputs: prompt, parameters: { num_inference_steps } })) as Blob | string const base64 = await blobToBase64(blob) return { content: [ { type: 'image' as const, data: base64, mimeType: 'image/png' } ], structuredContent: { content: [ { type: 'image' as const, data: base64, mimeType: 'image/png' } ] } } } catch (err) { const message = err instanceof Error ? err.message : String(err) return { content: [ { type: 'text' as const, text: `이미지 생성에 실패했습니다: ${message}` } ], isError: true, structuredContent: { content: [ { type: 'text' as const, text: `이미지 생성에 실패했습니다: ${message}` } ] } } } } )