Skip to content

feat(ai): add image generation support - #1461

Merged
hwbrzzl merged 3 commits into
masterfrom
bowen/#918-1
May 3, 2026
Merged

hwbrzzl merged 3 commits into
masterfrom
bowen/#918-1

Conversation

@hwbrzzl

@hwbrzzl hwbrzzl commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a fluent facades.AI().Image(...) API for generating and editing images with provider, model, quality, size, timeout, and attachment options
  • support OpenAI image generation and image edits with reference image attachments through the framework AI provider
  • extend AI configuration, errors, and mocks to cover default image models and image responses

Closes goravel/goravel#918

Why

This adds the first end-to-end image generation surface to the framework so Goravel applications can generate and edit images without dropping down to provider-specific SDKs. The API stays on the existing facades.AI() entrypoint and reuses the current image attachment helpers, which keeps image prompting consistent with the rest of the AI module.

image, err := facades.AI().
	Image("Turn this product photo into a watercolor poster").
	Attachments(
		aiimage.FromStorage("products/shoe.png"),
	).
	Landscape().
	Quality(ai.ImageQualityHigh).
	Generate()
if err != nil {
	return ctx.Response().Json(http.StatusInternalServerError, http.Json{
		"error": err.Error(),
	})
}

content, err := image.Content(context.Background())
if err != nil {
	return ctx.Response().Json(http.StatusInternalServerError, http.Json{
		"error": err.Error(),
	})
}

path, err := facades.Storage().Disk("public").Put("images/posters/shoe.png", content)
if err != nil {
	return ctx.Response().Json(http.StatusInternalServerError, http.Json{
		"error": err.Error(),
	})
}

return ctx.Response().Success().Json(http.Json{
	"path": path,
})

It also wires OpenAI image generation and edit endpoints into the provider layer, adds default image model configuration, and covers the new behavior with application and provider tests so the first image feature phase is ready to build on.

Copilot AI review requested due to automatic review settings May 3, 2026 07:47
@hwbrzzl
hwbrzzl requested a review from a team as a code owner May 3, 2026 07:47
@codecov

codecov Bot commented May 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.33663% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.28%. Comparing base (f439f83) to head (85de5e6).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
ai/openai/provider.go 67.74% 31 Missing and 9 partials ⚠️
ai/image_request.go 76.00% 9 Missing and 3 partials ⚠️
ai/setup/stubs.go 0.00% 8 Missing ⚠️
ai/openai/response.go 25.00% 6 Missing ⚠️
ai/application.go 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1461      +/-   ##
==========================================
- Coverage   69.30%   69.28%   -0.03%     
==========================================
  Files         367      368       +1     
  Lines       28949    29151     +202     
==========================================
+ Hits        20062    20196     +134     
- Misses       7987     8042      +55     
- Partials      900      913      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class image generation/edit support to the framework AI surface via a fluent facades.AI().Image(...) request API, with an OpenAI provider implementation and supporting contracts/config/errors/mocks.

Changes:

  • Introduce image-specific AI contracts (ImageRequest, ImageResponse, ImagePrompt) and AI facade entrypoint AI.Image(...).
  • Implement OpenAI image generations/edits (including reference image attachments) and parse image responses into a framework ImageResponse.
  • Extend configuration defaults, errors, and mocks/tests to cover image models and image flows.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
mocks/ai/ImageResponse.go Adds mock for contracts/ai.ImageResponse.
mocks/ai/ImageRequest.go Adds mock for contracts/ai.ImageRequest.
mocks/ai/ImageProvider.go Adds mock for contracts/ai.ImageProvider.
mocks/ai/AI.go Extends AI mock with Image(prompt, ...Option) fluent entrypoint.
errors/list.go Adds centralized errors for image provider support and image prompt/response validation.
contracts/ai/response.go Adds ImageResponse interface (content, mime type, usage, Then).
contracts/ai/provider.go Adds ImagePrompt and ImageProvider provider extension interface.
contracts/ai/image.go Introduces image request contract plus ImageQuality/ImageSize types.
contracts/ai/config.go Extends model config with Models.Image.Default.
contracts/ai/ai.go Adds AI.Image(...) ImageRequest to the primary AI contract.
ai/setup/stubs.go Updates AI setup stub config to include default image model config.
ai/openai/response.go Implements OpenAI-backed ImageResponse (and related response structs).
ai/openai/provider_test.go Adds provider tests for image generations/edits, validations, and request shaping.
ai/openai/provider.go Implements OpenAI Image(...) support and image response parsing.
ai/image_request.go Adds internal fluent request builder wiring to Application.image(...).
ai/image.go Re-exports image size/quality types/constants from contracts for convenience.
ai/application_test.go Adds application-level tests for the fluent image request and provider dispatch.
ai/application.go Adds Application.Image(...) and internal image(...) dispatch via ImageProvider.

Comment thread contracts/ai/provider.go
Comment thread ai/image_request.go
Comment thread ai/openai/response.go Outdated
Comment thread ai/openai/provider_test.go Outdated
Comment thread ai/openai/provider.go
Comment thread ai/image.go Outdated
Copilot AI review requested due to automatic review settings May 3, 2026 14:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Comment on lines 55 to +70
app.Call(func() {
immediatelyCall++
if immediatelyCall.Add(1) == 3 {
go func() {
shutdownErr <- app.Shutdown()
}()
}
}).Cron("* * * * * *"),
app.Call(func() {
time.Sleep(2 * time.Second)
delayIfStillRunningCall++
time.Sleep(1100 * time.Millisecond)
delayIfStillRunningCall.Add(1)
}).Cron("* * * * * *").DelayIfStillRunning(),
app.Call(func() {
time.Sleep(2 * time.Second)
skipIfStillRunningCall++
time.Sleep(2500 * time.Millisecond)
skipIfStillRunningCall.Add(1)
}).Cron("* * * * * *").SkipIfStillRunning(),
app.Command("test --name Goravel argument0 argument1").Cron("*/2 * * * * *"),
app.Command("test --name Goravel argument0 argument1").Cron("* * * * * *"),
Comment on lines +83 to +87
s.Equal(int64(3), immediatelyCall.Load())
s.Equal(int64(3), delayIfStillRunningCall.Load())
s.Equal(int64(1), skipIfStillRunningCall.Load())
s.Equal(int64(3), commandCall.Load())
s.Equal(int64(3), panicCall.Load())
@hwbrzzl
hwbrzzl merged commit 40421cc into master May 3, 2026
21 of 23 checks passed
@hwbrzzl
hwbrzzl deleted the bowen/#918-1 branch May 3, 2026 14:25
LinboLen added a commit to LinboLen/framework that referenced this pull request May 3, 2026
* origin/master:
  fix(ai): remove context from image response content (goravel#1462)
  feat(ai): support provider-managed files (goravel#1460)
  feat(ai): add image generation support (goravel#1461)
  fix: [goravel#946] stop WithContext from leaking framework context keys (goravel#1456)
  feat(ai): add attachment upload support (goravel#1459)
  feat(ai): add attachment helper subpackages (goravel#1458)
  feat(ai): switch OpenAI provider to responses API (goravel#1457)
  feat(ai): add attachment support (goravel#1455)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] AI SDK Phase 4: Multi-Modal (Attachments, Image, and Audio)

2 participants