Skip to content

Commit 609d734

Browse files
committed
feat: improve generation stability and prompt optimization
1 parent b2ec5b3 commit 609d734

31 files changed

Lines changed: 991 additions & 830 deletions

backend/go.mod

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ require (
77
github.com/disintegration/imaging v1.6.2
88
github.com/gin-gonic/gin v1.11.0
99
github.com/google/uuid v1.6.0
10+
github.com/mattn/go-sqlite3 v1.14.22
1011
github.com/mazrean/formstream v1.1.3
11-
github.com/openai/openai-go/v3 v3.15.0
1212
github.com/spf13/viper v1.21.0
13-
google.golang.org/genai v1.40.0
13+
golang.org/x/sync v0.17.0
1414
gorm.io/driver/sqlite v1.6.0
1515
gorm.io/gorm v1.31.1
1616
)
1717

1818
require (
19-
cloud.google.com/go v0.116.0 // indirect
20-
cloud.google.com/go/auth v0.9.3 // indirect
21-
cloud.google.com/go/compute/metadata v0.5.0 // indirect
2219
github.com/bytedance/sonic v1.14.0 // indirect
2320
github.com/bytedance/sonic/loader v0.3.0 // indirect
2421
github.com/cloudwego/base64x v0.1.6 // indirect
@@ -31,18 +28,12 @@ require (
3128
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
3229
github.com/goccy/go-json v0.10.2 // indirect
3330
github.com/goccy/go-yaml v1.18.0 // indirect
34-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
35-
github.com/google/go-cmp v0.7.0 // indirect
36-
github.com/google/s2a-go v0.1.8 // indirect
37-
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
38-
github.com/gorilla/websocket v1.5.3 // indirect
3931
github.com/jinzhu/inflection v1.0.0 // indirect
4032
github.com/jinzhu/now v1.1.5 // indirect
4133
github.com/json-iterator/go v1.1.12 // indirect
4234
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
4335
github.com/leodido/go-urn v1.4.0 // indirect
4436
github.com/mattn/go-isatty v0.0.20 // indirect
45-
github.com/mattn/go-sqlite3 v1.14.22 // indirect
4637
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4738
github.com/modern-go/reflect2 v1.0.2 // indirect
4839
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
@@ -54,26 +45,18 @@ require (
5445
github.com/spf13/cast v1.10.0 // indirect
5546
github.com/spf13/pflag v1.0.10 // indirect
5647
github.com/subosito/gotenv v1.6.0 // indirect
57-
github.com/tidwall/gjson v1.18.0 // indirect
58-
github.com/tidwall/match v1.1.1 // indirect
59-
github.com/tidwall/pretty v1.2.1 // indirect
60-
github.com/tidwall/sjson v1.2.5 // indirect
6148
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
6249
github.com/ugorji/go/codec v1.3.0 // indirect
63-
go.opencensus.io v0.24.0 // indirect
6450
go.uber.org/mock v0.6.0 // indirect
6551
go.yaml.in/yaml/v3 v3.0.4 // indirect
6652
golang.org/x/arch v0.20.0 // indirect
6753
golang.org/x/crypto v0.41.0 // indirect
6854
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect
6955
golang.org/x/mod v0.27.0 // indirect
7056
golang.org/x/net v0.43.0 // indirect
71-
golang.org/x/sync v0.17.0 // indirect
7257
golang.org/x/sys v0.35.0 // indirect
7358
golang.org/x/text v0.28.0 // indirect
7459
golang.org/x/time v0.6.0 // indirect
7560
golang.org/x/tools v0.36.0 // indirect
76-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
77-
google.golang.org/grpc v1.66.2 // indirect
7861
google.golang.org/protobuf v1.36.9 // indirect
7962
)

backend/go.sum

Lines changed: 0 additions & 111 deletions
Large diffs are not rendered by default.

backend/inspect_client_config.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

backend/inspect_http_options.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

backend/inspect_struct.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

backend/internal/api/export_images.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ import (
1111
"strings"
1212
"time"
1313

14+
"image-gen-service/internal/config"
1415
"image-gen-service/internal/model"
1516

1617
"github.com/gin-gonic/gin"
1718
)
1819

19-
const maxExportRemoteSize = 50 * 1024 * 1024
20+
const (
21+
defaultExportRemoteFetchTimeoutSeconds = 120
22+
defaultExportRemoteMaxFileMB = 512
23+
)
2024

2125
type exportImagesRequest struct {
2226
ImageIDs []string `json:"imageIds"`
@@ -176,7 +180,16 @@ func ExportImagesHandler(c *gin.Context) {
176180
}
177181

178182
func writeRemoteFile(writer io.Writer, source string) error {
179-
resp, err := http.Get(source)
183+
timeoutSeconds := config.GlobalConfig.Exports.RemoteFetchTimeoutSeconds
184+
if timeoutSeconds <= 0 {
185+
timeoutSeconds = defaultExportRemoteFetchTimeoutSeconds
186+
}
187+
188+
client := &http.Client{
189+
Timeout: time.Duration(timeoutSeconds) * time.Second,
190+
}
191+
192+
resp, err := client.Get(source)
180193
if err != nil {
181194
return err
182195
}
@@ -186,13 +199,19 @@ func writeRemoteFile(writer io.Writer, source string) error {
186199
return fmt.Errorf("http status %d", resp.StatusCode)
187200
}
188201

189-
reader := io.LimitReader(resp.Body, maxExportRemoteSize+1)
202+
maxFileMB := config.GlobalConfig.Exports.RemoteMaxFileMB
203+
if maxFileMB <= 0 {
204+
maxFileMB = defaultExportRemoteMaxFileMB
205+
}
206+
207+
maxBytes := int64(maxFileMB) * 1024 * 1024
208+
reader := io.LimitReader(resp.Body, maxBytes+1)
190209
written, err := io.Copy(writer, reader)
191210
if err != nil {
192211
return err
193212
}
194-
if written > maxExportRemoteSize {
195-
return fmt.Errorf("remote file exceeds %d bytes", maxExportRemoteSize)
213+
if written > maxBytes {
214+
return fmt.Errorf("remote file exceeds %d bytes", maxBytes)
196215
}
197216
return nil
198217
}

0 commit comments

Comments
 (0)