replicate

package
v0.0.0-...-d3d3e8a Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ModelList = []string{

	"black-forest-labs/flux-1.1-pro",
	"black-forest-labs/flux-1.1-pro-ultra",
	"black-forest-labs/flux-canny-dev",
	"black-forest-labs/flux-canny-pro",
	"black-forest-labs/flux-depth-dev",
	"black-forest-labs/flux-depth-pro",
	"black-forest-labs/flux-dev",
	"black-forest-labs/flux-dev-lora",
	"black-forest-labs/flux-fill-dev",
	"black-forest-labs/flux-fill-pro",
	"black-forest-labs/flux-pro",
	"black-forest-labs/flux-redux-dev",
	"black-forest-labs/flux-redux-schnell",
	"black-forest-labs/flux-schnell",
	"black-forest-labs/flux-schnell-lora",
	"ideogram-ai/ideogram-v2",
	"ideogram-ai/ideogram-v2-turbo",
	"recraft-ai/recraft-v3",
	"recraft-ai/recraft-v3-svg",
	"stability-ai/stable-diffusion-3",
	"stability-ai/stable-diffusion-3.5-large",
	"stability-ai/stable-diffusion-3.5-large-turbo",
	"stability-ai/stable-diffusion-3.5-medium",

	"ibm-granite/granite-20b-code-instruct-8k",
	"ibm-granite/granite-3.0-2b-instruct",
	"ibm-granite/granite-3.0-8b-instruct",
	"ibm-granite/granite-8b-code-instruct-128k",
	"meta/llama-2-13b",
	"meta/llama-2-13b-chat",
	"meta/llama-2-70b",
	"meta/llama-2-70b-chat",
	"meta/llama-2-7b",
	"meta/llama-2-7b-chat",
	"meta/meta-llama-3.1-405b-instruct",
	"meta/meta-llama-3-70b",
	"meta/meta-llama-3-70b-instruct",
	"meta/meta-llama-3-8b",
	"meta/meta-llama-3-8b-instruct",
	"mistralai/mistral-7b-instruct-v0.2",
	"mistralai/mistral-7b-v0.1",
	"mistralai/mixtral-8x7b-instruct-v0.1",
}

ModelList is a list of models that can be used with Replicate.

https://replicate.com/pricing

Functions

func ChatHandler

func ChatHandler(c *gin.Context, resp *http.Response) (
	srvErr *model.ErrorWithStatusCode, usage *model.Usage)

func ConvertImageToPNG

func ConvertImageToPNG(webpData []byte) ([]byte, error)

ConvertImageToPNG converts a WebP image to PNG format

func ImageHandler

func ImageHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, *model.Usage)

Types

type Adaptor

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

func (*Adaptor) ConvertImageRequest

func (*Adaptor) ConvertImageRequest(request *model.ImageRequest) (any, error)

ConvertImageRequest implements adaptor.Adaptor.

func (*Adaptor) ConvertRequest

func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.GeneralOpenAIRequest) (any, error)

func (*Adaptor) DoRequest

func (a *Adaptor) DoRequest(c *gin.Context, meta *meta.Meta, requestBody io.Reader) (*http.Response, error)

func (*Adaptor) DoResponse

func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, meta *meta.Meta) (usage *model.Usage, err *model.ErrorWithStatusCode)

func (*Adaptor) GetChannelName

func (a *Adaptor) GetChannelName() string

func (*Adaptor) GetModelList

func (a *Adaptor) GetModelList() []string

func (*Adaptor) GetRequestURL

func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error)

func (*Adaptor) Init

func (a *Adaptor) Init(meta *meta.Meta)

func (*Adaptor) SetupRequestHeader

func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *meta.Meta) error

type ChatInput

type ChatInput struct {
	TopK             int     `json:"top_k"`
	TopP             float64 `json:"top_p"`
	Prompt           string  `json:"prompt"`
	MaxTokens        int     `json:"max_tokens"`
	MinTokens        int     `json:"min_tokens"`
	Temperature      float64 `json:"temperature"`
	SystemPrompt     string  `json:"system_prompt"`
	StopSequences    string  `json:"stop_sequences"`
	PromptTemplate   string  `json:"prompt_template"`
	PresencePenalty  float64 `json:"presence_penalty"`
	FrequencyPenalty float64 `json:"frequency_penalty"`
}

ChatInput is input of ChatByReplicateRequest

https://replicate.com/meta/meta-llama-3.1-405b-instruct/api/schema

type ChatResponse

type ChatResponse struct {
	CompletedAt time.Time   `json:"completed_at"`
	CreatedAt   time.Time   `json:"created_at"`
	DataRemoved bool        `json:"data_removed"`
	Error       string      `json:"error"`
	ID          string      `json:"id"`
	Input       ChatInput   `json:"input"`
	Logs        string      `json:"logs"`
	Metrics     FluxMetrics `json:"metrics"`
	// Output could be `string` or `[]string`
	Output    []string        `json:"output"`
	StartedAt time.Time       `json:"started_at"`
	Status    string          `json:"status"`
	URLs      ChatResponseUrl `json:"urls"`
	Version   string          `json:"version"`
}

ChatResponse is response of ChatByReplicateRequest

https://replicate.com/meta/meta-llama-3.1-405b-instruct/examples?input=http&output=json

type ChatResponseUrl

type ChatResponseUrl struct {
	Stream string `json:"stream"`
	Get    string `json:"get"`
	Cancel string `json:"cancel"`
}

ChatResponseUrl is task urls of ChatResponse

type DrawImageRequest

type DrawImageRequest struct {
	Input ImageInput `json:"input"`
}

DrawImageRequest draw image by fluxpro

https://replicate.com/black-forest-labs/flux-pro?prediction=kg1krwsdf9rg80ch1sgsrgq7h8&output=json

type FluxInpaintingInput

type FluxInpaintingInput struct {
	Mask             string `json:"mask" binding:"required"`
	Image            string `json:"image" binding:"required"`
	Seed             int    `json:"seed"`
	Steps            int    `json:"steps" binding:"required,min=1"`
	Prompt           string `json:"prompt" binding:"required,min=5"`
	Guidance         int    `json:"guidance" binding:"required,min=2,max=5"`
	OutputFormat     string `json:"output_format"`
	SafetyTolerance  int    `json:"safety_tolerance" binding:"required,min=1,max=5"`
	PromptUnsampling bool   `json:"prompt_unsampling"`
}

FluxInpaintingInput is input of DrawImageByFluxProRequest

https://replicate.com/black-forest-labs/flux-fill-pro/api/schema

type FluxMetrics

type FluxMetrics struct {
	ImageCount  int     `json:"image_count"`
	PredictTime float64 `json:"predict_time"`
	TotalTime   float64 `json:"total_time"`
}

FluxMetrics is metrics of ImageResponse

type FluxURLs

type FluxURLs struct {
	Get    string `json:"get"`
	Cancel string `json:"cancel"`
}

FluxURLs is urls of ImageResponse

type ImageInput

type ImageInput struct {
	Steps           int    `json:"steps" binding:"required,min=1"`
	Prompt          string `json:"prompt" binding:"required,min=5"`
	ImagePrompt     string `json:"image_prompt"`
	Guidance        int    `json:"guidance" binding:"required,min=2,max=5"`
	Interval        int    `json:"interval" binding:"required,min=1,max=4"`
	AspectRatio     string `json:"aspect_ratio" binding:"required,oneof=1:1 16:9 2:3 3:2 4:5 5:4 9:16"`
	SafetyTolerance int    `json:"safety_tolerance" binding:"required,min=1,max=5"`
	Seed            int    `json:"seed"`
	NImages         int    `json:"n_images" binding:"required,min=1,max=8"`
	Width           int    `json:"width" binding:"required,min=256,max=1440"`
	Height          int    `json:"height" binding:"required,min=256,max=1440"`
}

ImageInput is input of DrawImageByFluxProRequest

https://replicate.com/black-forest-labs/flux-1.1-pro/api/schema

type ImageResponse

type ImageResponse struct {
	CompletedAt time.Time        `json:"completed_at"`
	CreatedAt   time.Time        `json:"created_at"`
	DataRemoved bool             `json:"data_removed"`
	Error       string           `json:"error"`
	ID          string           `json:"id"`
	Input       DrawImageRequest `json:"input"`
	Logs        string           `json:"logs"`
	Metrics     FluxMetrics      `json:"metrics"`
	// Output could be `string` or `[]string`
	Output    any       `json:"output"`
	StartedAt time.Time `json:"started_at"`
	Status    string    `json:"status"`
	URLs      FluxURLs  `json:"urls"`
	Version   string    `json:"version"`
}

ImageResponse is response of DrawImageByFluxProRequest

https://replicate.com/black-forest-labs/flux-pro?prediction=kg1krwsdf9rg80ch1sgsrgq7h8&output=json

func (*ImageResponse) GetOutput

func (r *ImageResponse) GetOutput() ([]string, error)

type InpaintingImageByFlusReplicateRequest

type InpaintingImageByFlusReplicateRequest struct {
	Input FluxInpaintingInput `json:"input"`
}

InpaintingImageByFlusReplicateRequest is request to inpainting image by flux pro

https://replicate.com/black-forest-labs/flux-fill-pro/api/schema

type ReplicateChatRequest

type ReplicateChatRequest struct {
	Input ChatInput `json:"input" form:"input" binding:"required"`
}

Jump to

Keyboard shortcuts

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