leonardo

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 11 Imported by: 0

README

Leonardo AI for Go

Go Reference

This is an unofficial implementation of the Leonardo AI API client for Go.

This is not sufficiently tested, may not work as expected, and it is not in a stable API state.

Installation

To install the package, run:

go get github.com/emmaly/leonardo

Usage

Review the example/example.go file for a usage example.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Overview

services/datasets.go

services/prompt.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ptr

func Ptr[T any](v T) *T

Helper function to create pointers

func UploadImageToS3

func UploadImageToS3(s3URL string, fields map[string]string, imagePath string) error

UploadImageToS3 uploads the image data to S3 using the presigned URL. This is a helper function and not directly interacting with Leonardo.ai API.

Types

type APIErrorResponse

type APIErrorResponse struct {
	Code    string `json:"code"`
	Message string `json:"error"`
	Path    string `json:"path"`
}

APIErrorResponse represents a detailed error response from the API.

type CalculateAPICostRequest

type CalculateAPICostRequest struct {
	Service       string                 `json:"service"`
	ServiceParams map[string]interface{} `json:"serviceParams,omitempty"`
}

CalculateAPICostRequest represents the payload for calculating API cost.

type CalculateAPICostResponse

type CalculateAPICostResponse struct {
	CalculateProductionApiServiceCost struct {
		Cost *int `json:"cost"`
	} `json:"calculateProductionApiServiceCost"`
}

CalculateAPICostResponse represents the response from calculating API cost.

type CanvasRequestType

type CanvasRequestType string
const (
	CanvasRequestTypeInpaint    CanvasRequestType = "INPAINT"
	CanvasRequestTypeOutpaint   CanvasRequestType = "OUTPAINT"
	CanvasRequestTypeSketch2Img CanvasRequestType = "SKETCH2IMG"
	CanvasRequestTypeImg2Img    CanvasRequestType = "IMG2IMG"
)

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
	APIKey     string

	// Services
	Datasets          *DatasetsService
	Images            *ImagesService
	Elements          *ElementsService
	Prompt            *PromptService
	InitImages        *InitImagesService
	Models            *ModelsService
	PricingCalculator *PricingCalculatorService
	RealtimeCanvas    *RealtimeCanvasService
	Texture           *TextureService
	ThreeDModelAssets *ThreeDModelAssetsService
	User              *UserService
	Variation         *VariationService
	Motion            *MotionService
}

Client is the Leonardo.ai API client.

func NewClient

func NewClient(apiKey string) *Client

NewClient creates a new Leonardo.ai API client.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) error

Do sends an HTTP request and decodes the response into v. It also handles API-specific error responses.

func (*Client) NewDatasetsService

func (c *Client) NewDatasetsService() *DatasetsService

NewDatasetsService creates a new DatasetsService.

func (*Client) NewElementsService

func (c *Client) NewElementsService() *ElementsService

NewElementsService creates a new ElementsService.

func (*Client) NewImagesService

func (c *Client) NewImagesService() *ImagesService

NewImagesService creates a new ImagesService.

func (*Client) NewInitImagesService

func (c *Client) NewInitImagesService() *InitImagesService

NewInitImagesService creates a new InitImagesService.

func (*Client) NewModelsService

func (c *Client) NewModelsService() *ModelsService

NewModelsService creates a new ModelsService.

func (*Client) NewMotionService

func (c *Client) NewMotionService() *MotionService

NewMotionService creates a new MotionService.

func (*Client) NewPricingCalculatorService

func (c *Client) NewPricingCalculatorService() *PricingCalculatorService

NewPricingCalculatorService creates a new PricingCalculatorService.

func (*Client) NewPromptService

func (c *Client) NewPromptService() *PromptService

NewPromptService creates a new PromptService.

func (*Client) NewRealtimeCanvasService

func (c *Client) NewRealtimeCanvasService() *RealtimeCanvasService

NewRealtimeCanvasService creates a new RealtimeCanvasService.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, path string, body interface{}) (*http.Request, error)

NewRequest creates an HTTP request with the given method, path, and body.

func (*Client) NewTextureService

func (c *Client) NewTextureService() *TextureService

NewTextureService creates a new TextureService.

func (*Client) NewThreeDModelAssetsService

func (c *Client) NewThreeDModelAssetsService() *ThreeDModelAssetsService

NewThreeDModelAssetsService creates a new ThreeDModelAssetsService.

func (*Client) NewUserService

func (c *Client) NewUserService() *UserService

NewUserService creates a new UserService.

func (*Client) NewVariationService

func (c *Client) NewVariationService() *VariationService

NewVariationService creates a new VariationService.

type CreateDatasetRequest

type CreateDatasetRequest struct {
	Name        string  `json:"name"`
	Description *string `json:"description,omitempty"`
}

CreateDatasetRequest represents the payload for creating a new dataset.

type CreateDatasetResponse

type CreateDatasetResponse struct {
	InsertDatasetsOne struct {
		ID *string `json:"id"`
	} `json:"insert_datasets_one"`
}

CreateDatasetResponse represents the response after creating a dataset.

type CreateGenerationRequest

type CreateGenerationRequest struct {
	Alchemy               *bool              `json:"alchemy,omitempty"`       // default true
	ContrastRatio         *float64           `json:"contrastRatio,omitempty"` // 0.1-1.0 inclusive
	ExpandedDomain        *bool              `json:"expandedDomain,omitempty"`
	FantasyAvatar         *bool              `json:"fantasyAvatar,omitempty"`
	GuidanceScale         *int               `json:"guidance_scale,omitempty"` // 1-20, recommended 7
	Height                *int               `json:"height,omitempty"`         // default 768
	HighContrast          *bool              `json:"highContrast,omitempty"`
	HighResolution        *bool              `json:"highResolution,omitempty"`
	ImagePrompts          []string           `json:"imagePrompts,omitempty"`
	ImagePromptWeight     *float64           `json:"imagePromptWeight,omitempty"`
	InitGenerationImageID *string            `json:"init_generation_image_id,omitempty"`
	InitImageID           *string            `json:"init_image_id,omitempty"`
	InitStrength          *float64           `json:"init_strength,omitempty"`
	ModelID               *string            `json:"modelId,omitempty"` // default b24e16ff-06e3-43eb-8d33-4416c2d75876
	NegativePrompt        *string            `json:"negative_prompt,omitempty"`
	NumImages             *int               `json:"num_images,omitempty"`          // default 4
	NumInferenceSteps     *int               `json:"num_inference_steps,omitempty"` // 10-60, default 15
	PhotoReal             *bool              `json:"photoReal,omitempty"`           // requires Alchemy=true, ModelID=nil
	PhotoRealVersion      *string            `json:"photoRealVersion,omitempty"`    // v1 or v2
	PhotoRealStrength     *float64           `json:"photoRealStrength,omitempty"`   // 0.55 for low, 0.5 for medium, 0.45 for high; default 0.55
	PresetStyle           *PresetStyle       `json:"presetStyle,omitempty"`         // default DYNAMIC
	Prompt                string             `json:"prompt"`                        // required
	PromptMagic           *bool              `json:"promptMagic,omitempty"`
	PromptMagicStrength   *float64           `json:"promptMagicStrength,omitempty"` // 0.1-1.0 inclusive
	PromptMagicVersion    *string            `json:"promptMagicVersion,omitempty"`  // v2 or v3
	Public                *bool              `json:"public,omitempty"`
	Scheduler             *Scheduler         `json:"scheduler,omitempty"`  // default EULER_DISCRETE
	SDVersion             *SDVersion         `json:"sd_version,omitempty"` // default v1_5
	Seed                  *int               `json:"seed,omitempty"`
	Tiling                *bool              `json:"tiling,omitempty"`
	Transparency          *string            `json:"transparency,omitempty"` // disabled, foreground_only; default disabled
	Ultra                 *bool              `json:"ultra,omitempty"`        // requires Alchemy=false
	Unzoom                *bool              `json:"unzoom,omitempty"`       // requires UnzoomAmount and InitImageID
	UnzoomAmount          *int               `json:"unzoomAmount,omitempty"`
	UpscaleRatio          *int               `json:"upscaleRatio,omitempty"` // NOTE: ENTERPRISE ACCOUNTS ONLY
	Width                 *int               `json:"width,omitempty"`        // 32-1024; default 1024
	CanvasRequest         *bool              `json:"canvasRequest,omitempty"`
	CanvasRequestType     *CanvasRequestType `json:"canvasRequestType,omitempty"` // INPAINT, OUTPAINT, SKETCH2IMG, IMG2IMG
	CanvasInitID          *string            `json:"canvasInitId,omitempty"`
	CanvasMaskID          *string            `json:"canvasMaskId,omitempty"`
}

Image Generation-related types

type CreateGenerationResponse

type CreateGenerationResponse struct {
	SDGenerationJob struct {
		APICreditCost *int    `json:"apiCreditCost"`
		GenerationID  *string `json:"generationId"`
	} `json:"sdGenerationJob"`
}

type CreateLCMGenerationRequest

type CreateLCMGenerationRequest struct {
	Guidance         *float64 `json:"guidance,omitempty"`
	Height           *int     `json:"height,omitempty"`
	ImageDataURL     string   `json:"imageDataUrl"`
	Prompt           string   `json:"prompt"`
	RefineCreative   *bool    `json:"refineCreative,omitempty"`
	RefineStrength   *float64 `json:"refineStrength,omitempty"`
	RequestTimestamp *string  `json:"requestTimestamp,omitempty"`
	Seed             *int     `json:"seed,omitempty"`
	Steps            *int     `json:"steps,omitempty"`
	Strength         *float64 `json:"strength,omitempty"`
	Style            *string  `json:"style,omitempty"`
	Width            *int     `json:"width,omitempty"`
}

CreateLCMGenerationRequest represents the payload for creating a LCM generation.

type CreateLCMGenerationResponse

type CreateLCMGenerationResponse struct {
	LCMGenerationJob *LCMGenerationJob `json:"lcmGenerationJob"`
}

CreateLCMGenerationResponse represents the response after creating a LCM generation.

type CreateNoBackgroundVariationResponse

type CreateNoBackgroundVariationResponse struct {
	SdNobgJob VariationJob `json:"sdNobgJob"`
}

CreateNoBackgroundVariationResponse represents the response from creating a no background variation.

type CreateSVDMotionGenerationErrorResponse

type CreateSVDMotionGenerationErrorResponse struct {
	Code  int    `json:"code"`
	Error string `json:"error"`
}

CreateSVDMotionGenerationErrorResponse represents the error response from creating an SVD motion generation.

type CreateSVDMotionGenerationResponse

type CreateSVDMotionGenerationResponse struct {
	Details      map[string]interface{} `json:"details"`
	GenerationID string                 `json:"generationId"`
	Status       string                 `json:"status"`
}

Motion-related types CreateSVDMotionGenerationResponse represents the response from creating an SVD motion generation.

type CreateTextureGenerationRequest

type CreateTextureGenerationRequest struct {
	FrontRotationOffset *int    `json:"front_rotation_offset,omitempty"`
	ModelAssetID        *string `json:"modelAssetId,omitempty"`
	NegativePrompt      *string `json:"negative_prompt,omitempty"`
	Preview             *bool   `json:"preview,omitempty"`
	PreviewDirection    *string `json:"preview_direction,omitempty"`
	Prompt              *string `json:"prompt,omitempty"`
	SDVersion           *string `json:"sd_version,omitempty"`
	Seed                *int    `json:"seed,omitempty"`
}

CreateTextureGenerationRequest represents the payload for creating a texture generation.

type CreateTextureGenerationResponse

type CreateTextureGenerationResponse struct {
	TextureGenerationJob struct {
		APICreditCost *int    `json:"apiCreditCost"`
		ID            *string `json:"id"`
	} `json:"textureGenerationJob"`
}

CreateTextureGenerationResponse represents the response after creating a texture generation.

type CreateUnzoomVariationResponse

