image

package
v0.0.0-...-4fe83b5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PromptError = errors.New("system judge that the prompt is not suitable for image generation, please try again with a different prompt")
)

Functions

func DetectError

func DetectError(supplier, model, body string) error

Types

type GenericParser

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

func NewGenericParser

func NewGenericParser(strategy ParseStrategy) *GenericParser

func (*GenericParser) Parse

func (g *GenericParser) Parse(resp *http.Response, response Response) error

type MarkdownImageStrategy

type MarkdownImageStrategy struct{}

func (*MarkdownImageStrategy) ExtractURLs

func (m *MarkdownImageStrategy) ExtractURLs(body []byte) ([]string, error)

func (*MarkdownImageStrategy) ValidateResponse

func (m *MarkdownImageStrategy) ValidateResponse(response Response) bool

type OpenAIImageStrategy

type OpenAIImageStrategy struct{}

func (*OpenAIImageStrategy) ExtractURLs

func (o *OpenAIImageStrategy) ExtractURLs(body []byte) ([]string, error)

func (*OpenAIImageStrategy) ValidateResponse

func (o *OpenAIImageStrategy) ValidateResponse(response Response) bool

type ParseStrategy

type ParseStrategy interface {
	ExtractURLs(body []byte) ([]string, error)
	ValidateResponse(response Response) bool
}

type Parser

type Parser interface {
	Parse(resp *http.Response, response Response) error
}

type RequestContent

type RequestContent interface {
	BodyContentType(supplier consts.ModelSupplier) (io.Reader, string, error)
	Path() string
	InitResponse(supplier string, duration time.Duration, tokenDesc string) Response
}

type Requester

type Requester struct {
	RequestTypes RequestContent
	Parser       Parser
	TaskID       int // 添加TaskID字段用于日志跟踪
	// contains filtered or unexported fields
}

func NewRequester

func NewRequester(token ai.Token, requestTypes RequestContent, parser Parser) *Requester

func (*Requester) Do

func (r *Requester) Do() (Response, error)

func (*Requester) SetTaskID

func (r *Requester) SetTaskID(taskID int) *Requester

type Response

type Response interface {
	GetModel() string
	GetSupplier() string
	GetTokenDesc() string
	GetStatusCode() int
	GetRespAt() time.Time
	FailedRespBody() string // != 200
	DurationMs() int64
	GetTaskID() int // 添加TaskID方法

	Succeed() bool
	GetURLs() []string
	GetError() error

	SetBasicResponse(statusCode int, respBody string, respAt time.Time)
	SetURLs(urls []string)
	SetError(err error)
	SetTaskID(taskID int) // 添加设置TaskID的方法
}

type StreamParser

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

func NewStreamParser

func NewStreamParser(strategy ParseStrategy) *StreamParser

func (*StreamParser) Parse

func (s *StreamParser) Parse(resp *http.Response, response Response) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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