1"use strict";(self.webpackChunkintellidocs=self.webpackChunkintellidocs||[]).push([[8986],{2861:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>a,default:()=>m,frontMatter:()=>r,metadata:()=>s,toc:()=>d});var o=t(4848),i=t(8453);const r={sidebar_position:3,title:"AI Image Generation in Python",sidebar_label:"Image generation",description:"Generate images from text prompts with Intelli for Python. Configure RemoteImageModel and ImageModelInput for OpenAI or Stability providers.",keywords:["python image generation","intelli image generation","remoteimagemodel python","openai image generation python","stability image generation","imagemodelinput"]},a="Image generation",s={id:"python/controllers/image-generation",title:"AI Image Generation in Python",description:"Generate images from text prompts with Intelli for Python. Configure RemoteImageModel and ImageModelInput for OpenAI or Stability providers.",source:"@site/docs/python/controllers/image-generation.md",sourceDirName:"python/controllers",slug:"/python/controllers/image-generation",permalink:"/docs/python/controllers/image-generation",draft:!1,unlisted:!1,editUrl:"https://github.com/intelligentnode/docs/edit/main/intellidocs/docs/python/controllers/image-generation.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3,title:"AI Image Generation in Python",sidebar_label:"Image generation",description:"Generate images from text prompts with Intelli for Python. Configure RemoteImageModel and ImageModelInput for OpenAI or Stability providers.",keywords:["python image generation","intelli image generation","remoteimagemodel python","openai image generation python","stability image generation","imagemodelinput"]},sidebar:"pythonSidebar",previous:{title:"Embedding",permalink:"/docs/python/controllers/embedding"},next:{title:"Speech",permalink:"/docs/python/controllers/speech"}},l={},d=[{value:"Supported Providers",id:"supported-providers",level:3},{value:"Parameters",id:"parameters",level:3},{value:"Example",id:"example",level:3},{value:"Openai Image Parameters",id:"openai-image-parameters",level:3}];function p(e){const n={code:"code",h1:"h1",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.h1,{id:"image-generation",children:"Image generation"}),"\n",(0,o.jsx)(n.p,{children:"The Image generation controller lets you create images based on text descriptions. This empowers developers to dynamically produce visuals for various applications."}),"\n",(0,o.jsx)(n.h3,{id:"supported-providers",children:"Supported Providers"}),"\n",(0,o.jsx)(n.p,{children:"The framework supports different image generation models, allowing you to choose based on your needs: openai, stability."}),"\n",(0,o.jsx)(n.h3,{id:"parameters",children:"Parameters"}),"\n",(0,o.jsx)(n.p,{children:"Specify these parameters to generate images:"}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:"api_key"}),": Your API key or authentication token for the chosen provider."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:"provider"}),": The name of the AI service provider (",(0,o.jsx)(n.code,{children:"openai"})," or ",(0,o.jsx)(n.code,{children:"stability"}),")."]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.strong,{children:"image_input"}),": This can be an instance of ",(0,o.jsx)(n.code,{children:"ImageModelInput"})," containing the details of the image you want to generate, such as the prompt, dimensions, and model-specific parameters."]}),"\n"]}),"\n",(0,o.jsx)(n.h3,{id:"example",children:"Example"}),"\n",(0,o.jsxs)(n.p,{children:["Create an instance of the ",(0,o.jsx)(n.code,{children:"RemoteImageModel"})," with your chosen provider and API key."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-python",children:'from intelli.controller.remote_image_model import RemoteImageModel\n\nimage_model = RemoteImageModel(api_key="your_api_key_here", provider="openai")\n'})}),"\n",(0,o.jsx)(n.p,{children:"Prepare your image input, specifying the prompt and any other necessary parameters."}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-python",children:'from intelli.model.input.image_input import ImageModelInput\n\n# define the prompt and image parameters\nprompt = "A futuristic city skyline at sunset, with flying cars."\nimage_input = ImageModelInput(\n prompt=prompt,\n width=1024,\n height=1024,\n model="gpt-image-2"\n)\n\n# Generate the image\nimages = image_model.generate_images(image_input)\n'})}),"\n",(0,o.jsx)(n.h3,{id:"openai-image-parameters",children:"Openai Image Parameters"}),"\n",(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.code,{children:"gpt-image-2"})," is the default openai model, and the gpt-image family returns base64 images. It accepts additional parameters:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-python",children:'image_input = ImageModelInput(\n prompt=prompt,\n model="gpt-image-2",\n quality="low", # low, medium, high, auto\n background="transparent",\n output_format="webp", # png, jpeg, webp\n output_compression=80, # jpeg and webp only\n moderation="auto",\n
1)\n'})}),"\n",(0,o.jsxs)(n.p,{children:["The older ",(0,o.jsx)(n.code,{children:"dall-e-3"})," model was retired by openai. If your code still passes the parameters of that era, intelli maps them for you, so ",(0,o.jsx)(n.code,{children:'quality="standard"'})," becomes ",(0,o.jsx)(n.code,{children:"medium"}),", ",(0,o.jsx)(n.code,{children:'quality="hd"'})," becomes ",(0,o.jsx)(n.code,{children:"high"}),", and ",(0,o.jsx)(n.code,{children:"response_format"})," and ",(0,o.jsx)(n.code,{children:"style"})," are dropped."]})]})}function m(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(p,{...e})}):p(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>a,x:()=>s});var o=t(6540);const i={},r=o.createContext(i);function a(e){const n=o.useContext(r);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(r.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.