Camel.toolkits.dalle toolkit
DalleToolkit
A class representing a toolkit for image generation using OpenAI’s DALL-E model.
init
Initializes a new instance of the DalleToolkit class.
Parameters:
- timeout (Optional[float]): The timeout value for API requests in seconds. If None, no timeout is applied. (default: :obj:
None
)
base64_to_image
Converts a base64 encoded string into a PIL Image object.
Parameters:
- base64_string (str): The base64 encoded string of the image.
Returns:
Optional[Image.Image]: The PIL Image object or None if conversion fails.
image_path_to_base64
Converts the file path of an image to a Base64 encoded string.
Parameters:
- image_path (str): The path to the image file.
Returns:
str: A Base64 encoded string representing the content of the image file.
image_to_base64
Converts an image into a base64-encoded string.
This function takes an image object as input, encodes the image into a PNG format base64 string, and returns it. If the encoding process encounters an error, it prints the error message and returns None.
Parameters:
- image: The image object to be encoded, supports any image format that can be saved in PNG format.
Returns:
str: A base64-encoded string of the image.
get_dalle_img
Generate an image using OpenAI’s DALL-E model. The generated image is saved to the specified directory.
Parameters:
- prompt (str): The text prompt based on which the image is generated.
- image_dir (str): The directory to save the generated image. Defaults to ‘img’.
Returns:
str: The path to the saved image.
get_tools
Returns:
List[FunctionTool]: A list of FunctionTool objects representing the functions in the toolkit.