Merge pull request #778 from trheyi/main

Refactor Neo execution methods to improve error handling and streamli…
This commit is contained in:
Max 2024-11-06 20:39:37 +08:00 committed by GitHub
commit a599929b85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -348,13 +348,14 @@ func (neo *DSL) write(msg *message.JSON, w io.Writer, ctx command.Context, messa
return nil return nil
} }
res, err := p.WithSID(ctx.Sid).Exec() err = p.WithSID(ctx.Sid).Execute()
if err != nil { if err != nil {
log.Error("Neo custom write error: %s", err.Error()) log.Error("Neo custom write error: %s", err.Error())
msg.Write(w) msg.Write(w)
return nil return nil
} }
defer p.Release()
res := p.Value()
if res == nil { if res == nil {
return fmt.Errorf("Neo custom write return null") return fmt.Errorf("Neo custom write return null")
} }
@ -385,12 +386,14 @@ func (neo *DSL) prepare(ctx command.Context, messages []map[string]interface{})
return prompts return prompts
} }
data, err := p.WithSID(ctx.Sid).Exec() err = p.WithSID(ctx.Sid).Execute()
if err != nil { if err != nil {
color.Red("Neo prepare execute error: %s", err.Error()) color.Red("Neo prepare execute error: %s", err.Error())
return prompts return prompts
} }
defer p.Release()
data := p.Value()
items, ok := data.([]interface{}) items, ok := data.([]interface{})
if !ok { if !ok {
color.Red("Neo prepare response is not array") color.Red("Neo prepare response is not array")
@ -433,10 +436,7 @@ func (neo *DSL) chatMessages(ctx command.Context, content string) ([]map[string]
// Add prepare messages witch is query from vector database // Add prepare messages witch is query from vector database
preparePrompts := neo.prepare(ctx, messages) preparePrompts := neo.prepare(ctx, messages)
if len(preparePrompts) > 0 { if len(preparePrompts) > 0 {
messages = append([]map[string]interface{}{}, neo.prompts()...) messages = preparePrompts
messages = append(messages, preparePrompts...)
messages = append(messages, history...)
messages = append(messages, map[string]interface{}{"role": "user", "content": content, "name": ctx.Sid})
} }
return messages, nil return messages, nil