type CreateUnzoomVariationResponse struct {
	SdUnzoomJob VariationJob `json:"sdUnzoomJob"`
}

CreateUnzoomVariationResponse represents the response from creating an unzoom variation.

type DatasetsService

type DatasetsService struct {
	// contains filtered or unexported fields
}

DatasetsService provides methods to interact with the Dataset endpoints of the Leonardo.ai API.

func (*DatasetsService) CreateDataset

CreateDataset creates a new dataset. POST /datasets

func (*DatasetsService) DeleteDataset

func (s *DatasetsService) DeleteDataset(ctx context.Context, id string) (*DeleteDatasetResponse, error)

DeleteDataset deletes a dataset by its ID. DELETE /datasets/{id}

func (*DatasetsService) GetDataset

func (s *DatasetsService) GetDataset(ctx context.Context, id string) (*GetDatasetResponse, error)

GetDataset retrieves a dataset by its ID. GET /datasets/{id}

func (*DatasetsService) UploadDatasetImage

func (s *DatasetsService) UploadDatasetImage(ctx context.Context, datasetID string, req UploadDatasetImageRequest) (*UploadDatasetImageResponse, error)

UploadDatasetImage retrieves presigned S3 upload details to upload a dataset image. POST /datasets/{datasetId}/upload

func (*DatasetsService) UploadGeneratedImageToDataset

func (s *DatasetsService) UploadGeneratedImageToDataset(ctx context.Context, datasetID string, req UploadGeneratedImageRequest) (*UploadGeneratedImageResponse, error)

UploadGeneratedImageToDataset uploads a previously generated image to a dataset. POST /datasets/{datasetId}/upload/gen

type Delete3DModelResponse

type Delete3DModelResponse struct {
	DeleteModelAssetsByPK struct {
		ID *string `json:"id"`
	} `json:"delete_model_assets_by_pk"`
}

Delete3DModelResponse represents the response when deleting a 3D model.

type DeleteCustomModelResponse

type DeleteCustomModelResponse struct {
	DeleteCustomModelsByPK struct {
		ID *string `json:"id"`
	} `json:"delete_custom_models_by_pk"`
}

DeleteCustomModelResponse represents the response when deleting a custom model.

type DeleteDatasetResponse

type DeleteDatasetResponse struct {
	DeleteDatasetsByPK struct {
		ID *string `json:"id"`
	} `json:"delete_datasets_by_pk"`
}

DeleteDatasetResponse represents the response after deleting a dataset.

type DeleteGenerationResponse

type DeleteGenerationResponse struct {
	DeleteGenerationsByPK struct {
		ID *string `json:"id"`
	} `json:"delete_generations_by_pk"`
}

type DeleteInitImageResponse

type DeleteInitImageResponse struct {
	DeleteInitImagesByPk struct {
		ID *string `json:"id"`
	} `json:"delete_init_images_by_pk"`
}

DeleteInitImageResponse represents the response from deleting an init image.

type ElementsService

type ElementsService struct {
	// contains filtered or unexported fields
}

ElementsService provides methods to interact with the Elements endpoints.

func (*ElementsService) ListElements

func (s *ElementsService) ListElements(ctx context.Context) (*ListElementsResponse, error)

ListElements retrieves a list of public Elements available for use with generations. GET /elements

type GenerateRandomPromptResponse

type GenerateRandomPromptResponse struct {
	PromptGeneration *struct {
		APICreditCost *int    `json:"apiCreditCost"`
		Prompt        *string `json:"prompt"`
	} `json:"promptGeneration"`
}

GenerateRandomPromptResponse represents the response from generating a random prompt.

type Generation

type Generation struct {
	ID     *string `json:"id"`
	Status *string `json:"status"`
	// Add other relevant fields as necessary
	CreatedAt *Time `json:"createdAt,omitempty"`
}

type GenerationStatus

type GenerationStatus string
const (
	GenerationStatusComplete GenerationStatus = "COMPLETE"
	GenerationStatusFailed   GenerationStatus = "FAILED"
	GenerationStatusPending  GenerationStatus = "PENDING"
)

type Get3DModelByIDResponse

type Get3DModelByIDResponse struct {
	ModelAssetsByPK struct {
		CreatedAt   *Time   `json:"createdAt"`
		Description *string `json:"description"`
		ID          *string `json:"id"`
		MeshURL     *string `json:"meshUrl"`
		Name        *string `json:"name"`
		UpdatedAt   *Time   `json:"updatedAt"`
		UserID      *string `json:"userId"`
	} `json:"model_assets_by_pk"`
}

Get3DModelByIDResponse represents the response when retrieving a 3D model by ID.

type Get3DModelsByUserResponse

type Get3DModelsByUserResponse struct {
	ModelAssets []struct {
		CreatedAt *Time   `json:"createdAt"`
		ID        *string `json:"id"`
		MeshURL   *string `json:"meshUrl"`
		Name      *string `json:"name"`
		UpdatedAt *Time   `json:"updatedAt"`
		UserID    *string `json:"userId"`
	} `json:"model_assets"`
}

Get3DModelsByUserResponse represents the response when retrieving 3D models by user ID.

type GetCustomModelResponse

type GetCustomModelResponse struct {
	CustomModelsByPK struct {
		CreatedAt      *Time   `json:"createdAt"`
		Description    *string `json:"description"`
		ID             *string `json:"id"`
		InstancePrompt *string `json:"instancePrompt"`
		ModelHeight    *int    `json:"modelHeight"`
		ModelWidth     *int    `json:"modelWidth"`
		Name           *string `json:"name"`
		Public         *bool   `json:"public"`
		SDVersion      *string `json:"sdVersion"`
		Status         *string `json:"status"`
		Type           *string `json:"type"`
		UpdatedAt      *Time   `json:"updatedAt"`
	} `json:"custom_models_by_pk"`
}

GetCustomModelResponse represents the response when retrieving a custom model by ID.

type GetDatasetResponse

