content

package
v0.0.0-...-e4aef70 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImageToDataURI

func ImageToDataURI(path string, highQuality bool) (name, dataURI string, err error)

ImageToDataURI reads an image from the given path, resizes it if necessary based on the quality setting, encodes it as base64, and returns its filename and a data URI string.

Types

type Content

type Content []Item

func FromAny

func FromAny(value any) (Content, error)

FromAny marshals the given value to JSON and returns a new JSON content item with the marshalled JSON data.

func FromRawJSON

func FromRawJSON(data json.RawMessage) Content

FromRawJSON returns a new JSON content item with the given raw JSON data.

func FromText

func FromText(text string) Content

FromText returns a new content item with the given text.

func FromTextAndImage

func FromTextAndImage(text, imageURL string) Content

FromTextAndImage returns a new content item with the given text and image URL.

func Textf

func Textf(format string, args ...any) Content

Textf returns a new content item with the provided formatted text.

func (*Content) AddImage

func (c *Content) AddImage(imageURL string)

AddImage adds an image URL to the content.

func (*Content) Append

func (c *Content) Append(text string)

Append adds the text to the last content item if it's a text item, otherwise it adds a new text item to the end of the list.

func (Content) MarshalJSON

func (c Content) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Content.

func (*Content) UnmarshalJSON

func (c *Content) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Content.

type ImageURL

type ImageURL struct {
	URL string `json:"image_url"`
}

func (*ImageURL) Type

func (iu *ImageURL) Type() Type

type Item

type Item interface {
	Type() Type
}

type JSON

type JSON struct {
	Data json.RawMessage `json:"data"`
}

func (*JSON) Type

func (j *JSON) Type() Type

type Text

type Text struct {
	Text string `json:"text"`
}

func (*Text) Type

func (t *Text) Type() Type

type Type

type Type string
const (
	TypeText     Type = "text"
	TypeImageURL Type = "imageURL"
	TypeJSON     Type = "json"
)

Jump to

Keyboard shortcuts

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