github gofr-dev/gofr v1.58.0

7 hours ago

Release v1.58.0

🚀 Features

🔹 LLM Support with Built-in Observability

Call LLMs directly from a handler, with tracing, token-usage metrics, logs and health wired
automatically — the same zero-config observability GoFr gives every datasource. Token usage
is captured per request and recorded as the app_llm_tokens_per_request histogram, labelled
by provider, model, status and token_type (prompt / completion / cached⊆prompt /
reasoning⊆completion), so cost and consumption are visible out of the box. Register a model with
app.AddLLM, then reach it via ctx.LLM(). Register additional named models and select one
per call. An OpenAI-compatible model can also wire from the environment with no code — set
LLM_PROVIDER, LLM_MODEL, LLM_API_KEY and skip AddLLM entirely. Providers:
OpenAI / Groq / DeepSeek / Together / Ollama, or any OpenAI-compatible BaseURL.

app.AddLLM(&llm.Client{Provider: llm.Groq, Model: "llama-3.3-70b-versatile"})
resp, _ := ctx.LLM().Generate(ctx, prompt) // tracing + metrics automatic

// Register additional named models and select one per call.
app.AddLLM(&llm.Client{Provider: llm.OpenAI, Model: "gpt-4o-mini"}, gofr.WithName("fast"))
quick, _ := ctx.LLM("fast").Generate(ctx, prompt)

🔹 Server-Sent Events (SSE) Streaming

A new generic response.Stream special-response type streams values to the client over SSE
(and NDJSON) — useful for LLM token streaming, progress updates, or log tailing. Values are
pulled on demand over an unbuffered channel for backpressure, and the responder flushes via
http.NewResponseController. Streaming is transport, not tied to AI.

func handler(ctx *gofr.Context) (any, error) {
    return response.Stream{Source: tokens}, nil // flushed to the client as they arrive
}

🔹 MCP — Expose Your Service to AI Agents

app.EnableMCP() exposes your read-only handlers to AI agents as MCP tools. Tool calls are
rebuilt into *http.Requests and dispatched back through the real router, so Bind /
validation / RBAC / auth middleware all run and the caller's auth headers propagate
(ctx.GetAuthInfo() works). The same tools back ctx.LLM().Tools(), so you can build an
agent loop over your own service's endpoints.

app.EnableMCP()            // read-only handlers become MCP tools
tools := ctx.LLM().Tools() // build an agent loop over your own endpoints

🔹 S3 Signed URL Support

The S3 file store now implements GenerateSignedURL, making it a first-class
CloudFileSystem alongside GCS. URLs are signed locally with AWS Signature V4 (offline, no
new dependency), and an extensible flavor system lets the same store target S3-compatible
providers. Previously S3 returned ErrSignedURLsNotSupported.

🛠️ Fixes

  • Subscriber Backoff on Handler Error — a failing pub/sub handler now propagates its
    error to startSubscriber, engaging the existing 2s backoff instead of tight-looping on
    every consecutive failure. The recovered-panic sentinel still returns nil to avoid
    duplicate logging.

  • Dependency Updates — Consolidated minor/patch dependency updates and bumped GitHub
    Actions to their latest major versions.

Full Changelog: v1.57.0...v1.58.0

Don't miss a new gofr release

NewReleases is sending notifications on new releases.