type GetDatasetResponse struct {
	DatasetsByPk struct {
		CreatedAt     *Time `json:"createdAt"`
		DatasetImages []struct {
			CreatedAt *Time   `json:"createdAt"`
			ID        *string `json:"id"`
			URL       *string `json:"url"`
		} `json:"dataset_images"`
		Description *string `json:"description"`
		ID          *string `json:"id"`
		Name        *string `json:"name"`
		UpdatedAt   *Time   `json:"updatedAt"`
	} `json:"datasets_by_pk"`
}

GetDatasetResponse represents the response when retrieving a dataset by ID.

type GetGenerationResponse

type GetGenerationResponse struct {
	GenerationsByPK struct {
		ID                  *string           `json:"id"`
		Status              *GenerationStatus `json:"status"`
		CreatedAt           *Time             `json:"createdAt"`
		Height              *int              `json:"imageHeight,omitempty"`
		ModelID             *string           `json:"modelId,omitempty"`
		NegativePrompt      *string           `json:"negativePrompt,omitempty"`
		NumInferenceSteps   *int              `json:"inferenceSteps,omitempty"`
		PhotoReal           *bool             `json:"photoReal,omitempty"`
		PhotoRealStrength   *float64          `json:"photoRealStrength,omitempty"`
		PresetStyle         *PresetStyle      `json:"presetStyle,omitempty"`
		Prompt              string            `json:"prompt"`
		PromptMagic         *bool             `json:"promptMagic,omitempty"`
		PromptMagicStrength *float64          `json:"promptMagicStrength,omitempty"`
		PromptMagicVersion  *string           `json:"promptMagicVersion,omitempty"`
		Public              *bool             `json:"public,omitempty"`
		Scheduler           *Scheduler        `json:"scheduler,omitempty"`
		SDVersion           *SDVersion        `json:"sdVersion,omitempty"`
		Seed                *int              `json:"seed,omitempty"`
		Ultra               *bool             `json:"ultra,omitempty"`
		Width               *int              `json:"imageWidth,omitempty"`
		GenerationElements  []struct {
			ID            *string `json:"id"`
			Lora          *Lora   `json:"lora"`
			WeightApplied *int    `json:"weightApplied"`
		} `json:"generation_elements"`
		GeneratedImages []struct {
			ID                              *string `json:"id"`
			GeneratedImageVariationGenerics []struct {
				ID            *string           `json:"id"`
				Status        *GenerationStatus `json:"status"`
				TransformType *TransformType    `json:"transformType"`
				URL           *string           `json:"url"`
			} `json:"generated_image_variation_generics"`
			FantasyAvatar  *bool   `json:"fantasyAvatar,omitempty"`
			ImageToVideo   *bool   `json:"imageToVideo,omitempty"`
			LikeCount      *int    `json:"likeCount,omitempty"`
			Motion         *bool   `json:"motion,omitempty"`
			MotionModel    *string `json:"motionModel,omitempty"`
			MotionMP4URL   *string `json:"motionMP4Url,omitempty"`
			MotionStrength *int    `json:"motionStrength,omitempty"`
			NSFW           *bool   `json:"nsfw,omitempty"`
			URL            *string `json:"url"`
		} `json:"generated_images"`
	} `json:"generations_by_pk"`
}

type GetGenerationsByUserResponse

type GetGenerationsByUserResponse struct {
	Generations []Generation `json:"generations"`
}

type GetSingleInitImageResponse

type GetSingleInitImageResponse struct {
	InitImagesByPk struct {
		CreatedAt *Time   `json:"createdAt"`
		ID        *string `json:"id"`
		URL       *string `json:"url"`
	} `json:"init_images_by_pk"`
}

GetSingleInitImageResponse represents the response from retrieving a single init image.

type GetUserInfoResponse

type GetUserInfoResponse struct {
	UserDetails []struct {
		APIPlanTokenRenewalDate *string `json:"apiPlanTokenRenewalDate"`
		APIConcurrencySlots     *int    `json:"apiConcurrencySlots"`
		APIPaidTokens           *int    `json:"apiPaidTokens"`
		APISubscriptionTokens   *int    `json:"apiSubscriptionTokens"`
		PaidTokens              *int    `json:"paidTokens"`
		SubscriptionGPTTokens   *int    `json:"subscriptionGptTokens"`
		SubscriptionModelTokens *int    `json:"subscriptionModelTokens"`
		SubscriptionTokens      *int    `json:"subscriptionTokens"`
		TokenRenewalDate        *string `json:"tokenRenewalDate"`
		User                    User    `json:"user"`
	} `json:"user_details"`
}

User-related types

type GetVariationResponse

type GetVariationResponse struct {
	GeneratedImageVariationGeneric []struct {
		CreatedAt     *Time   `json:"createdAt"`
		ID            *string `json:"id"`
		Status        *string `json:"status"`
		TransformType *string `json:"transformType"`
		URL           *string `json:"url"`
	} `json:"generated_image_variation_generic"`
}

GetVariationResponse represents the response when retrieving variation details.

type ImagesService

type ImagesService struct {
	// contains filtered or unexported fields
}

ImagesService provides methods to interact with the Image endpoints of the Leonardo.ai API.

func (*ImagesService) CreateImageGeneration

func (s *ImagesService) CreateImageGeneration(ctx context.Context, req CreateGenerationRequest) (*CreateGenerationResponse, error)

CreateImageGeneration generates images based on a prompt. POST /generations

func (*ImagesService) DeleteGeneration

func (s *ImagesService) DeleteGeneration(ctx context.Context, id string) (*DeleteGenerationResponse, error)

DeleteGeneration deletes a specific image generation by its ID. DELETE /generations/{id}

func (*ImagesService) GetGenerationsByUserID

func (s *ImagesService) GetGenerationsByUserID(ctx context.Context, userID string, limit, offset int) (*GetGenerationsByUserResponse, error)

GetGenerationsByUserID retrieves all generations associated with a specific user ID. GET /generations/user/{userId} Optional parameters: limit, offset for pagination.

func (*ImagesService) GetImageGeneration

func (s *ImagesService) GetImageGeneration(ctx context.Context, id string) (*GetGenerationResponse, error)

GetImageGeneration retrieves information about a specific image generation. GET /generations/{id}

type ImprovePromptRequest

type ImprovePromptRequest struct {
	Prompt *string `json:"prompt"`
}

ImprovePromptRequest represents the payload for improving a prompt.

type ImprovePromptResponse

type ImprovePromptResponse struct {
	PromptGeneration *struct {
		APICreditCost *int    `json:"apiCreditCost"`
		Prompt        *string `json:"prompt"`
	} `json:"promptGeneration"`
}

ImprovePromptResponse represents the response from improving a prompt.

type InitImagesService

type InitImagesService struct {
	// contains filtered or unexported fields
}

InitImagesService provides methods to interact with the Init Images endpoints.

func (*InitImagesService) DeleteInitImage

func (s *InitImagesService) DeleteInitImage(ctx context.Context, id string) (*DeleteInitImageResponse, error)

DeleteInitImage deletes an init image by its ID. DELETE /init-image/{id}

func (*InitImagesService) GetSingleInitImage

func (s *InitImagesService) GetSingleInitImage(ctx context.Context, id string) (*GetSingleInitImageResponse, error)

GetSingleInitImage retrieves a single init image by its ID. GET /init-image/{id}

func (*InitImagesService) UploadCanvasInitAndMaskImage

UploadCanvasInitAndMaskImage uploads canvas init and mask images and retrieves presigned S3 upload details. POST /canvas-init-image

func (*InitImagesService) UploadInitImage

func (s *InitImagesService) UploadInitImage(ctx context.Context, req UploadInitImageRequest) (*struct {
	UploadInitImageID *string `json:"uploadInitImageId"`
	Message           string  `json:"message"`
}, error)

UploadInitImage uploads an init image and retrieves presigned S3 upload details. POST /init-image

type LCMGenerationJob

type LCMGenerationJob struct {
	APICreditCost    *int     `json:"apiCreditCost"`
	ImageDataURL     []string `json:"imageDataUrl"`
	RequestTimestamp *string  `json:"requestTimestamp"`
}

LCMGenerationJob represents a LCM generation job.

type ListElementsResponse

type ListElementsResponse struct {
	Loras []Lora `json:"loras"`
}

ListModelsResponse represents the response when listing models.

type ListPlatformModelsResponse

type ListPlatformModelsResponse struct {
	CustomModels []struct {
		AKUUID        *string `json:"akUUID"`
		BaseModel     *string `json:"baseModel"`
		CreatorName   *string `json:"creatorName"`
		Description   *string `json:"description"`
		ID            *string `json:"id"`
		Name          *string `json:"name"`
		URLImage      *string `json:"urlImage"`
		WeightDefault *int    `json:"weightDefault"`
		WeightMax     *int    `json:"weightMax"`
		WeightMin     *int    `json:"weightMin"`
	} `json:"custom_models"`
}

ListPlatformModelsResponse represents the response when listing platform models.

type Lora

type Lora struct {
	AKUUID        *string `json:"akUUID"`
	BaseModel     *string `json:"baseModel"`
	CreatorName   *string `json:"creatorName"`
	Description   *string `json:"description"`
	Name          *string `json:"name"`
	URLImage      *string `json:"urlImage"`
	WeightDefault *int    `json:"weightDefault"`
	WeightMax     *int    `json:"weightMax"`
	WeightMin     *int    `json:"weightMin"`
}

type ModelsService

type ModelsService struct {
	// contains filtered or unexported fields
}

ModelsService provides methods to interact with the Models endpoints of the Leonardo.ai API.

func (*ModelsService) DeleteCustomModel

func (s *ModelsService) DeleteCustomModel(ctx context.Context, id string) (*DeleteCustomModelResponse, error)

DeleteCustomModel deletes a specific custom model by its ID. DELETE /models/{id}

func (*ModelsService) GetCustomModel

func (s *ModelsService) GetCustomModel(ctx context.Context, id string) (*GetCustomModelResponse, error)

GetCustomModel retrieves details of a specific custom model by its ID. GET /models/{id}

func (*ModelsService) ListPlatformModels

func (s *ModelsService) ListPlatformModels(ctx context.Context, req PaginationParams) (*ListPlatformModelsResponse, error)

ListPlatformModels retrieves platform models with pagination support. GET /platformModels

func (*ModelsService) TrainCustomModel

TrainCustomModel trains a new custom model using the specified dataset and parameters. POST /models

func (*ModelsService) UpdateCustomModel

UpdateCustomModel updates the details of a specific custom model. PUT /models/{id}

type MotionRequest

type MotionRequest struct {
}

MotionRequest represents the request payload for creating an SVD motion generation. Since the API specification shows empty bodyParameters, it's an empty struct.

type MotionService

type MotionService struct {
	// contains filtered or unexported fields
}

MotionService provides methods to interact with the Motion endpoints.

func (*MotionService) CreateSVDMotionGeneration

func (s *MotionService) CreateSVDMotionGeneration(ctx context.Context, req MotionRequest) (*CreateSVDMotionGenerationResponse, error)

CreateSVDMotionGeneration generates an SVD motion generation. POST /generations-motion-svd

type PaginationParams

type PaginationParams struct {
	Limit  int `json:"limit,omitempty"`
	Offset int `json:"offset,omitempty"`
}

PaginationParams defines parameters for paginated requests.

type PerformAlchemyUpscaleRequest

type PerformAlchemyUpscaleRequest struct {
	Guidance         *float64 `json:"guidance,omitempty"`
	Height           *int     `json:"height,omitempty"`
	ImageDataURL     string   `json:"imageDataUrl"`
	Prompt           string   `json:"prompt"`
	RequestTimestamp *string  `json:"requestTimestamp,omitempty"`
	Seed             *int     `json:"seed,omitempty"`
	Steps            *int     `json:"steps,omitempty"`
	Strength         *float64 `json:"strength,omitempty"`
	Style            *string  `json:"style,omitempty"`
	Width            *int     `json:"width,omitempty"`
}

PerformAlchemyUpscaleRequest represents the payload for performing Alchemy Upscale.

type PerformAlchemyUpscaleResponse

type PerformAlchemyUpscaleResponse struct {
	LCMGenerationJob *struct {
		APICreditCost    *int     `json:"apiCreditCost"`
		GeneratedImageID *string  `json:"generatedImageId"`
		GenerationID     []string `json:"generationId"`
		ImageDataURL     []string `json:"imageDataUrl"`
		RequestTimestamp *string  `json:"requestTimestamp"`
		VariationID      []string `json:"variationId"`
	} `json:"lcmGenerationJob"`
}

PerformAlchemyUpscaleResponse represents the response after performing Alchemy Upscale.

type PerformInpaintingRequest

type PerformInpaintingRequest struct {
	Guidance         *float64 `json:"guidance,omitempty"`
	Height           *int     `json:"height,omitempty"`
	ImageDataURL     string   `json:"imageDataUrl"`
	MaskDataURL      string   `json:"maskDataUrl"`
	Prompt           string   `json:"prompt"`
	RequestTimestamp *string  `json:"requestTimestamp,omitempty"`
	Seed             *int     `json:"seed,omitempty"`
	Steps            *int     `json:"steps,omitempty"`
	Strength         *float64 `json:"strength,omitempty"`
	Style            *string  `json:"style,omitempty"`
	Width            *int     `json:"width,omitempty"`
}

PerformInpaintingRequest represents the payload for performing inpainting.

type PerformInpaintingResponse

type PerformInpaintingResponse struct {
	LCMGenerationJob *LCMGenerationJob `json:"lcmGenerationJob"`
}

PerformInpaintingResponse represents the response after performing inpainting.

type PerformInstantRefineRequest

type PerformInstantRefineRequest struct {
	Guidance         *float64 `json:"guidance,omitempty"`
	Height           *int     `json:"height,omitempty"`
	ImageDataURL     string   `json:"imageDataUrl"`
	Prompt           string   `json:"prompt"`
	RefineCreative   *bool    `json:"refineCreative,omitempty"`
	RefineStrength   *float64 `json:"refineStrength,omitempty"`
	RequestTimestamp *string  `json:"requestTimestamp,omitempty"`
	Seed             *int     `json:"seed,omitempty"`
	Steps            *int     `json:"steps,omitempty"`
	Strength         *float64 `json:"strength,omitempty"`
	Style            *string  `json:"style,omitempty"`
	Width            *int     `json:"width,omitempty"`
}

PerformInstantRefineRequest represents the payload for performing instant refine.

type PerformInstantRefineResponse

type PerformInstantRefineResponse struct {
	LCMGenerationJob *LCMGenerationJob `json:"lcmGenerationJob"`
}

PerformInstantRefineResponse represents the response after performing instant refine.

type PresetStyle

type PresetStyle string
const (
	PresetStyleNone             PresetStyle = "NONE"
	PresetStyleLeonardo         PresetStyle = "LEONARDO"          // requires Alchemy=false
	PresetStyleAnime            PresetStyle = "ANIME"             // requires Alchemy=true
	PresetStyleCreative         PresetStyle = "CREATIVE"          // requires Alchemy=true
	PresetStyleDynamic          PresetStyle = "DYNAMIC"           // requires Alchemy=true
	PresetStyleEnvironment      PresetStyle = "ENVIRONMENT"       // requires Alchemy=true
	PresetStyleGeneral          PresetStyle = "GENERAL"           // requires Alchemy=true
	PresetStyleIllustration     PresetStyle = "ILLUSTRATION"      // requires Alchemy=true
	PresetStylePhotography      PresetStyle = "PHOTOGRAPHY"       // requires Alchemy=true
	PresetStyleRaytraced        PresetStyle = "RAYTRACED"         // requires Alchemy=true
	PresetStyleRender3D         PresetStyle = "RENDER_3D"         // requires Alchemy=true
	PresetStyleSketchBW         PresetStyle = "SKETCH_BW"         // requires Alchemy=true
	PresetStyleSketchColor      PresetStyle = "SKETCH_COLOR"      // requires Alchemy=true
	PresetStyleStockPhoto       PresetStyle = "STOCK_PHOTO"       // requires PhotoReal=true
	PresetStyleVibrant          PresetStyle = "VIBRANT"           // requires PhotoReal=true
	PresetStyleUnprocessed      PresetStyle = "UNPROCESSED"       // requires PhotoReal=true
	PresetStyleBokeh            PresetStyle = "BOKEH"             // requires PhotoReal=true
	PresetStyleCinematic        PresetStyle = "CINEMATIC"         // requires PhotoReal=true
	PresetStyleCinematicCloseup PresetStyle = "CINEMATIC_CLOSEUP" // requires PhotoReal=true
	PresetStyleFashion          PresetStyle = "FASHION"           // requires PhotoReal=true
	PresetStyleFilm             PresetStyle = "FILM"              // requires PhotoReal=true
	PresetStyleFood             PresetStyle = "FOOD"              // requires PhotoReal=true
	PresetStyleHDR              PresetStyle = "HDR"               // requires PhotoReal=true
	PresetStyleLongExposure     PresetStyle = "LONG_EXPOSURE"     // requires PhotoReal=true
	PresetStyleMacro            PresetStyle = "MACRO"             // requires PhotoReal=true
	PresetStyleMinimalistic     PresetStyle = "MINIMALISTIC"      // requires PhotoReal=true
	PresetStyleMonochrome       PresetStyle = "MONOCHROME"        // requires PhotoReal=true
	PresetStyleMoody            PresetStyle = "MOODY"             // requires PhotoReal=true
	PresetStyleNeutral          PresetStyle = "NEUTRAL"           // requires PhotoReal=true
	PresetStylePortrait         PresetStyle = "PORTRAIT"          // requires PhotoReal=true
	PresetStyleRetro            PresetStyle = "RETRO"             // requires PhotoReal=true
)

type PricingCalculatorService

type PricingCalculatorService struct {
	// contains filtered or unexported fields
}

PricingCalculatorService provides methods to interact with the Pricing Calculator endpoints.

func (*PricingCalculatorService) CalculateAPICost

CalculateAPICost calculates the API credit cost for a given service. POST /pricing-calculator

type PromptService

type PromptService struct {
	// contains filtered or unexported fields
}

PromptService provides methods to interact with the Prompt endpoints of the Leonardo.ai API.

func (*PromptService) GenerateRandomPrompt

func (s *PromptService) GenerateRandomPrompt(ctx context.Context) (*GenerateRandomPromptResponse, error)

GenerateRandomPrompt generates a random prompt. POST /prompt/random

func (*PromptService) ImprovePrompt

ImprovePrompt improves an existing prompt. POST /prompt/improve

type RealtimeCanvasService

type RealtimeCanvasService struct {
	// contains filtered or unexported fields
}

RealtimeCanvasService provides methods to interact with the Realtime Canvas endpoints.

func (*RealtimeCanvasService) CreateLCMGeneration

CreateLCMGeneration generates a LCM image. POST /generations-lcm

func (*RealtimeCanvasService) PerformAlchemyUpscale

PerformAlchemyUpscale performs Alchemy Upscale on a LCM image. POST /lcm-upscale

func (*RealtimeCanvasService) PerformInpainting

PerformInpainting performs inpainting on a LCM image. POST /lcm-inpainting

func (*RealtimeCanvasService) PerformInstantRefine

PerformInstantRefine performs instant refine on a LCM image. POST /lcm-instant-refine

type SDVersion

type SDVersion string
const (
	SDVersionV1_5           SDVersion = "v1_5"
	SDVersionV2             SDVersion = "v2"
	SDVersionV3             SDVersion = "v3"
	SDVersionSDXL_0_8       SDVersion = "SDXL_0_8"
	SDVersionSDXL_0_9       SDVersion = "SDXL_0_9"
	SDVersionSDXL_1_0       SDVersion = "SDXL_1_0"
	SDVersionSDXL_LIGHTNING SDVersion = "SDXL_LIGHTNING"
)

type Scheduler

type Scheduler string
const (
	SchedulerKLMS                   Scheduler = "KLMS"
	SchedulerEulerAncestralDiscrete Scheduler = "EULER_ANCESTRAL_DISCRETE"
	SchedulerEulerDiscrete          Scheduler = "EULER_DISCRETE"
	SchedulerDDIM                   Scheduler = "DDIM"
	SchedulerDPMSolver              Scheduler = "DPM_SOLVER"
	SchedulerPNDM                   Scheduler = "PNDM"
	SchedulerLeonardo               Scheduler = "LEONARDO"
)

type TextureService

type TextureService struct {
	// contains filtered or unexported fields
}

TextureService provides methods to interact with the Texture endpoints.

func (*TextureService) CreateTextureGeneration

CreateTextureGeneration generates a texture. POST /generations-texture

type ThreeDModelAssetsService

type ThreeDModelAssetsService struct {
	// contains filtered or unexported fields
}

ThreeDModelAssetsService provides methods to interact with the 3D Model Assets endpoints.

func (*ThreeDModelAssetsService) Delete3DModel

Delete3DModel deletes a specific 3D model by its ID. DELETE /models-3d/{id}

func (*ThreeDModelAssetsService) Get3DModelByID

Get3DModelByID retrieves a specific 3D model by its ID. GET /models-3d/{id}

func (*ThreeDModelAssetsService) Get3DModelsByUser

func (s *ThreeDModelAssetsService) Get3DModelsByUser(ctx context.Context, userID string, limit, offset int) (*Get3DModelsByUserResponse, error)

Get3DModelsByUser retrieves all 3D models associated with a specific user ID. GET /models-3d/user/{userId}?limit={limit}&offset={offset}

func (*ThreeDModelAssetsService) Upload3DModel

Upload3DModel uploads a 3D model and retrieves presigned S3 upload details. POST /models-3d/upload

type Time

type Time struct {
	Time time.Time
}

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (*Time) String

func (t *Time) String() string

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

type TrainCustomModelRequest

type TrainCustomModelRequest struct {
	DatasetID      string  `json:"datasetId"`
	Description    *string `json:"description,omitempty"`
	InstancePrompt string  `json:"instance_prompt"`
	ModelType      *string `json:"modelType,omitempty"`
	Name           string  `json:"name"`
	NSFW           *bool   `json:"nsfw,omitempty"`
	Resolution     *int    `json:"resolution,omitempty"`
	SDVersion      *string `json:"sd_Version,omitempty"`
	Strength       *string `json:"strength,omitempty"`
}

TrainCustomModelRequest represents the payload for training a new custom model.

type TrainCustomModelResponse

type TrainCustomModelResponse struct {
	SDTrainingJob struct {
		APICreditCost *int    `json:"apiCreditCost"`
		CustomModelID *string `json:"customModelId"`
	} `json:"sdTrainingJob"`
}

TrainCustomModelResponse represents the response from training a new custom model.

type TransformType

type TransformType string
const (
	TransformTypeOutpaint     TransformType = "OUTPAINT"
	TransformTypeInpaint      TransformType = "INPAINT"
	TransformTypeUpscale      TransformType = "UPSCALE"
	TransformTypeUnzoom       TransformType = "UNZOOM"
	TransformTypeNoBackground TransformType = "NOBG"
)

type UniversalUpscalerRequest

type UniversalUpscalerRequest struct {
	ImageURL    string `json:"image_url"`
	ScaleFactor int    `json:"scale_factor"`
}

UniversalUpscalerRequest represents the payload for universal upscaler.

type UniversalUpscalerResponse

type UniversalUpscalerResponse struct {
	UpscaledImageURL string `json:"upscaled_image_url"`
}

UniversalUpscalerResponse represents the response from the universal upscaler.

type UpdateCustomModelRequest

type UpdateCustomModelRequest struct {
	Description *string `json:"description,omitempty"`
	Name        *string `json:"name,omitempty"`
}

UpdateCustomModelRequest represents the payload for updating a custom model.

type UpdateCustomModelResponse

type UpdateCustomModelResponse struct {
	UpdatedCustomModelsByPk struct {
		ID          *string `json:"id"`
		Name        *string `json:"name"`
		Description *string `json:"description"`
	} `json:"updated_custom_models_by_pk"`
}

UpdateCustomModelResponse represents the response after updating a custom model.

type Upload3DModelRequest

type Upload3DModelRequest struct {
	ModelExtension *string `json:"modelExtension,omitempty"`
	Name           *string `json:"name,omitempty"`
}

Upload3DModelRequest represents the payload for uploading a 3D model.

type Upload3DModelResponse

type Upload3DModelResponse struct {
	UploadModelAsset *struct {
		ModelFields *string `json:"modelFields"`
		ModelID     *string `json:"modelId"`
		ModelKey    *string `json:"modelKey"`
		ModelURL    *string `json:"modelUrl"`
	} `json:"uploadModelAsset"`
}

Upload3DModelResponse represents the response after uploading a 3D model.

type UploadCanvasInitAndMaskImageRequest

type UploadCanvasInitAndMaskImageRequest struct {
	InitExtension string `json:"initExtension"`
	MaskExtension string `json:"maskExtension"`
}

UploadCanvasInitAndMaskImageRequest represents the payload for uploading canvas init and mask images.

type UploadCanvasInitAndMaskImageResponse

type UploadCanvasInitAndMaskImageResponse struct {
	UploadCanvasInitImage *struct {
		InitFields  string `json:"initFields"`
		InitImageID string `json:"initImageId"`
		InitKey     string `json:"initKey"`
		InitURL     string `json:"initUrl"`
		MaskFields  string `json:"maskFields"`
		MaskImageID string `json:"maskImageId"`
		MaskKey     string `json:"maskKey"`
		MaskURL     string `json:"maskUrl"`
	} `json:"uploadCanvasInitImage"`
}

UploadCanvasInitAndMaskImageResponse represents the response from uploading canvas init and mask images.

type UploadDatasetImageRequest

type UploadDatasetImageRequest struct {
	Extension string `json:"extension"`
}

UploadDatasetImageRequest represents the payload for uploading a dataset image to S3.

type UploadDatasetImageResponse

type UploadDatasetImageResponse struct {
	UploadDatasetImage *struct {
		Fields map[string]string `json:"fields"`
		ID     *string           `json:"id"`
		Key    *string           `json:"key"`
		URL    *string           `json:"url"`
	} `json:"uploadDatasetImage"`
}

UploadDatasetImageResponse represents the response containing presigned S3 upload details.

type UploadGeneratedImageRequest

type UploadGeneratedImageRequest struct {
	GeneratedImageID string `json:"generatedImageId"`
}

UploadGeneratedImageRequest represents the payload for uploading a generated image to a dataset.

type UploadGeneratedImageResponse

type UploadGeneratedImageResponse struct {
	UploadDatasetImageFromGen *struct {
		ID *string `json:"id"`
	} `json:"uploadDatasetImageFromGen"`
}

UploadGeneratedImageResponse represents the response after uploading a generated image to a dataset.

type UploadInitImageRequest

type UploadInitImageRequest struct {
	ImageFile string `json:"image_file"`
}

InitImages-related types UploadInitImageRequest represents the payload for uploading an init image.

type UpscaleVariationRequest

type UpscaleVariationRequest struct {
	ID          string `json:"id"`
	IsVariation *bool  `json:"isVariation,omitempty"`
}

UpscaleVariationRequest represents the payload for creating an upscale variation.

type UpscaleVariationResponse

type UpscaleVariationResponse struct {
	SdUpscaleJob struct {
		ID            *string `json:"id"`
		APICreditCost *int    `json:"apiCreditCost"`
	} `json:"sdUpscaleJob"`
}

UpscaleVariationResponse represents the response from creating an upscale variation.

type User

type User struct {
	// Define user fields as per API response
	ID       *string `json:"id"`
	Username *string `json:"username"`
}

User represents the user information.

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

UserService provides methods to interact with the User endpoints of the Leonardo.ai API.

func (*UserService) GetUserInfo

func (s *UserService) GetUserInfo(ctx context.Context) (*GetUserInfoResponse, error)

GetUserInfo retrieves information about the authenticated user. GET /me

type VariationJob

type VariationJob struct {
	ID            *string `json:"id"`
	APICreditCost *int    `json:"apiCreditCost"`
}

VariationJob represents variation job details.

type VariationRequest

type VariationRequest struct {
	ID          string `json:"id"`
	IsVariation *bool  `json:"isVariation,omitempty"`
}

VariationRequest represents a generic variation request.

type VariationService

type VariationService struct {
	// contains filtered or unexported fields
}

VariationService provides methods to interact with the Variation endpoints.

func (*VariationService) CreateNoBackgroundVariation

func (s *VariationService) CreateNoBackgroundVariation(ctx context.Context, req VariationRequest) (*CreateNoBackgroundVariationResponse, error)

CreateNoBackgroundVariation creates a no background variation for the provided image ID. POST /variations/nobg

func (*VariationService) CreateUniversalUpscalerVariation

func (s *VariationService) CreateUniversalUpscalerVariation(ctx context.Context, req UniversalUpscalerRequest) (*UniversalUpscalerResponse, error)

CreateUniversalUpscalerVariation creates a high-resolution image using Universal Upscaler. POST /variations/universal-upscaler

func (*VariationService) CreateUnzoomVariation

CreateUnzoomVariation creates an unzoom variation for the provided image ID. POST /variations/unzoom

func (*VariationService) CreateUpscaleVariation

func (s *VariationService) CreateUpscaleVariation(ctx context.Context, id string) (*UpscaleVariationResponse, error)

CreateUpscaleVariation creates an upscale variation for a given image ID. POST /variations/upscale

func (*VariationService) GetVariation

func (s *VariationService) GetVariation(ctx context.Context, id string) (*GetVariationResponse, error)

GetVariation retrieves variation details by ID. GET /variations/{id}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL