Merge pull request #916 from trheyi/main
fix: Enhance message role handling in Assistant API and object
This commit is contained in:
commit
8ace21a617
2 changed files with 15 additions and 4 deletions
|
|
@ -1086,6 +1086,11 @@ func (ast *Assistant) requestMessages(ctx context.Context, messages []chatMessag
|
|||
|
||||
role := message.Role
|
||||
if role == "" {
|
||||
if os.Getenv("YAO_AGENT_PRINT_REQUEST_MESSAGES") == "true" {
|
||||
raw, _ := jsoniter.MarshalToString(message)
|
||||
color.Red("Request Message Error, role is empty:")
|
||||
fmt.Println(raw)
|
||||
}
|
||||
return nil, fmt.Errorf("role must be string")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -290,6 +290,11 @@ func jsSend(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
|||
return bridge.JsException(info.Context(), err.Error())
|
||||
}
|
||||
|
||||
// Set the role to assistant
|
||||
if msg.Role == "" {
|
||||
msg.Role = "assistant"
|
||||
}
|
||||
|
||||
// Append the message to the contents
|
||||
if saveHistory {
|
||||
msg.AppendTo(global.Contents)
|
||||
|
|
@ -299,6 +304,11 @@ func jsSend(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
|||
|
||||
case map[string]interface{}:
|
||||
msg := message.New().Map(v)
|
||||
if msg.Role == "" {
|
||||
msg.Role = "assistant"
|
||||
}
|
||||
|
||||
// Append the message to the contents
|
||||
if saveHistory {
|
||||
msg.AppendTo(global.Contents)
|
||||
}
|
||||
|
|
@ -332,10 +342,6 @@ func jsReplace(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
|||
}
|
||||
|
||||
replaced, _ := sui.Data(data).Replace(tmpl)
|
||||
if err != nil {
|
||||
return bridge.JsException(info.Context(), err.Error())
|
||||
}
|
||||
|
||||
jsReplaced, err := bridge.JsValue(info.Context(), replaced)
|
||||
if err != nil {
|
||||
return bridge.JsException(info.Context(), err.Error())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue