Merge pull request #954 from trheyi/main

feat: Add support for Vision and Search in Assistant API
This commit is contained in:
Max 2025-05-14 16:03:49 +08:00 committed by GitHub
commit a66bc2c4ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 9 deletions

View file

@ -87,9 +87,10 @@ func (ast *Assistant) execute(c *gin.Context, ctx chatctx.Context, userInput int
}
options := ast.withOptions(userOptions)
// Add RAG and Version support
// Add RAG、Vision and Search support
ctx.RAG = rag != nil
ctx.Version = ast.vision
ctx.Vision = ast.vision
ctx.Search = ast.search && search != nil
// Run init hook
res, err := ast.HookCreate(c, ctx, input, options, contents)

View file

@ -25,6 +25,7 @@ import (
var loaded = NewCache(200) // 200 is the default capacity
var storage store.Store = nil
var rag *RAG = nil
var search *Search = nil
var connectorSettings map[string]ConnectorSetting = map[string]ConnectorSetting{}
var vision *neovision.Vision = nil
var defaultConnector string = "" // default connector

View file

@ -84,6 +84,12 @@ type RAG struct {
Setting RAGSetting
}
// Search the search interface
// @todo: add search engine
type Search struct {
Engine interface{}
}
// RAGSetting the RAG setting
type RAGSetting struct {
IndexPrefix string `json:"index_prefix" yaml:"index_prefix"`
@ -129,6 +135,7 @@ type Assistant struct {
UpdatedAt int64 `json:"updated_at"` // Last update timestamp
openai *api.OpenAI // OpenAI API
vision bool // Whether this assistant supports vision
search bool // Whether this assistant supports search
toolCalls bool // Whether this assistant supports tool_calls
initHook bool // Whether this assistant has an init hook
}

View file

@ -28,10 +28,11 @@ type Context struct {
Retry bool `json:"retry,omitempty"` // Retry mode
RetryTimes uint8 `json:"retry_times,omitempty"` // Retry times
Upload *FileUpload `json:"upload,omitempty"`
Version bool `json:"version,omitempty"` // Version support
RAG bool `json:"rag,omitempty"` // RAG support
Args []interface{} `json:"args,omitempty"` // Arguments for call
SharedSpace plan.Space `json:"-"` // Shared space
Vision bool `json:"vision,omitempty"` // Vision support
Search bool `json:"search,omitempty"` // Search support
RAG bool `json:"rag,omitempty"` // RAG support
Args []interface{} `json:"args,omitempty"` // Arguments for call
SharedSpace plan.Space `json:"-"` // Shared space
}
// Field the context field
@ -181,9 +182,10 @@ func (ctx *Context) Release() {
// Map the context to a map
func (ctx *Context) Map() map[string]interface{} {
data := map[string]interface{}{
"sid": ctx.Sid,
"rag": ctx.RAG,
"version": ctx.Version,
"sid": ctx.Sid,
"rag": ctx.RAG,
"vision": ctx.Vision,
"search": ctx.Search,
}
if ctx.ChatID != "" {