Merge pull request #837 from trheyi/main

Add assistant match functionality with RAG and store support
This commit is contained in:
Max 2025-01-27 11:55:21 +08:00 committed by GitHub
commit 73d6f6994e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 81 additions and 0 deletions

View file

@ -181,6 +181,15 @@ func NewOpenAI(data []byte) *Message {
msg.Text = message.Choices[0].Delta.Content
}
case strings.Contains(text, `{"error":{`):
var errorMessage openai.ErrorMessage
if err := jsoniter.Unmarshal(data, &errorMessage); err != nil {
msg.Text = err.Error() + "\n" + string(data)
return msg
}
msg.Type = "error"
msg.Text = errorMessage.Error.Message
case strings.Contains(text, `[DONE]`):
msg.IsDone = true
@ -209,6 +218,10 @@ func (m *Message) String() string {
switch typ {
case "text":
return m.Text
case "error":
return m.Text
default:
raw, _ := jsoniter.MarshalToString(map[string]interface{}{"type": m.Type, "props": m.Props})
return raw

View file

@ -27,6 +27,7 @@ func init() {
"assistant.delete": processAssistantDelete,
"assistant.search": processAssistantSearch,
"assistant.find": processAssistantFind,
"assistant.match": processAssistantMatch, // Match assistant by content and params
})
}
@ -110,6 +111,73 @@ func processAssistantDelete(process *process.Process) interface{} {
return gin.H{"message": "ok"}
}
// processAssistantMatch process the assistant match request
func processAssistantMatch(process *process.Process) interface{} {
process.ValidateArgNums(1)
content := process.Args[0]
params := map[string]interface{}{}
if len(process.Args) > 1 {
params = process.ArgsMap(1)
}
// Limit default to 20
if _, has := params["limit"]; !has {
params["limit"] = 20
}
// Max limit to 100
if limit, has := params["limit"]; has {
switch v := limit.(type) {
case int:
if v > 100 {
params["limit"] = 100
}
case string:
limitInt, err := strconv.Atoi(v)
if err != nil {
exception.New("Invalid limit type: %T", 500, limit).Throw()
}
params["limit"] = limitInt
if limitInt > 100 {
params["limit"] = 100
}
default:
exception.New("Invalid limit type: %T", 500, limit).Throw()
}
}
// Force Using sotre
forceStore := false
if store, has := params["store"]; has {
switch v := store.(type) {
case bool:
forceStore = v
case int:
forceStore = v == 1
case string:
forceStore = v == "true" || v == "1"
}
}
// Rag Support match using RAG
if Neo.RAG != nil && !forceStore {
return assistantMatchRAG(content, params)
}
// Match using Store
return assistantMatchStore(content, params)
}
func assistantMatchRAG(content interface{}, params map[string]interface{}) interface{} {
return nil
}
func assistantMatchStore(content interface{}, params map[string]interface{}) interface{} {
return nil
}
// processAssistantSearch process the assistant search request
func processAssistantSearch(process *process.Process) interface{} {
params := process.ArgsMap(0)