diff --git a/backend/biz/host/usecase/host.go b/backend/biz/host/usecase/host.go index 2bda3b81..303355b3 100644 --- a/backend/biz/host/usecase/host.go +++ b/backend/biz/host/usecase/host.go @@ -406,11 +406,12 @@ func (h *HostUsecase) CreateVM(ctx context.Context, user *domain.User, req *doma var LLMConfig taskflow.LLMProviderReq if model != nil { LLMConfig = taskflow.LLMProviderReq{ - Provider: taskflow.LlmProviderOpenAI, - ApiKey: model.APIKey, - Model: model.Model, - Temperature: temperature, - BaseURL: model.BaseURL, + Provider: taskflow.LlmProviderOpenAI, + ApiKey: model.APIKey, + Model: model.Model, + SupportImage: model.SupportImage, + Temperature: temperature, + BaseURL: model.BaseURL, } } diff --git a/backend/biz/setting/repo/model.go b/backend/biz/setting/repo/model.go index 322751d4..5e67a537 100644 --- a/backend/biz/setting/repo/model.go +++ b/backend/biz/setting/repo/model.go @@ -147,6 +147,9 @@ func (r *modelRepo) Create(ctx context.Context, uid uuid.UUID, req *domain.Creat if req.ThinkingEnabled != nil { create.SetThinkingEnabled(*req.ThinkingEnabled) } + if req.SupportImage != nil { + create.SetSupportImage(*req.SupportImage) + } if req.ContextLimit != nil { create.SetContextLimit(*req.ContextLimit) } @@ -231,6 +234,9 @@ func (r *modelRepo) Update(ctx context.Context, uid, id uuid.UUID, req *domain.U if req.ThinkingEnabled != nil { update.SetThinkingEnabled(*req.ThinkingEnabled) } + if req.SupportImage != nil { + update.SetSupportImage(*req.SupportImage) + } if req.ContextLimit != nil { update.SetContextLimit(*req.ContextLimit) } diff --git a/backend/biz/task/usecase/gittask.go b/backend/biz/task/usecase/gittask.go index 38046a8c..71d1af5c 100644 --- a/backend/biz/task/usecase/gittask.go +++ b/backend/biz/task/usecase/gittask.go @@ -75,10 +75,11 @@ func (g *GitTaskUsecase) Create(ctx context.Context, req domain.CreateGitTaskReq ImageURL: g.cfg.ReviewAgent.Image, TaskID: t.ID, LLM: taskflow.LLMProviderReq{ - Provider: taskflow.LlmProviderOpenAI, - ApiKey: m.APIKey, - BaseURL: m.BaseURL, - Model: m.Model, + Provider: taskflow.LlmProviderOpenAI, + ApiKey: m.APIKey, + BaseURL: m.BaseURL, + Model: m.Model, + SupportImage: m.SupportImage, }, Cores: fmt.Sprintf("%d", g.cfg.Task.Core), Memory: g.cfg.Task.Memory, @@ -111,9 +112,10 @@ func (g *GitTaskUsecase) Create(ctx context.Context, req domain.CreateGitTaskReq Text: req.Prompt, CodingAgent: taskflow.CodingAgentMCAIReview, LLM: taskflow.LLM{ - ApiKey: m.APIKey, - BaseURL: m.BaseURL, - Model: m.Model, + ApiKey: m.APIKey, + BaseURL: m.BaseURL, + Model: m.Model, + SupportImage: m.SupportImage, }, Env: req.Env, LogStore: normalizeTaskLogStore(t.LogStore), diff --git a/backend/biz/task/usecase/task.go b/backend/biz/task/usecase/task.go index b7deb680..7647cad5 100644 --- a/backend/biz/task/usecase/task.go +++ b/backend/biz/task/usecase/task.go @@ -526,10 +526,11 @@ func (a *TaskUsecase) Create(ctx context.Context, user *domain.User, req domain. ProxyURL: "", TaskID: t.ID, LLM: taskflow.LLMProviderReq{ - Provider: taskflow.LlmProviderOpenAI, - ApiKey: m.APIKey, - BaseURL: m.BaseURL, - Model: m.Model, + Provider: taskflow.LlmProviderOpenAI, + ApiKey: m.APIKey, + BaseURL: m.BaseURL, + Model: m.Model, + SupportImage: m.SupportImage, }, Cores: "2", Memory: 8 << 30, @@ -556,10 +557,11 @@ func (a *TaskUsecase) Create(ctx context.Context, user *domain.User, req domain. SystemPrompt: req.SystemPrompt, CodingAgent: coding, LLM: taskflow.LLM{ - ApiKey: m.APIKey, - BaseURL: m.BaseURL, - Model: m.Model, - ApiType: m.InterfaceType, + ApiKey: m.APIKey, + BaseURL: m.BaseURL, + Model: m.Model, + ApiType: m.InterfaceType, + SupportImage: m.SupportImage, }, Configs: configs, McpConfigs: mcps, @@ -754,6 +756,7 @@ func (a *TaskUsecase) getCodingConfigs(cli consts.CliName, m *db.Model, skillIDs "api_key": m.APIKey, "npm_package": npmPackage, "thinking_enabled": thinkingEnabled, + "support_image": m.SupportImage, "force_reasoning": strings.HasPrefix(m.Model, "monkeycode-ultra"), "context_limit": contextLimit, "output_limit": outputLimit, diff --git a/backend/biz/task/usecase/task_model_config_test.go b/backend/biz/task/usecase/task_model_config_test.go index 0276ff08..8e11f928 100644 --- a/backend/biz/task/usecase/task_model_config_test.go +++ b/backend/biz/task/usecase/task_model_config_test.go @@ -197,6 +197,50 @@ func TestGetCodingConfigsOpenCodeRendersUltraForceReasoning(t *testing.T) { } } +func TestGetCodingConfigsOpenCodeRendersSupportImage(t *testing.T) { + uc := &TaskUsecase{} + model := &db.Model{ + BaseURL: "https://example.com/v1", + Model: "gpt-4.1", + APIKey: "sk-test", + InterfaceType: string(consts.InterfaceTypeOpenAIResponse), + SupportImage: true, + } + + _, cfs, err := uc.getCodingConfigs(consts.CliNameOpencode, model, nil) + if err != nil { + t.Fatalf("getCodingConfigs() error = %v", err) + } + + config := opencodeConfig(t, cfs) + provider := opencodeProvider(t, config) + renderedModel := opencodeModel(t, provider, "gpt-4.1") + if got := renderedModel["attachment"]; got != true { + t.Fatalf("attachment = %v, want true", got) + } + modalities, ok := renderedModel["modalities"].(map[string]any) + if !ok { + t.Fatalf("modalities = %v, want object", renderedModel["modalities"]) + } + assertStringSlice(t, modalities["input"], []string{"text", "image"}) + assertStringSlice(t, modalities["output"], []string{"text"}) + + model.SupportImage = false + _, cfs, err = uc.getCodingConfigs(consts.CliNameOpencode, model, nil) + if err != nil { + t.Fatalf("getCodingConfigs() error = %v", err) + } + config = opencodeConfig(t, cfs) + provider = opencodeProvider(t, config) + renderedModel = opencodeModel(t, provider, "gpt-4.1") + if _, ok := renderedModel["attachment"]; ok { + t.Fatalf("attachment = %v, want absent", renderedModel["attachment"]) + } + if _, ok := renderedModel["modalities"]; ok { + t.Fatalf("modalities = %v, want absent", renderedModel["modalities"]) + } +} + func TestGetCodingConfigsNilModel(t *testing.T) { uc := &TaskUsecase{} _, _, err := uc.getCodingConfigs(consts.CliNameOpencode, nil, nil) @@ -219,6 +263,22 @@ func opencodeAuthConfig(t *testing.T, cfs []taskflow.ConfigFile) taskflow.Config return taskflow.ConfigFile{} } +func assertStringSlice(t *testing.T, got any, want []string) { + t.Helper() + values, ok := got.([]any) + if !ok { + t.Fatalf("value = %v, want array", got) + } + if len(values) != len(want) { + t.Fatalf("value length = %d, want %d", len(values), len(want)) + } + for i, wantValue := range want { + if values[i] != wantValue { + t.Fatalf("value[%d] = %v, want %q", i, values[i], wantValue) + } + } +} + func opencodeConfig(t *testing.T, cfs []taskflow.ConfigFile) map[string]any { t.Helper() for _, cf := range cfs { diff --git a/backend/biz/team/repo/model.go b/backend/biz/team/repo/model.go index 49f37822..814bcfd3 100644 --- a/backend/biz/team/repo/model.go +++ b/backend/biz/team/repo/model.go @@ -75,7 +75,7 @@ func (r *teamModelRepo) Create(ctx context.Context, teamID uuid.UUID, userID uui return tg.ID }) - newModel, err := tx.Model.Create(). + create := tx.Model.Create(). SetProvider(req.Provider). SetAPIKey(req.APIKey). SetBaseURL(req.BaseURL). @@ -83,8 +83,12 @@ func (r *teamModelRepo) Create(ctx context.Context, teamID uuid.UUID, userID uui SetRemark(req.Remark). SetUserID(userID). SetTemperature(req.Temperature). - SetInterfaceType(string(req.InterfaceType)). - Save(ctx) + SetInterfaceType(string(req.InterfaceType)) + if req.SupportImage != nil { + create.SetSupportImage(*req.SupportImage) + } + + newModel, err := create.Save(ctx) if err != nil { return err } @@ -150,6 +154,9 @@ func (r *teamModelRepo) Update(ctx context.Context, teamID uuid.UUID, req *domai if req.InterfaceType != "" { upt.SetInterfaceType(string(req.InterfaceType)) } + if req.SupportImage != nil { + upt.SetSupportImage(*req.SupportImage) + } err := upt.Exec(ctx) if err != nil { return err diff --git a/backend/db/migrate/schema.go b/backend/db/migrate/schema.go index fd78bbfe..0d4bdba9 100644 --- a/backend/db/migrate/schema.go +++ b/backend/db/migrate/schema.go @@ -357,6 +357,7 @@ var ( {Name: "interface_type", Type: field.TypeString, Nullable: true}, {Name: "weight", Type: field.TypeInt, Default: 1}, {Name: "thinking_enabled", Type: field.TypeBool, Default: true}, + {Name: "support_image", Type: field.TypeBool, Default: false}, {Name: "context_limit", Type: field.TypeInt, Default: 200000}, {Name: "output_limit", Type: field.TypeInt, Default: 32000}, {Name: "last_check_at", Type: field.TypeTime, Nullable: true}, @@ -374,7 +375,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "models_users_models", - Columns: []*schema.Column{ModelsColumns[18]}, + Columns: []*schema.Column{ModelsColumns[19]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.NoAction, }, diff --git a/backend/db/model.go b/backend/db/model.go index 05380125..40712d4c 100644 --- a/backend/db/model.go +++ b/backend/db/model.go @@ -42,6 +42,8 @@ type Model struct { Weight int `json:"weight,omitempty"` // ThinkingEnabled holds the value of the "thinking_enabled" field. ThinkingEnabled bool `json:"thinking_enabled,omitempty"` + // SupportImage holds the value of the "support_image" field. + SupportImage bool `json:"support_image,omitempty"` // ContextLimit holds the value of the "context_limit" field. ContextLimit int `json:"context_limit,omitempty"` // OutputLimit holds the value of the "output_limit" field. @@ -199,7 +201,7 @@ func (*Model) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case model.FieldThinkingEnabled, model.FieldLastCheckSuccess: + case model.FieldThinkingEnabled, model.FieldSupportImage, model.FieldLastCheckSuccess: values[i] = new(sql.NullBool) case model.FieldTemperature: values[i] = new(sql.NullFloat64) @@ -298,6 +300,12 @@ func (_m *Model) assignValues(columns []string, values []any) error { } else if value.Valid { _m.ThinkingEnabled = value.Bool } + case model.FieldSupportImage: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field support_image", values[i]) + } else if value.Valid { + _m.SupportImage = value.Bool + } case model.FieldContextLimit: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field context_limit", values[i]) @@ -464,6 +472,9 @@ func (_m *Model) String() string { builder.WriteString("thinking_enabled=") builder.WriteString(fmt.Sprintf("%v", _m.ThinkingEnabled)) builder.WriteString(", ") + builder.WriteString("support_image=") + builder.WriteString(fmt.Sprintf("%v", _m.SupportImage)) + builder.WriteString(", ") builder.WriteString("context_limit=") builder.WriteString(fmt.Sprintf("%v", _m.ContextLimit)) builder.WriteString(", ") diff --git a/backend/db/model/model.go b/backend/db/model/model.go index 537aa63b..7e5e0192 100644 --- a/backend/db/model/model.go +++ b/backend/db/model/model.go @@ -37,6 +37,8 @@ const ( FieldWeight = "weight" // FieldThinkingEnabled holds the string denoting the thinking_enabled field in the database. FieldThinkingEnabled = "thinking_enabled" + // FieldSupportImage holds the string denoting the support_image field in the database. + FieldSupportImage = "support_image" // FieldContextLimit holds the string denoting the context_limit field in the database. FieldContextLimit = "context_limit" // FieldOutputLimit holds the string denoting the output_limit field in the database. @@ -164,6 +166,7 @@ var Columns = []string{ FieldInterfaceType, FieldWeight, FieldThinkingEnabled, + FieldSupportImage, FieldContextLimit, FieldOutputLimit, FieldLastCheckAt, @@ -212,6 +215,8 @@ var ( DefaultWeight int // DefaultThinkingEnabled holds the default value on creation for the "thinking_enabled" field. DefaultThinkingEnabled bool + // DefaultSupportImage holds the default value on creation for the "support_image" field. + DefaultSupportImage bool // DefaultContextLimit holds the default value on creation for the "context_limit" field. DefaultContextLimit int // DefaultOutputLimit holds the default value on creation for the "output_limit" field. @@ -287,6 +292,11 @@ func ByThinkingEnabled(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldThinkingEnabled, opts...).ToFunc() } +// BySupportImage orders the results by the support_image field. +func BySupportImage(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSupportImage, opts...).ToFunc() +} + // ByContextLimit orders the results by the context_limit field. func ByContextLimit(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldContextLimit, opts...).ToFunc() diff --git a/backend/db/model/where.go b/backend/db/model/where.go index 1fe9d97d..28a7127a 100644 --- a/backend/db/model/where.go +++ b/backend/db/model/where.go @@ -111,6 +111,11 @@ func ThinkingEnabled(v bool) predicate.Model { return predicate.Model(sql.FieldEQ(FieldThinkingEnabled, v)) } +// SupportImage applies equality check predicate on the "support_image" field. It's identical to SupportImageEQ. +func SupportImage(v bool) predicate.Model { + return predicate.Model(sql.FieldEQ(FieldSupportImage, v)) +} + // ContextLimit applies equality check predicate on the "context_limit" field. It's identical to ContextLimitEQ. func ContextLimit(v int) predicate.Model { return predicate.Model(sql.FieldEQ(FieldContextLimit, v)) @@ -726,6 +731,16 @@ func ThinkingEnabledNEQ(v bool) predicate.Model { return predicate.Model(sql.FieldNEQ(FieldThinkingEnabled, v)) } +// SupportImageEQ applies the EQ predicate on the "support_image" field. +func SupportImageEQ(v bool) predicate.Model { + return predicate.Model(sql.FieldEQ(FieldSupportImage, v)) +} + +// SupportImageNEQ applies the NEQ predicate on the "support_image" field. +func SupportImageNEQ(v bool) predicate.Model { + return predicate.Model(sql.FieldNEQ(FieldSupportImage, v)) +} + // ContextLimitEQ applies the EQ predicate on the "context_limit" field. func ContextLimitEQ(v int) predicate.Model { return predicate.Model(sql.FieldEQ(FieldContextLimit, v)) diff --git a/backend/db/model_create.go b/backend/db/model_create.go index 31b686fa..2e2bd0d8 100644 --- a/backend/db/model_create.go +++ b/backend/db/model_create.go @@ -148,6 +148,20 @@ func (_c *ModelCreate) SetNillableThinkingEnabled(v *bool) *ModelCreate { return _c } +// SetSupportImage sets the "support_image" field. +func (_c *ModelCreate) SetSupportImage(v bool) *ModelCreate { + _c.mutation.SetSupportImage(v) + return _c +} + +// SetNillableSupportImage sets the "support_image" field if the given value is not nil. +func (_c *ModelCreate) SetNillableSupportImage(v *bool) *ModelCreate { + if v != nil { + _c.SetSupportImage(*v) + } + return _c +} + // SetContextLimit sets the "context_limit" field. func (_c *ModelCreate) SetContextLimit(v int) *ModelCreate { _c.mutation.SetContextLimit(v) @@ -456,6 +470,10 @@ func (_c *ModelCreate) defaults() error { v := model.DefaultThinkingEnabled _c.mutation.SetThinkingEnabled(v) } + if _, ok := _c.mutation.SupportImage(); !ok { + v := model.DefaultSupportImage + _c.mutation.SetSupportImage(v) + } if _, ok := _c.mutation.ContextLimit(); !ok { v := model.DefaultContextLimit _c.mutation.SetContextLimit(v) @@ -524,6 +542,9 @@ func (_c *ModelCreate) check() error { if _, ok := _c.mutation.ThinkingEnabled(); !ok { return &ValidationError{Name: "thinking_enabled", err: errors.New(`db: missing required field "Model.thinking_enabled"`)} } + if _, ok := _c.mutation.SupportImage(); !ok { + return &ValidationError{Name: "support_image", err: errors.New(`db: missing required field "Model.support_image"`)} + } if _, ok := _c.mutation.ContextLimit(); !ok { return &ValidationError{Name: "context_limit", err: errors.New(`db: missing required field "Model.context_limit"`)} } @@ -615,6 +636,10 @@ func (_c *ModelCreate) createSpec() (*Model, *sqlgraph.CreateSpec) { _spec.SetField(model.FieldThinkingEnabled, field.TypeBool, value) _node.ThinkingEnabled = value } + if value, ok := _c.mutation.SupportImage(); ok { + _spec.SetField(model.FieldSupportImage, field.TypeBool, value) + _node.SupportImage = value + } if value, ok := _c.mutation.ContextLimit(); ok { _spec.SetField(model.FieldContextLimit, field.TypeInt, value) _node.ContextLimit = value @@ -1048,6 +1073,18 @@ func (u *ModelUpsert) UpdateThinkingEnabled() *ModelUpsert { return u } +// SetSupportImage sets the "support_image" field. +func (u *ModelUpsert) SetSupportImage(v bool) *ModelUpsert { + u.Set(model.FieldSupportImage, v) + return u +} + +// UpdateSupportImage sets the "support_image" field to the value that was provided on create. +func (u *ModelUpsert) UpdateSupportImage() *ModelUpsert { + u.SetExcluded(model.FieldSupportImage) + return u +} + // SetContextLimit sets the "context_limit" field. func (u *ModelUpsert) SetContextLimit(v int) *ModelUpsert { u.Set(model.FieldContextLimit, v) @@ -1406,6 +1443,20 @@ func (u *ModelUpsertOne) UpdateThinkingEnabled() *ModelUpsertOne { }) } +// SetSupportImage sets the "support_image" field. +func (u *ModelUpsertOne) SetSupportImage(v bool) *ModelUpsertOne { + return u.Update(func(s *ModelUpsert) { + s.SetSupportImage(v) + }) +} + +// UpdateSupportImage sets the "support_image" field to the value that was provided on create. +func (u *ModelUpsertOne) UpdateSupportImage() *ModelUpsertOne { + return u.Update(func(s *ModelUpsert) { + s.UpdateSupportImage() + }) +} + // SetContextLimit sets the "context_limit" field. func (u *ModelUpsertOne) SetContextLimit(v int) *ModelUpsertOne { return u.Update(func(s *ModelUpsert) { @@ -1950,6 +2001,20 @@ func (u *ModelUpsertBulk) UpdateThinkingEnabled() *ModelUpsertBulk { }) } +// SetSupportImage sets the "support_image" field. +func (u *ModelUpsertBulk) SetSupportImage(v bool) *ModelUpsertBulk { + return u.Update(func(s *ModelUpsert) { + s.SetSupportImage(v) + }) +} + +// UpdateSupportImage sets the "support_image" field to the value that was provided on create. +func (u *ModelUpsertBulk) UpdateSupportImage() *ModelUpsertBulk { + return u.Update(func(s *ModelUpsert) { + s.UpdateSupportImage() + }) +} + // SetContextLimit sets the "context_limit" field. func (u *ModelUpsertBulk) SetContextLimit(v int) *ModelUpsertBulk { return u.Update(func(s *ModelUpsert) { diff --git a/backend/db/model_update.go b/backend/db/model_update.go index 004c6567..90f3e83b 100644 --- a/backend/db/model_update.go +++ b/backend/db/model_update.go @@ -232,6 +232,20 @@ func (_u *ModelUpdate) SetNillableThinkingEnabled(v *bool) *ModelUpdate { return _u } +// SetSupportImage sets the "support_image" field. +func (_u *ModelUpdate) SetSupportImage(v bool) *ModelUpdate { + _u.mutation.SetSupportImage(v) + return _u +} + +// SetNillableSupportImage sets the "support_image" field if the given value is not nil. +func (_u *ModelUpdate) SetNillableSupportImage(v *bool) *ModelUpdate { + if v != nil { + _u.SetSupportImage(*v) + } + return _u +} + // SetContextLimit sets the "context_limit" field. func (_u *ModelUpdate) SetContextLimit(v int) *ModelUpdate { _u.mutation.ResetContextLimit() @@ -855,6 +869,9 @@ func (_u *ModelUpdate) sqlSave(ctx context.Context) (_node int, err error) { if value, ok := _u.mutation.ThinkingEnabled(); ok { _spec.SetField(model.FieldThinkingEnabled, field.TypeBool, value) } + if value, ok := _u.mutation.SupportImage(); ok { + _spec.SetField(model.FieldSupportImage, field.TypeBool, value) + } if value, ok := _u.mutation.ContextLimit(); ok { _spec.SetField(model.FieldContextLimit, field.TypeInt, value) } @@ -1592,6 +1609,20 @@ func (_u *ModelUpdateOne) SetNillableThinkingEnabled(v *bool) *ModelUpdateOne { return _u } +// SetSupportImage sets the "support_image" field. +func (_u *ModelUpdateOne) SetSupportImage(v bool) *ModelUpdateOne { + _u.mutation.SetSupportImage(v) + return _u +} + +// SetNillableSupportImage sets the "support_image" field if the given value is not nil. +func (_u *ModelUpdateOne) SetNillableSupportImage(v *bool) *ModelUpdateOne { + if v != nil { + _u.SetSupportImage(*v) + } + return _u +} + // SetContextLimit sets the "context_limit" field. func (_u *ModelUpdateOne) SetContextLimit(v int) *ModelUpdateOne { _u.mutation.ResetContextLimit() @@ -2245,6 +2276,9 @@ func (_u *ModelUpdateOne) sqlSave(ctx context.Context) (_node *Model, err error) if value, ok := _u.mutation.ThinkingEnabled(); ok { _spec.SetField(model.FieldThinkingEnabled, field.TypeBool, value) } + if value, ok := _u.mutation.SupportImage(); ok { + _spec.SetField(model.FieldSupportImage, field.TypeBool, value) + } if value, ok := _u.mutation.ContextLimit(); ok { _spec.SetField(model.FieldContextLimit, field.TypeInt, value) } diff --git a/backend/db/mutation.go b/backend/db/mutation.go index 11a430b2..b17717ed 100644 --- a/backend/db/mutation.go +++ b/backend/db/mutation.go @@ -12129,6 +12129,7 @@ type ModelMutation struct { weight *int addweight *int thinking_enabled *bool + support_image *bool context_limit *int addcontext_limit *int output_limit *int @@ -12768,6 +12769,42 @@ func (m *ModelMutation) ResetThinkingEnabled() { m.thinking_enabled = nil } +// SetSupportImage sets the "support_image" field. +func (m *ModelMutation) SetSupportImage(b bool) { + m.support_image = &b +} + +// SupportImage returns the value of the "support_image" field in the mutation. +func (m *ModelMutation) SupportImage() (r bool, exists bool) { + v := m.support_image + if v == nil { + return + } + return *v, true +} + +// OldSupportImage returns the old "support_image" field's value of the Model entity. +// If the Model object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ModelMutation) OldSupportImage(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSupportImage is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSupportImage requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSupportImage: %w", err) + } + return oldValue.SupportImage, nil +} + +// ResetSupportImage resets all changes to the "support_image" field. +func (m *ModelMutation) ResetSupportImage() { + m.support_image = nil +} + // SetContextLimit sets the "context_limit" field. func (m *ModelMutation) SetContextLimit(i int) { m.context_limit = &i @@ -13685,7 +13722,7 @@ func (m *ModelMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ModelMutation) Fields() []string { - fields := make([]string, 0, 18) + fields := make([]string, 0, 19) if m.deleted_at != nil { fields = append(fields, model.FieldDeletedAt) } @@ -13719,6 +13756,9 @@ func (m *ModelMutation) Fields() []string { if m.thinking_enabled != nil { fields = append(fields, model.FieldThinkingEnabled) } + if m.support_image != nil { + fields = append(fields, model.FieldSupportImage) + } if m.context_limit != nil { fields = append(fields, model.FieldContextLimit) } @@ -13770,6 +13810,8 @@ func (m *ModelMutation) Field(name string) (ent.Value, bool) { return m.Weight() case model.FieldThinkingEnabled: return m.ThinkingEnabled() + case model.FieldSupportImage: + return m.SupportImage() case model.FieldContextLimit: return m.ContextLimit() case model.FieldOutputLimit: @@ -13815,6 +13857,8 @@ func (m *ModelMutation) OldField(ctx context.Context, name string) (ent.Value, e return m.OldWeight(ctx) case model.FieldThinkingEnabled: return m.OldThinkingEnabled(ctx) + case model.FieldSupportImage: + return m.OldSupportImage(ctx) case model.FieldContextLimit: return m.OldContextLimit(ctx) case model.FieldOutputLimit: @@ -13915,6 +13959,13 @@ func (m *ModelMutation) SetField(name string, value ent.Value) error { } m.SetThinkingEnabled(v) return nil + case model.FieldSupportImage: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSupportImage(v) + return nil case model.FieldContextLimit: v, ok := value.(int) if !ok { @@ -14142,6 +14193,9 @@ func (m *ModelMutation) ResetField(name string) error { case model.FieldThinkingEnabled: m.ResetThinkingEnabled() return nil + case model.FieldSupportImage: + m.ResetSupportImage() + return nil case model.FieldContextLimit: m.ResetContextLimit() return nil diff --git a/backend/db/runtime/runtime.go b/backend/db/runtime/runtime.go index 3dc92bd9..8a5cea42 100644 --- a/backend/db/runtime/runtime.go +++ b/backend/db/runtime/runtime.go @@ -393,20 +393,24 @@ func init() { modelDescThinkingEnabled := modelFields[10].Descriptor() // model.DefaultThinkingEnabled holds the default value on creation for the thinking_enabled field. model.DefaultThinkingEnabled = modelDescThinkingEnabled.Default.(bool) + // modelDescSupportImage is the schema descriptor for support_image field. + modelDescSupportImage := modelFields[11].Descriptor() + // model.DefaultSupportImage holds the default value on creation for the support_image field. + model.DefaultSupportImage = modelDescSupportImage.Default.(bool) // modelDescContextLimit is the schema descriptor for context_limit field. - modelDescContextLimit := modelFields[11].Descriptor() + modelDescContextLimit := modelFields[12].Descriptor() // model.DefaultContextLimit holds the default value on creation for the context_limit field. model.DefaultContextLimit = modelDescContextLimit.Default.(int) // modelDescOutputLimit is the schema descriptor for output_limit field. - modelDescOutputLimit := modelFields[12].Descriptor() + modelDescOutputLimit := modelFields[13].Descriptor() // model.DefaultOutputLimit holds the default value on creation for the output_limit field. model.DefaultOutputLimit = modelDescOutputLimit.Default.(int) // modelDescCreatedAt is the schema descriptor for created_at field. - modelDescCreatedAt := modelFields[16].Descriptor() + modelDescCreatedAt := modelFields[17].Descriptor() // model.DefaultCreatedAt holds the default value on creation for the created_at field. model.DefaultCreatedAt = modelDescCreatedAt.Default.(func() time.Time) // modelDescUpdatedAt is the schema descriptor for updated_at field. - modelDescUpdatedAt := modelFields[17].Descriptor() + modelDescUpdatedAt := modelFields[18].Descriptor() // model.DefaultUpdatedAt holds the default value on creation for the updated_at field. model.DefaultUpdatedAt = modelDescUpdatedAt.Default.(func() time.Time) // model.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. diff --git a/backend/domain/model.go b/backend/domain/model.go index ac0e0312..6fba97fb 100644 --- a/backend/domain/model.go +++ b/backend/domain/model.go @@ -52,6 +52,7 @@ type Model struct { LastCheckSuccess bool `json:"last_check_success"` LastCheckError string `json:"last_check_error"` ThinkingEnabled bool `json:"thinking_enabled"` + SupportImage bool `json:"support_image"` ContextLimit int `json:"context_limit"` OutputLimit int `json:"output_limit"` } @@ -73,6 +74,7 @@ func (m *Model) From(src *db.Model) *Model { m.LastCheckSuccess = src.LastCheckSuccess m.LastCheckError = src.LastCheckError m.ThinkingEnabled = src.ThinkingEnabled + m.SupportImage = src.SupportImage m.ContextLimit = src.ContextLimit m.OutputLimit = src.OutputLimit m.CreatedAt = src.CreatedAt.Unix() @@ -142,6 +144,7 @@ type ModelBrief struct { LastCheckSuccess bool `json:"last_check_success"` LastCheckError string `json:"last_check_error"` ThinkingEnabled bool `json:"thinking_enabled"` + SupportImage bool `json:"support_image"` ContextLimit int `json:"context_limit"` OutputLimit int `json:"output_limit"` } @@ -167,6 +170,7 @@ func (m *ModelBrief) From(src *db.Model) *ModelBrief { m.LastCheckSuccess = full.LastCheckSuccess m.LastCheckError = full.LastCheckError m.ThinkingEnabled = full.ThinkingEnabled + m.SupportImage = full.SupportImage m.ContextLimit = full.ContextLimit m.OutputLimit = full.OutputLimit return m @@ -198,6 +202,7 @@ type CreateModelReq struct { IsDefault bool `json:"is_default"` InterfaceType consts.InterfaceType `json:"interface_type" validate:"required,oneof=openai_chat openai_responses anthropic"` ThinkingEnabled *bool `json:"thinking_enabled"` + SupportImage *bool `json:"support_image"` ContextLimit *int `json:"context_limit"` OutputLimit *int `json:"output_limit"` } @@ -244,6 +249,7 @@ type UpdateModelReq struct { IsDefault *bool `json:"is_default,omitempty"` InterfaceType *consts.InterfaceType `json:"interface_type,omitempty" validate:"omitempty,oneof=openai_chat openai_responses anthropic"` ThinkingEnabled *bool `json:"thinking_enabled,omitempty"` + SupportImage *bool `json:"support_image,omitempty"` ContextLimit *int `json:"context_limit,omitempty"` OutputLimit *int `json:"output_limit,omitempty"` } diff --git a/backend/domain/team_model.go b/backend/domain/team_model.go index 832b80a8..2c8bbc96 100644 --- a/backend/domain/team_model.go +++ b/backend/domain/team_model.go @@ -46,6 +46,7 @@ type TeamModel struct { LastCheckAt int64 `json:"last_check_at"` LastCheckSuccess bool `json:"last_check_success"` LastCheckError string `json:"last_check_error"` + SupportImage bool `json:"support_image"` } // From 从数据库模型转换为领域模型 @@ -66,6 +67,7 @@ func (t *TeamModel) From(src *db.Model) *TeamModel { t.InterfaceType = consts.InterfaceType(src.InterfaceType) t.LastCheckSuccess = src.LastCheckSuccess t.LastCheckError = src.LastCheckError + t.SupportImage = src.SupportImage t.CreatedAt = src.CreatedAt.Unix() t.UpdatedAt = src.UpdatedAt.Unix() t.LastCheckAt = src.LastCheckAt.Unix() @@ -82,6 +84,7 @@ type AddTeamModelReq struct { Temperature float64 `json:"temperature"` GroupIDs []uuid.UUID `json:"group_ids" validate:"required"` InterfaceType consts.InterfaceType `json:"interface_type" validate:"required,oneof=openai_chat openai_responses anthropic"` + SupportImage *bool `json:"support_image"` } // ListTeamModelsResp 获取团队模型配置列表响应 @@ -100,6 +103,7 @@ type UpdateTeamModelReq struct { Temperature float64 `json:"temperature" validate:"omitempty"` GroupIDs []uuid.UUID `json:"group_ids" validate:"omitempty"` InterfaceType consts.InterfaceType `json:"interface_type" validate:"omitempty,oneof=openai_chat openai_responses anthropic"` + SupportImage *bool `json:"support_image,omitempty"` } // DeleteTeamModelReq 删除团队模型配置请求 diff --git a/backend/ent/schema/model.go b/backend/ent/schema/model.go index 1e23f02d..9282edeb 100644 --- a/backend/ent/schema/model.go +++ b/backend/ent/schema/model.go @@ -45,6 +45,7 @@ func (Model) Fields() []ent.Field { field.String("interface_type").Optional(), field.Int("weight").Default(1), field.Bool("thinking_enabled").Default(true), + field.Bool("support_image").Default(false), field.Int("context_limit").Default(200000), field.Int("output_limit").Default(32000), field.Time("last_check_at").Optional(), diff --git a/backend/migration/000011_alter_models_add_support_image.down.sql b/backend/migration/000011_alter_models_add_support_image.down.sql new file mode 100644 index 00000000..fef42c23 --- /dev/null +++ b/backend/migration/000011_alter_models_add_support_image.down.sql @@ -0,0 +1 @@ +ALTER TABLE models DROP COLUMN IF EXISTS support_image; diff --git a/backend/migration/000011_alter_models_add_support_image.up.sql b/backend/migration/000011_alter_models_add_support_image.up.sql new file mode 100644 index 00000000..dac8daf8 --- /dev/null +++ b/backend/migration/000011_alter_models_add_support_image.up.sql @@ -0,0 +1 @@ +ALTER TABLE models ADD COLUMN IF NOT EXISTS support_image BOOLEAN NOT NULL DEFAULT FALSE; diff --git a/backend/pkg/taskflow/types.go b/backend/pkg/taskflow/types.go index e3f4ec35..9ad54040 100644 --- a/backend/pkg/taskflow/types.go +++ b/backend/pkg/taskflow/types.go @@ -156,11 +156,12 @@ const ( // LLMProviderReq 模型提供商配置 type LLMProviderReq struct { - Provider LLMProvider `json:"provider"` - ApiKey string `json:"api_key"` - BaseURL string `json:"base_url"` - Model string `json:"model"` - Temperature *float32 `json:"temperature,omitempty"` + Provider LLMProvider `json:"provider"` + ApiKey string `json:"api_key"` + BaseURL string `json:"base_url"` + Model string `json:"model"` + SupportImage bool `json:"support_image"` + Temperature *float32 `json:"temperature,omitempty"` } // DeleteVirtualMachineReq 删除虚拟机请求 @@ -563,11 +564,12 @@ const ( // LLM 模型配置 type LLM struct { - ApiKey string `json:"api_key"` - BaseURL string `json:"base_url"` - Model string `json:"model"` - ApiType string `json:"api_type,omitempty"` // 接口类型 anthropic | openai - Temperature *float32 `json:"temperature,omitempty"` + ApiKey string `json:"api_key"` + BaseURL string `json:"base_url"` + Model string `json:"model"` + ApiType string `json:"api_type,omitempty"` // 接口类型 anthropic | openai + SupportImage bool `json:"support_image"` + Temperature *float32 `json:"temperature,omitempty"` } // ConfigFile 配置文件 diff --git a/backend/templates/opencode.tmpl b/backend/templates/opencode.tmpl index 022adf23..c9b0c562 100644 --- a/backend/templates/opencode.tmpl +++ b/backend/templates/opencode.tmpl @@ -25,6 +25,13 @@ }, {{- end }} "name": "{{.model}}", +{{- if .support_image }} + "attachment": true, + "modalities": { + "input": ["text", "image"], + "output": ["text"] + }, +{{- end }} "limit": {"context": {{.context_limit}}, "output": {{.output_limit}}} } }