Enhance Neo API assistant with improved error handling and message structure
- Added nil check for script context in the call method to prevent potential nil pointer dereference. - Updated the String method in the Content struct to include additional properties (text and props) for better message representation. These changes improve the robustness and maintainability of the Neo API, paving the way for enhanced message handling and assistant functionalities.
This commit is contained in:
parent
228e8cf482
commit
e874e8dfb4
2 changed files with 9 additions and 1 deletions
|
|
@ -221,7 +221,9 @@ func (ast *Assistant) call(ctx context.Context, method string, context chatctx.C
|
|||
// Wait for either context cancellation or method completion
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
scriptCtx.Close() // Force close the script context
|
||||
if scriptCtx != nil {
|
||||
scriptCtx.Close() // Force close the script context
|
||||
}
|
||||
return nil, ctx.Err()
|
||||
case <-done:
|
||||
return result, callErr
|
||||
|
|
|
|||
|
|
@ -52,6 +52,12 @@ func (c *Content) String() string {
|
|||
data := map[string]interface{}{
|
||||
"id": c.ID,
|
||||
"type": "function",
|
||||
"text": c.Name,
|
||||
"props": map[string]interface{}{
|
||||
"id": c.ID,
|
||||
"name": c.Name,
|
||||
"arguments": arguments,
|
||||
},
|
||||
"function": map[string]interface{}{
|
||||
"name": c.Name,
|
||||
"arguments": arguments,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue