resource

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Data

func Data(name string, data []byte) (llm.Resource, error)

Data returns a new in-memory resource for the given raw bytes. The MIME type is resolved by content sniffing first; if the sniffed type is application/octet-stream and name has an extension, the extension is used as a fallback. If name contains path separators or an extension, the bare base name (without extension) is used as the resource identifier.

func JSON

func JSON(name string, v any) (llm.Resource, error)

JSON returns a new in-memory JSON resource with the given name. If v is already a json.RawMessage it is used directly; otherwise v is marshalled to JSON. Name must be a non-empty identifier.

func Must

func Must[V string | json.RawMessage | []byte](name string, value V) llm.Resource

Must creates a resource from name and value, panicking on error. V may be string (text resource), json.RawMessage (JSON resource), or []byte (data resource).

func Read

func Read(r io.Reader) (llm.Resource, error)

Read reads all bytes from r and returns a resource. If r is an *os.File its path is used to derive the name and MIME type, exactly as Data() does. For other readers r must be an io.Reader with discoverable content only; the name defaults to "data" and the MIME type is content-sniffed.

func Text

func Text(name, content string) (llm.Resource, error)

Text returns a new in-memory text resource with the given name and content. The URI scheme is "text:" and the MIME type is "text/plain". Name must be a non-empty identifier.

func Unmarshal

func Unmarshal(data []byte) (llm.Resource, error)

Unmarshal decodes a JSON-encoded resource (as produced by MarshalJSON) back into an llm.Resource. The MIME type field determines the concrete type:

  • "text/plain" → text resource
  • "application/json" → JSON resource
  • anything else → binary data resource

If the JSON contains a non-empty description the result is wrapped with WithDescription so that Description() returns the stored value.

func WithDescription

func WithDescription(description string, r llm.Resource) llm.Resource

WithDescription returns r with its description replaced by the given value.

func WithNamespace

func WithNamespace(namespace string, r llm.Resource) llm.Resource

WithNamespace returns r with its name replaced by "namespace.r.Name()".

func WithURI

func WithURI(uri string, r llm.Resource) llm.Resource

WithURI returns r with its URI replaced by the given value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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