feat: Refactor template handling and brand management
- Removed schema_json from article templates and related queries. - Updated brand service to include website field in requests and responses. - Simplified template wizard view by eliminating unused schema fields and related logic. - Added tests for ark text format handling. - Created migrations for dropping schema_json and adding website to brands.
This commit is contained in:
@@ -132,31 +132,7 @@ func (c *arkClient) Generate(ctx context.Context, req GenerateRequest, onDelta f
|
||||
},
|
||||
}
|
||||
|
||||
var textFormat *responses.ResponsesText
|
||||
if req.ResponseFormat != nil {
|
||||
format := &responses.TextFormat{
|
||||
Name: strings.TrimSpace(req.ResponseFormat.Name),
|
||||
}
|
||||
switch req.ResponseFormat.Type {
|
||||
case ResponseFormatTypeJSONSchema:
|
||||
format.Type = responses.TextType_json_schema
|
||||
case ResponseFormatTypeJSONObject:
|
||||
format.Type = responses.TextType_json_object
|
||||
default:
|
||||
format.Type = responses.TextType_text
|
||||
}
|
||||
if description := strings.TrimSpace(req.ResponseFormat.Description); description != "" {
|
||||
format.Description = &description
|
||||
}
|
||||
if len(req.ResponseFormat.SchemaJSON) > 0 {
|
||||
format.Schema = &responses.Bytes{Value: req.ResponseFormat.SchemaJSON}
|
||||
}
|
||||
if req.ResponseFormat.Strict {
|
||||
strict := true
|
||||
format.Strict = &strict
|
||||
}
|
||||
textFormat = &responses.ResponsesText{Format: format}
|
||||
}
|
||||
textFormat := buildArkTextFormat(req.ResponseFormat)
|
||||
|
||||
var tools []*responses.ResponsesTool
|
||||
if req.WebSearch != nil && req.WebSearch.Enabled {
|
||||
@@ -260,6 +236,38 @@ func (c *arkClient) Generate(ctx context.Context, req GenerateRequest, onDelta f
|
||||
}, nil
|
||||
}
|
||||
|
||||
func buildArkTextFormat(format *ResponseFormat) *responses.ResponsesText {
|
||||
if format == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
textFormat := &responses.TextFormat{}
|
||||
switch format.Type {
|
||||
case ResponseFormatTypeJSONSchema:
|
||||
textFormat.Type = responses.TextType_json_schema
|
||||
if name := strings.TrimSpace(format.Name); name != "" {
|
||||
textFormat.Name = name
|
||||
}
|
||||
if description := strings.TrimSpace(format.Description); description != "" {
|
||||
textFormat.Description = &description
|
||||
}
|
||||
if len(format.SchemaJSON) > 0 {
|
||||
textFormat.Schema = &responses.Bytes{Value: format.SchemaJSON}
|
||||
}
|
||||
if format.Strict {
|
||||
strict := true
|
||||
textFormat.Strict = &strict
|
||||
}
|
||||
case ResponseFormatTypeJSONObject:
|
||||
// Ark only accepts the type discriminator for json_object.
|
||||
textFormat.Type = responses.TextType_json_object
|
||||
default:
|
||||
textFormat.Type = responses.TextType_text
|
||||
}
|
||||
|
||||
return &responses.ResponsesText{Format: textFormat}
|
||||
}
|
||||
|
||||
func resolveArkReasoning(value string) *responses.ResponsesReasoning {
|
||||
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||
case "":
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package llm
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/volcengine/volcengine-go-sdk/service/arkruntime/model/responses"
|
||||
)
|
||||
|
||||
func TestBuildArkTextFormatJSONObjectDropsSchemaFields(t *testing.T) {
|
||||
text := buildArkTextFormat(&ResponseFormat{
|
||||
Type: ResponseFormatTypeJSONObject,
|
||||
Name: "article_outline",
|
||||
Description: "outline object",
|
||||
SchemaJSON: []byte(`{"type":"object"}`),
|
||||
Strict: true,
|
||||
})
|
||||
|
||||
if text == nil || text.Format == nil {
|
||||
t.Fatal("buildArkTextFormat() returned nil")
|
||||
}
|
||||
if got := text.Format.Type; got != responses.TextType_json_object {
|
||||
t.Fatalf("buildArkTextFormat() type = %v, want %v", got, responses.TextType_json_object)
|
||||
}
|
||||
if text.Format.Name != "" {
|
||||
t.Fatalf("buildArkTextFormat() name = %q, want empty for json_object", text.Format.Name)
|
||||
}
|
||||
if text.Format.Description != nil {
|
||||
t.Fatalf("buildArkTextFormat() description = %v, want nil for json_object", *text.Format.Description)
|
||||
}
|
||||
if text.Format.Schema != nil {
|
||||
t.Fatalf("buildArkTextFormat() schema = %v, want nil for json_object", text.Format.Schema)
|
||||
}
|
||||
if text.Format.Strict != nil {
|
||||
t.Fatalf("buildArkTextFormat() strict = %v, want nil for json_object", *text.Format.Strict)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildArkTextFormatJSONSchemaKeepsSchemaFields(t *testing.T) {
|
||||
text := buildArkTextFormat(&ResponseFormat{
|
||||
Type: ResponseFormatTypeJSONSchema,
|
||||
Name: "article_outline",
|
||||
Description: "outline object",
|
||||
SchemaJSON: []byte(`{"type":"object"}`),
|
||||
Strict: true,
|
||||
})
|
||||
|
||||
if text == nil || text.Format == nil {
|
||||
t.Fatal("buildArkTextFormat() returned nil")
|
||||
}
|
||||
if got := text.Format.Type; got != responses.TextType_json_schema {
|
||||
t.Fatalf("buildArkTextFormat() type = %v, want %v", got, responses.TextType_json_schema)
|
||||
}
|
||||
if text.Format.Name != "article_outline" {
|
||||
t.Fatalf("buildArkTextFormat() name = %q, want article_outline", text.Format.Name)
|
||||
}
|
||||
if text.Format.Description == nil || *text.Format.Description != "outline object" {
|
||||
t.Fatalf("buildArkTextFormat() description = %v, want outline object", text.Format.Description)
|
||||
}
|
||||
if text.Format.Schema == nil || string(text.Format.Schema.Value) != `{"type":"object"}` {
|
||||
t.Fatalf("buildArkTextFormat() schema = %v, want schema payload", text.Format.Schema)
|
||||
}
|
||||
if text.Format.Strict == nil || !*text.Format.Strict {
|
||||
t.Fatalf("buildArkTextFormat() strict = %v, want true", text.Format.Strict)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user