query

Function

Generates an image from given text prompts.

Prototype

def query(text, llm_config, *args, **kwargs)

Parameters

Parameter

Data Type

Required/Optional

Description

text

String

Required

Prompt for generating an image. The value cannot be empty and can contain a maximum of 1024 × 1024 characters.

llm_config

LLMParameterConfig

Optional

Parameters for calling an LLM. For details, see LLMParameterConfig.

args

List

Optional

(Not used) Inherited from the base class.

kwargs["output_format"]

String

Optional

Output image format, which can be obtained by using kwargs["output_format"].

The value can be png, jpeg, jpg, or webp. The default value is png.

kwargs["size"]

String

Optional

Image size, in the format of "height × width", which is specified by kwargs. The supported size depends on the corresponding LLM. The regular expression matching format is ^\d{1,5}\*\d{1,5}$. The default value is 512 × 512.

Return Value

Data Type

Description

Dict,

{"prompt": prompt, "result": data}

data is the Base64-encoded image data.

Example

from mx_rag.chain import Text2ImgChain
from mx_rag.llm import Text2ImgMultiModel
from mx_rag.utils import ClientParam
client_param = ClientParam(ca_file="/path/to/ca.crt")
multi_model=Text2ImgMultiModel(model_name="sd", url="text to img url", client_param=client_param)
text2img_chain = Text2ImgChain(multi_model=multi_model)
llm_data = text2img_chain.query("dog wearing black glasses", output_format="jpg")
print(llm_data)