Documentation
¶
Index ¶
- func BuildDataURI(mimeType, base64Data string) string
- func ExtractMIMETypeFromURIOrURL(s string) string
- func GuessMIMETypeFromURL(rawURL string) string
- func ImageToDataURI(path string, highQuality bool) (name, dataURI string, err error)
- func IsImageMIME(m string) bool
- func ParseDataURI(uri string) (mimeType string, base64Data string, ok bool)
- type AudioURL
- type CacheHint
- type Content
- func (c *Content) AddImage(imageURL string)
- func (c *Content) Append(text string)
- func (c *Content) AppendThought(text string)
- func (c *Content) AppendThoughtWithID(id, text string, summary bool) *Thought
- func (c Content) AsString() (string, bool)
- func (c Content) MarshalJSON() ([]byte, error)
- func (c *Content) SetThoughtSignature(signature string)
- func (c *Content) SetThoughtSummary(text, signature string)
- func (c *Content) UnmarshalJSON(data []byte) error
- type ImageURL
- type Item
- type JSON
- type MetadataCarrier
- type Text
- type Thought
- type Type
- type VideoURL
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDataURI ¶
BuildDataURI constructs a data URI from the given MIME type and base64 data.
func ExtractMIMETypeFromURIOrURL ¶
ExtractMIMETypeFromURIOrURL tries to obtain a MIME type from either a data URI (preferred) or a regular URL path extension as a fallback.
func GuessMIMETypeFromURL ¶
GuessMIMETypeFromURL attempts to infer a MIME type from a URL's path extension using the local MIME database. Falls back to a small set of common image/audio/video extensions when necessary. Returns an empty string if no guess can be made.
func ImageToDataURI ¶
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.
func IsImageMIME ¶
IsImageMIME returns true if the provided MIME type looks like an image type.
Types ¶
type AudioURL ¶
type AudioURL struct {
URL string `json:"audio_url"`
MimeType string `json:"mime_type,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
func (*AudioURL) GetMetadata ¶
type CacheHint ¶
type CacheHint struct {
// Duration: "short", "long"
Duration string `json:"duration,omitempty"`
}
type Content ¶
type Content []Item
func FromAny ¶
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 FromTextAndImage ¶
FromTextAndImage returns a new content item with the given text and image URL.
func (*Content) Append ¶
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) AppendThought ¶
AppendThought adds the given text to the last content item if it's a thought, otherwise it adds a new thought item to the end of the list.
func (*Content) AppendThoughtWithID ¶
AppendThoughtWithID finds an existing thought with the given ID and appends text to it, or creates a new thought with the given ID if none exists. Returns the thought that was updated or created. This is useful for streaming APIs that provide thought IDs upfront.
func (Content) AsString ¶
AsString returns the text content and true if the Content contains exactly one Text item. Otherwise, it returns an empty string and false.
func (Content) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for Content.
func (*Content) SetThoughtSignature ¶
SetThoughtSignature sets the signature for the last thought item. Panics if there is no thought item.
func (*Content) SetThoughtSummary ¶
SetThoughtSummary will replace the last content item if it's a thought, otherwise it adds a new thought item to the end of the list.
func (*Content) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface for Content.
type ImageURL ¶
type ImageURL struct {
URL string `json:"image_url"`
// MimeType, if omitted, will be inferred from data URIs / URL path extensions.
MimeType string `json:"mime_type,omitempty"`
// Metadata holds provider-specific metadata that should be forwarded unchanged.
Metadata map[string]string `json:"metadata,omitempty"`
}
func (*ImageURL) GetMetadata ¶
type JSON ¶
type JSON struct {
Data json.RawMessage `json:"data"`
}
type MetadataCarrier ¶
MetadataCarrier is implemented by content items that can carry provider-specific metadata through the pipeline. Keys are prefixed with the provider name, e.g. "openai:item_id".
type Thought ¶
type Thought struct {
ID string `json:"id,omitempty"`
Text string `json:"text,omitempty"`
Encrypted []byte `json:"encrypted,omitempty"`
Signature string `json:"signature,omitempty"`
// Metadata holds protocol-specific metadata that should be forwarded unchanged.
// Keys are prefixed with the protocol/provider name, e.g. "openai:format".
Metadata map[string]string `json:"metadata,omitempty"`
// Summary is true if the thought is a complete summary of the thinking
// session, as opposed to the actual thinking stream.
Summary bool `json:"summary"`
}