Add assistant match functionality with RAG and store support
- Implemented `processAssistantMatch` method to handle assistant matching requests - Added support for limit parameter with default and maximum values - Introduced `forceStore` flag to control matching method (RAG or store) - Created placeholder methods `assistantMatchRAG` and `assistantMatchStore` - Enhanced OpenAI message handling to parse error responses - Updated message type handling to include error messages This change adds flexible assistant matching capabilities with initial infrastructure for RAG and store-based matching.
This commit is contained in:
parent
3c38e968f8
commit
f14120c446
2 changed files with 81 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue