api

package
v0.0.0-...-2ee1e15 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	URLModelInfoByID        = "/v1/models/%s"
	URLModelVersionInfoByID = "/v1/model-versions/%s"
)
View Source
const (
	CivitaiAPIBaseV1 = "https://civitai.com/api/"
	UserAgent        = "civitai-go-client (https://github.com/zhaolion/civitai-cli)"
)
View Source
const (
	ModelTypeCheckpoint        = "Checkpoint"
	ModelTypeTextualInversion  = "TextualInversion"
	ModelTypeHypernetwork      = "Hypernetwork"
	ModelTypeAestheticGradient = "AestheticGradient"
	ModelTypeLORA              = "LORA"
	ModelTypeControlnet        = "Controlnet"
	ModelTypePoses             = "Poses"
)
View Source
const (
	TokenEnvKey   = "CIVITAI_API_KEY"
	ConfigDir     = "~/.civitai"
	TokenFilePath = "~/.civitai/token"
)

Variables

This section is empty.

Functions

func GetAPIToken

func GetAPIToken() string

func GetAPITokenMask

func GetAPITokenMask() string

func SetAPIToken

func SetAPIToken(token string)

Types

type CivitaiClient

type CivitaiClient struct {
	*req.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(token string, opts ...CivitaiClientOption) *CivitaiClient

NewClient with an API Key you can authenticate

func (*CivitaiClient) FileDownload

func (c *CivitaiClient) FileDownload(ctx context.Context, file *ModelInfoFiles, targetFile string, opts ...*FileDownloadOption) error

FileDownload download file from fileURL to targetFile.

func (*CivitaiClient) ModelInfoByID

func (c *CivitaiClient) ModelInfoByID(modelID string) (*ModelInfo, error)

ModelInfoByID fetch model info by id. GET /api/v1/models/:modelId API Doc: https://developer.civitai.com/docs/api/public-rest#get-apiv1modelsmodelid

func (*CivitaiClient) ModelVersionByID

func (c *CivitaiClient) ModelVersionByID(verID string) (*ModelVersion, error)

ModelVersionByID fetch model version files by ver-id. GET /api/v1/models/:modelId API Doc: https://developer.civitai.com/docs/api/public-rest#get-apiv1modelsmodelid

type CivitaiClientOption

type CivitaiClientOption func(cli *CivitaiClient)

func CivitaiClientOptionDebug

func CivitaiClientOptionDebug(enable bool) CivitaiClientOption

type ConsoleCell

type ConsoleCell struct {
	Key  string `json:"key,omitempty"`
	Text string `json:"text,omitempty"`
}

type ConsoleTable

type ConsoleTable struct {
	Cells [][]*ConsoleCell `json:"cells,omitempty"`
}

func NewConsoleTable

func NewConsoleTable() *ConsoleTable

type ErrorResponse

type ErrorResponse struct {
	StatusCode   int    `json:"-"`
	ErrorMessage string `json:"error"`
}

func NewNotFoundError

func NewNotFoundError(apiType, id string) *ErrorResponse

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type FileDownloadOption

type FileDownloadOption struct {
	DownloadTimeoutSec uint32
	Callback           req.DownloadCallback
}

type FormatModelInfoOption

type FormatModelInfoOption struct {
	Full bool
}

type FormatModelVersionOption

type FormatModelVersionOption struct {
	Full bool
}

type ModelCreator

type ModelCreator struct {
	Username string `json:"username,omitempty"`
	Image    string `json:"image,omitempty"`
}

type ModelHashes

type ModelHashes struct {
	AutoV1 string `json:"AutoV1,omitempty"`
	AutoV2 string `json:"AutoV2,omitempty"`
	Sha256 string `json:"SHA256,omitempty"`
	Crc32  string `json:"CRC32,omitempty"`
	Blake3 string `json:"BLAKE3,omitempty"`
}

type ModelInfo

type ModelInfo struct {
	ID                    int                 `json:"id,omitempty"`
	Name                  string              `json:"name,omitempty"`
	Description           string              `json:"description,omitempty"`
	AllowNoCredit         bool                `json:"allowNoCredit,omitempty"`
	AllowCommercialUse    []string            `json:"allowCommercialUse,omitempty"`
	AllowDerivatives      bool                `json:"allowDerivatives,omitempty"`
	AllowDifferentLicense bool                `json:"allowDifferentLicense,omitempty"`
	Type                  string              `json:"type,omitempty"`
	Minor                 bool                `json:"minor,omitempty"`
	Poi                   bool                `json:"poi,omitempty"`
	Nsfw                  bool                `json:"nsfw,omitempty"`
	NsfwLevel             int                 `json:"nsfwLevel,omitempty"`
	Cosmetic              interface{}         `json:"cosmetic,omitempty"`
	Stats                 ModelStats          `json:"stats,omitempty"`
	Creator               ModelCreator        `json:"creator,omitempty"`
	Tags                  []string            `json:"tags,omitempty"`
	ModelVersions         []ModelInfoVersions `json:"modelVersions,omitempty"`
}

func (*ModelInfo) JSON

func (m *ModelInfo) JSON() string

func (*ModelInfo) MatchVerByID

func (m *ModelInfo) MatchVerByID(verID string) *ModelInfoVersions

type ModelInfoFiles

type ModelInfoFiles struct {
	ID                int           `json:"id,omitempty"`
	SizeKB            float64       `json:"sizeKB,omitempty"`
	Name              string        `json:"name,omitempty"`
	Type              string        `json:"type,omitempty"`
	PickleScanResult  string        `json:"pickleScanResult,omitempty"`
	PickleScanMessage string        `json:"pickleScanMessage,omitempty"`
	VirusScanResult   string        `json:"virusScanResult,omitempty"`
	VirusScanMessage  interface{}   `json:"virusScanMessage,omitempty"`
	ScannedAt         time.Time     `json:"scannedAt,omitempty"`
	Metadata          ModelMetadata `json:"metadata,omitempty"`
	Hashes            ModelHashes   `json:"hashes,omitempty"`
	DownloadURL       string        `json:"downloadUrl,omitempty"`
	Primary           bool          `json:"primary,omitempty"`
}

type ModelInfoImages

type ModelInfoImages struct {
	URL       string `json:"url,omitempty"`
	NsfwLevel int    `json:"nsfwLevel,omitempty"`
	Width     int    `json:"width,omitempty"`
	Height    int    `json:"height,omitempty"`
	Hash      string `json:"hash,omitempty"`
	Type      string `json:"type,omitempty"`
}

type ModelInfoVersions

type ModelInfoVersions struct {
	ID            int               `json:"id,omitempty"`
	Index         int               `json:"index,omitempty"`
	Name          string            `json:"name,omitempty"`
	BaseModel     string            `json:"baseModel,omitempty"`
	BaseModelType string            `json:"baseModelType,omitempty"`
	CreatedAt     time.Time         `json:"createdAt,omitempty"`
	PublishedAt   time.Time         `json:"publishedAt,omitempty"`
	Status        string            `json:"status,omitempty"`
	Availability  string            `json:"availability,omitempty"`
	NsfwLevel     int               `json:"nsfwLevel,omitempty"`
	Description   string            `json:"description,omitempty"`
	TrainedWords  []string          `json:"trainedWords,omitempty"`
	Stats         ModelStats        `json:"stats,omitempty"`
	Files         []ModelInfoFiles  `json:"files,omitempty"`
	Images        []ModelInfoImages `json:"images,omitempty"`
	DownloadURL   string            `json:"downloadUrl,omitempty"`
}

type ModelMetadata

type ModelMetadata struct {
	Format string `json:"format,omitempty"`
	Size   string `json:"size,omitempty"`
	Fp     string `json:"fp,omitempty"`
}

type ModelStats

type ModelStats struct {
	DownloadCount   int     `json:"downloadCount,omitempty"` // version 公共字段 - begin
	RatingCount     int     `json:"ratingCount,omitempty"`
	Rating          float64 `json:"rating,omitempty"`
	ThumbsUpCount   int     `json:"thumbsUpCount,omitempty"`
	ThumbsDownCount int     `json:"thumbsDownCount,omitempty"` // version 公共字段 - end

	FavoriteCount     int `json:"favoriteCount,omitempty"`
	CommentCount      int `json:"commentCount,omitempty"`
	TippedAmountCount int `json:"tippedAmountCount,omitempty"`
}

type ModelVersion

type ModelVersion struct {
	ID                   int         `json:"id,omitempty"`
	ModelID              int         `json:"modelId,omitempty"`
	Name                 string      `json:"name,omitempty"`
	CreatedAt            time.Time   `json:"createdAt,omitempty"`
	UpdatedAt            time.Time   `json:"updatedAt,omitempty"`
	TrainedWords         []string    `json:"trainedWords,omitempty"`
	BaseModel            string      `json:"baseModel,omitempty"`
	EarlyAccessTimeFrame int         `json:"earlyAccessTimeFrame,omitempty"`
	Description          interface{} `json:"description,omitempty"`
	// Stats only contains:
	//  DownloadCount int
	//	RatingCount   int
	//	Rating        int
	Stats       ModelStats           `json:"stats,omitempty"`
	Model       ModelVersionModel    `json:"model,omitempty"`
	Files       []ModelVersionFiles  `json:"files,omitempty"`
	Images      []ModelVersionImages `json:"images,omitempty"`
	DownloadURL string               `json:"downloadUrl,omitempty"`
}

func (*ModelVersion) JSON

func (m *ModelVersion) JSON() string

type ModelVersionFiles

type ModelVersionFiles struct {
	ID                int           `json:"id,omitempty"`
	Name              string        `json:"name,omitempty"`
	SizeKB            float64       `json:"sizeKB,omitempty"`
	Type              string        `json:"type,omitempty"`
	Metadata          ModelMetadata `json:"metadata,omitempty"`
	PickleScanResult  string        `json:"pickleScanResult,omitempty"`
	PickleScanMessage string        `json:"pickleScanMessage,omitempty"`
	VirusScanResult   string        `json:"virusScanResult,omitempty"`
	ScannedAt         time.Time     `json:"scannedAt,omitempty"`
	Hashes            ModelHashes   `json:"hashes,omitempty"`
	Primary           bool          `json:"primary,omitempty"`
	DownloadURL       string        `json:"downloadUrl,omitempty"`
}

type ModelVersionImages

type ModelVersionImages struct {
	URL    string      `json:"url,omitempty"`
	Nsfw   bool        `json:"nsfw,omitempty"`
	Width  int         `json:"width,omitempty"`
	Height int         `json:"height,omitempty"`
	Hash   string      `json:"hash,omitempty"`
	Meta   interface{} `json:"meta,omitempty"`
}

type ModelVersionModel

type ModelVersionModel struct {
	Name string `json:"name,omitempty"`
	Type string `json:"type,omitempty"`
	Nsfw bool   `json:"nsfw,omitempty"`
	Poi  bool   `json:"poi,omitempty"`
}

type ModelVersionStats

type ModelVersionStats struct {
	DownloadCount int `json:"downloadCount,omitempty"`
	RatingCount   int `json:"ratingCount,omitempty"`
	Rating        int `json:"rating,omitempty"`
}

type Output

type Output interface {
	Format(ctx context.Context, table *ConsoleTable) ([]byte, error)
}

type Terminal

type Terminal struct {
	Output
}

func NewTerminal

func NewTerminal() *Terminal

func (*Terminal) PrintModelInfo

func (terminal *Terminal) PrintModelInfo(ctx context.Context, m *ModelInfo, _ *FormatModelInfoOption) error

PrintModelInfo print model info into terminal.

func (*Terminal) PrintModelVersionByID

func (terminal *Terminal) PrintModelVersionByID(ctx context.Context, m *ModelVersion, _ *FormatModelVersionOption) error

type TerminalTable

type TerminalTable struct {
	Style string
}

func NewTerminalTable

func NewTerminalTable() *TerminalTable

func (*TerminalTable) Format

func (out *TerminalTable) Format(_ context.Context, input *ConsoleTable) ([]byte, error)

Jump to

Keyboard shortcuts

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