prompt

package
v6.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

README

pkg/prompt

This package contains all prompt construction, enhancement, and OpenAI API logic for the project.

  • Prompt templates and generation
  • Attribute handling
  • OpenAI integration

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PromptTemplate    = template.Must(template.New("prompt").Parse(promptTemplateStr))
	DataTemplate      = template.Must(template.New("data").Parse(dataTemplateStr))
	TerseTemplate     = template.Must(template.New("terse").Parse(terseTemplateStr))
	TitleTemplate     = template.Must(template.New("title").Parse(titleTemplateStr))
	AuthorTemplate    = template.Must(template.New("author").Parse(authorTemplateStr))
	TechnicalTemplate = template.Must(template.New("technical").Parse(technicalTemplateStr))
)
View Source
var DatabaseNames = []string{
	"adverbs",
	"adjectives",
	"nouns",
	"emotions",
	"occupations",
	"actions",
	"artstyles",
	"artstyles",
	"litstyles",
	"colors",
	"colors",
	"colors",
	"viewpoints",
	"gazes",
	"backstyles",
	"compositions",
}

DatabaseNames lists the databases used to derive attributes from a seed.

Functions

func AttributeNames

func AttributeNames() []string

AttributeNames returns the list of attribute names (for test and compatibility).

func EnhanceLiteraryContent

func EnhanceLiteraryContent(basePrompt, authorContext string) (string, error)

EnhanceLiteraryContent performs Stage 1 enhancement focused on literary and creative content

func EnhancePrompt

func EnhancePrompt(prompt, authorType string) (string, error)

EnhancePrompt calls the OpenAI API to enhance a prompt using the given author type.

func IsOpenAIRetryableError

func IsOpenAIRetryableError(err error, statusCode int) bool

IsOpenAIRetryableError determines if an error from OpenAI should be retried

func IsRetryableHTTPStatus

func IsRetryableHTTPStatus(statusCode int) bool

IsRetryableHTTPStatus checks if an HTTP status code indicates a retryable error

Types

type AiConfiguration

type AiConfiguration struct {
	// Prompt Enhancement Configuration
	EnhancementModel       string        `json:"enhancement_model"`
	EnhancementSeed        int           `json:"enhancement_seed"`
	EnhancementTemperature float64       `json:"enhancement_temperature"`
	EnhancementURL         string        `json:"enhancement_url"`
	EnhancementTimeout     time.Duration `json:"enhancement_timeout"`

	// Image Generation Configuration
	ImageModel   string        `json:"image_model"`
	ImageQuality string        `json:"image_quality"`
	ImageStyle   string        `json:"image_style"`
	ImageURL     string        `json:"image_url"`
	ImageTimeout time.Duration `json:"image_timeout"`
}

AiConfiguration holds configuration for both prompt enhancement and image generation

func DefaultAiConfiguration

func DefaultAiConfiguration() AiConfiguration

DefaultAiConfiguration returns the default AI configuration

type Attribute

type Attribute struct {
	Database string  `json:"database"`
	Name     string  `json:"name"`
	Bytes    string  `json:"bytes"`
	Number   uint64  `json:"number"`
	Factor   float64 `json:"factor"`
	Count    uint64  `json:"count"`
	Selector uint64  `json:"selector"`
	Value    string  `json:"value"`
}

Attribute represents a data attribute with metadata used for prompt generation.

func NewAttribute

func NewAttribute(dbs map[string][]string, index int, bytes string) Attribute

NewAttribute constructs an Attribute from database info and a byte string.

type DalleResponse1

type DalleResponse1 struct {
	Data []struct {
		Url     string `json:"url"`
		B64Data string `json:"b64_json"`
	} `json:"data"`
}

DalleResponse1 represents the JSON structure returned by OpenAI image generation endpoints that contain either direct URLs or base64-encoded image data. This was previously defined privately in the root package as dalleResponse1 and has been moved here for reuse.

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

Message represents a message for the OpenAI API request.

type OpenAIAPIError

type OpenAIAPIError struct {
	Message    string
	StatusCode int
	RequestID  string
	Code       string
}

OpenAIAPIError represents an error from the OpenAI API

func (*OpenAIAPIError) Error

func (e *OpenAIAPIError) Error() string

func (*OpenAIAPIError) IsRetryable

func (e *OpenAIAPIError) IsRetryable() bool

IsRetryable determines if this error should be retried

type Request

type Request struct {
	Input       string    `json:"input,omitempty"`
	Prompt      string    `json:"prompt,omitempty"`
	N           int       `json:"n,omitempty"`
	Quality     string    `json:"quality,omitempty"`
	Model       string    `json:"model,omitempty"`
	Style       string    `json:"style,omitempty"`
	Size        string    `json:"size,omitempty"`
	Seed        int       `json:"seed,omitempty"`
	Temperature float64   `json:"temperature,omitempty"`
	Messages    []Message `json:"messages,omitempty"`
}

Request represents a request payload for the OpenAI API.

func (*Request) String

func (req *Request) String() string

String returns the JSON representation of the Request.

Jump to

Keyboard shortcuts

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