Skip to content

Commit

Permalink
Merge pull request #836 from YaoApp/revert-835-revert-834-main
Browse files Browse the repository at this point in the history
Revert "Revert "Add RAG and Version support to Assistant context and …
  • Loading branch information
trheyi authored Jan 26, 2025
2 parents bec72b2 + 069105d commit 68d0f26
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion neo/assistant/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func (ast *Assistant) Execute(c *gin.Context, ctx chatctx.Context, input string,
contents := chatMessage.NewContents()
options = ast.withOptions(options)

// Add RAG and Version support
ctx.RAG = rag != nil
ctx.Version = ast.vision

// Run init hook
res, err := ast.HookInit(c, ctx, messages, options, contents)
if err != nil {
Expand Down Expand Up @@ -370,14 +374,15 @@ func (ast *Assistant) withOptions(options map[string]interface{}) map[string]int
options = map[string]interface{}{}
}

// Add Custom Options
if ast.Options != nil {
for key, value := range ast.Options {
options[key] = value
}
}

// Add functions
if ast.Functions != nil {
if ast.Functions != nil && len(ast.Functions) > 0 {
options["tools"] = ast.Functions
if options["tool_choice"] == nil {
options["tool_choice"] = "auto"
Expand Down
2 changes: 1 addition & 1 deletion neo/assistant/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (ast *Assistant) HookInit(c *gin.Context, context chatctx.Context, input []
ctx, cancel := ast.createTimeoutContext(c)
defer cancel()

v, err := ast.call(ctx, "Init", c, contents, context, input)
v, err := ast.call(ctx, "Init", c, contents, context, input, options)
if err != nil {
if err.Error() == HookErrorMethodNotFound {
return nil, nil
Expand Down
6 changes: 5 additions & 1 deletion neo/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Context struct {
Config map[string]interface{} `json:"config,omitempty"`
Signal interface{} `json:"signal,omitempty"`
Upload *FileUpload `json:"upload,omitempty"`
Version bool `json:"version,omitempty"` // Version support
RAG bool `json:"rag,omitempty"` // RAG support
}

// Field the context field
Expand Down Expand Up @@ -84,7 +86,9 @@ func WithTimeout(parent Context, timeout time.Duration) (Context, context.Cancel
// Map the context to a map
func (ctx *Context) Map() map[string]interface{} {
data := map[string]interface{}{
"sid": ctx.Sid,
"sid": ctx.Sid,
"rag": ctx.RAG,
"version": ctx.Version,
}

if ctx.ChatID != "" {
Expand Down

0 comments on commit 68d0f26

Please sign in to comment.