Refactor Assistant struct to replace Flows with Workflow and update cloning logic
- Replaced the Flows field in the Assistant struct with a Workflow field to better represent the assistant's functionality. - Updated the Clone method to perform a deep copy of the Workflow instead of Flows. - Adjusted related test cases to reflect the changes in the Assistant struct and ensure proper functionality.
This commit is contained in:
parent
1058598be3
commit
b97933e357
3 changed files with 33 additions and 37 deletions
|
|
@ -239,15 +239,11 @@ func (ast *Assistant) Clone() *Assistant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deep copy flows
|
// Deep copy workflow
|
||||||
if ast.Flows != nil {
|
if ast.Workflow != nil {
|
||||||
clone.Flows = make([]map[string]interface{}, len(ast.Flows))
|
clone.Workflow = make(map[string]interface{})
|
||||||
for i, flow := range ast.Flows {
|
for k, v := range ast.Workflow {
|
||||||
cloneFlow := make(map[string]interface{})
|
clone.Workflow[k] = v
|
||||||
for k, v := range flow {
|
|
||||||
cloneFlow[k] = v
|
|
||||||
}
|
|
||||||
clone.Flows[i] = cloneFlow
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ func TestLoad_Clone(t *testing.T) {
|
||||||
Automated: true,
|
Automated: true,
|
||||||
Options: map[string]interface{}{"key": "value"},
|
Options: map[string]interface{}{"key": "value"},
|
||||||
Prompts: []Prompt{{Role: "system", Content: "test"}},
|
Prompts: []Prompt{{Role: "system", Content: "test"}},
|
||||||
Flows: []map[string]interface{}{{"step": "test"}},
|
Workflow: map[string]interface{}{"step": "test"},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone the assistant
|
// Clone the assistant
|
||||||
|
|
@ -218,15 +218,15 @@ func TestLoad_Clone(t *testing.T) {
|
||||||
assert.Equal(t, original.Automated, clone.Automated)
|
assert.Equal(t, original.Automated, clone.Automated)
|
||||||
assert.Equal(t, original.Options, clone.Options)
|
assert.Equal(t, original.Options, clone.Options)
|
||||||
assert.Equal(t, original.Prompts, clone.Prompts)
|
assert.Equal(t, original.Prompts, clone.Prompts)
|
||||||
assert.Equal(t, original.Flows, clone.Flows)
|
assert.Equal(t, original.Workflow, clone.Workflow)
|
||||||
|
|
||||||
// Verify deep copy by modifying original
|
// Verify deep copy by modifying original
|
||||||
original.Tags[0] = "modified"
|
original.Tags[0] = "modified"
|
||||||
original.Options["key"] = "modified"
|
original.Options["key"] = "modified"
|
||||||
original.Flows[0]["step"] = "modified"
|
original.Workflow["step"] = "modified"
|
||||||
assert.NotEqual(t, original.Tags[0], clone.Tags[0])
|
assert.NotEqual(t, original.Tags[0], clone.Tags[0])
|
||||||
assert.NotEqual(t, original.Options["key"], clone.Options["key"])
|
assert.NotEqual(t, original.Options["key"], clone.Options["key"])
|
||||||
assert.NotEqual(t, original.Flows[0]["step"], clone.Flows[0]["step"])
|
assert.NotEqual(t, original.Workflow["step"], clone.Workflow["step"])
|
||||||
|
|
||||||
// Test nil case
|
// Test nil case
|
||||||
var nilAssistant *Assistant
|
var nilAssistant *Assistant
|
||||||
|
|
|
||||||
|
|
@ -122,30 +122,30 @@ type QueryParam struct {
|
||||||
|
|
||||||
// Assistant the assistant
|
// Assistant the assistant
|
||||||
type Assistant struct {
|
type Assistant struct {
|
||||||
ID string `json:"assistant_id"` // Assistant ID
|
ID string `json:"assistant_id"` // Assistant ID
|
||||||
Type string `json:"type,omitempty"` // Assistant Type, default is assistant
|
Type string `json:"type,omitempty"` // Assistant Type, default is assistant
|
||||||
Name string `json:"name,omitempty"` // Assistant Name
|
Name string `json:"name,omitempty"` // Assistant Name
|
||||||
Avatar string `json:"avatar,omitempty"` // Assistant Avatar
|
Avatar string `json:"avatar,omitempty"` // Assistant Avatar
|
||||||
Connector string `json:"connector"` // AI Connector
|
Connector string `json:"connector"` // AI Connector
|
||||||
Path string `json:"path,omitempty"` // Assistant Path
|
Path string `json:"path,omitempty"` // Assistant Path
|
||||||
BuiltIn bool `json:"built_in,omitempty"` // Whether this is a built-in assistant
|
BuiltIn bool `json:"built_in,omitempty"` // Whether this is a built-in assistant
|
||||||
Sort int `json:"sort,omitempty"` // Assistant Sort
|
Sort int `json:"sort,omitempty"` // Assistant Sort
|
||||||
Description string `json:"description,omitempty"` // Assistant Description
|
Description string `json:"description,omitempty"` // Assistant Description
|
||||||
Tags []string `json:"tags,omitempty"` // Assistant Tags
|
Tags []string `json:"tags,omitempty"` // Assistant Tags
|
||||||
Readonly bool `json:"readonly,omitempty"` // Whether this assistant is readonly
|
Readonly bool `json:"readonly,omitempty"` // Whether this assistant is readonly
|
||||||
Mentionable bool `json:"mentionable,omitempty"` // Whether this assistant is mentionable
|
Mentionable bool `json:"mentionable,omitempty"` // Whether this assistant is mentionable
|
||||||
Automated bool `json:"automated,omitempty"` // Whether this assistant is automated
|
Automated bool `json:"automated,omitempty"` // Whether this assistant is automated
|
||||||
Options map[string]interface{} `json:"options,omitempty"` // AI Options
|
Options map[string]interface{} `json:"options,omitempty"` // AI Options
|
||||||
Prompts []Prompt `json:"prompts,omitempty"` // AI Prompts
|
Prompts []Prompt `json:"prompts,omitempty"` // AI Prompts
|
||||||
Tools *ToolCalls `json:"tools,omitempty"` // Assistant Tools
|
Tools *ToolCalls `json:"tools,omitempty"` // Assistant Tools
|
||||||
Flows []map[string]interface{} `json:"flows,omitempty"` // Assistant Flows
|
Workflow map[string]interface{} `json:"workflow,omitempty"` // Assistant Workflow
|
||||||
Placeholder *Placeholder `json:"placeholder,omitempty"` // Assistant Placeholder
|
Placeholder *Placeholder `json:"placeholder,omitempty"` // Assistant Placeholder
|
||||||
Locales i18n.Map `json:"locales,omitempty"` // Assistant Locales
|
Locales i18n.Map `json:"locales,omitempty"` // Assistant Locales
|
||||||
Search *SearchOption `json:"search,omitempty" yaml:"search,omitempty"` // Whether this assistant supports search
|
Search *SearchOption `json:"search,omitempty" yaml:"search,omitempty"` // Whether this assistant supports search
|
||||||
Knowledge *KnowledgeOption `json:"knowledge,omitempty" yaml:"knowledge,omitempty"` // Whether this assistant supports knowledge
|
Knowledge *KnowledgeOption `json:"knowledge,omitempty" yaml:"knowledge,omitempty"` // Whether this assistant supports knowledge
|
||||||
CreatedAt int64 `json:"created_at"` // Creation timestamp
|
CreatedAt int64 `json:"created_at"` // Creation timestamp
|
||||||
UpdatedAt int64 `json:"updated_at"` // Last update timestamp
|
UpdatedAt int64 `json:"updated_at"` // Last update timestamp
|
||||||
Script *v8.Script `json:"-" yaml:"-"` // Assistant Script
|
Script *v8.Script `json:"-" yaml:"-"` // Assistant Script
|
||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
// ===============================
|
// ===============================
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue