@teamflojo/floimg-openai
v0.2.0
Published
OpenAI image generation, vision, and text providers for floimg
Downloads
114
Readme
@teamflojo/floimg-openai
OpenAI integration for floimg, providing DALL-E image generation, GPT-4 Vision analysis, and image transforms.
Installation
npm install @teamflojo/floimg-openai
# or
pnpm add @teamflojo/floimg-openaiConfiguration
Set your OpenAI API key:
export OPENAI_API_KEY=your_key_hereOr pass it directly:
import openai from "@teamflojo/floimg-openai";
const generator = openai({ apiKey: "your_key_here" });Features
Image Generation (DALL-E)
Generate images using DALL-E 2 or DALL-E 3:
import { createClient } from "@teamflojo/floimg";
import openai from "@teamflojo/floimg-openai";
const floimg = createClient();
floimg.registerGenerator(openai());
const image = await floimg.generate({
generator: "openai",
params: {
prompt: "A serene mountain landscape at sunset",
model: "dall-e-3",
size: "1024x1024",
quality: "hd",
style: "vivid",
},
});Parameters:
| Parameter | Type | Default | Description | | --------- | ------------------------ | ----------- | ----------------------- | | prompt | string | (required) | Image description | | model | "dall-e-2" | "dall-e-3" | "dall-e-3" | Model to use | | size | string | "1024x1024" | Image dimensions | | quality | "standard" | "hd" | "standard" | Quality (DALL-E 3 only) | | style | "vivid" | "natural" | "vivid" | Style (DALL-E 3 only) |
Image Transforms
Transform existing images using DALL-E 2:
import { openaiTransform } from "@teamflojo/floimg-openai";
floimg.registerTransformProvider(openaiTransform());
// Edit/inpaint an image
const edited = await floimg.transform({
blob: inputImage,
op: "edit",
provider: "openai-transform",
params: {
prompt: "Add a sunset in the background",
size: "1024x1024",
},
});
// Generate variations
const variation = await floimg.transform({
blob: inputImage,
op: "variations",
provider: "openai-transform",
params: {
size: "1024x1024",
},
});Available Transforms:
| Operation | Description | | ---------- | ---------------------------------------- | | edit | Edit/inpaint an image with optional mask | | variations | Generate variations of an image |
Vision Analysis (GPT-4V)
Analyze images using GPT-4 Vision:
import { openaiVision } from "@teamflojo/floimg-openai";
floimg.registerVisionProvider(openaiVision());
const analysis = await floimg.analyze({
blob: inputImage,
provider: "openai-vision",
params: {
prompt: "Describe this image in detail",
outputFormat: "json",
},
});Text Generation (GPT-4)
Generate text for image workflows:
import { openaiText } from "@teamflojo/floimg-openai";
floimg.registerTextProvider(openaiText());
const result = await floimg.text({
provider: "openai-text",
params: {
prompt: "Write a caption for this sunset photo",
context: analysis.content, // From vision analysis
},
});License
MIT
