- 重构了 rag_controller.go 中的逻辑,使用新的 DocumentHub 结构 - 修改了 encounter.go 中的 Encounter 结构,增加了 explain 标签 - 重写了 rag_websocket.go 中的逻辑,使用新的 DocumentHub 结构 - 新增了 curd_es/encounter_es_curd.go 文件,实现了 Encounter 的 CURD 操作 - 更新了 nlp/func.go 中的 ChatRAG 函数,使用新的 DocumentHub 结构 - 新增了 curd/docs_hub.go 文件,实现了 DocumentHub 的 TopK 方法 - 新增了 utils/data_explain/data_explain_rag.go 文件,实现了结构体到解释字符串的转换
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package test
|
||
|
||
import (
|
||
"fmt"
|
||
"testing"
|
||
"time"
|
||
)
|
||
|
||
// 假设的 EncounterResult 结构体
|
||
type EncounterResult struct {
|
||
Title string
|
||
Content string
|
||
UpdatedAt time.Time
|
||
}
|
||
|
||
// ToString 方法
|
||
func (e EncounterResult) ToString() string {
|
||
return fmt.Sprintf(`路遇笔记标题:%s;路遇笔记内容:%s;最后更新时间:%v`, e.Title, e.Content, e.UpdatedAt)
|
||
}
|
||
|
||
// 测试 EncounterResult 的 ToString 方法
|
||
func TestEncounterResult_ToString(t *testing.T) {
|
||
// 设置一个时间点,用于测试
|
||
testTime := time.Now()
|
||
|
||
// 创建一个 EncounterResult 实例
|
||
testResult := EncounterResult{
|
||
Title: "测试笔记",
|
||
Content: "这是测试笔记的内容",
|
||
UpdatedAt: testTime,
|
||
}
|
||
|
||
// 调用 ToString 方法
|
||
resultString := testResult.ToString()
|
||
|
||
t.Log("resultString:", resultString)
|
||
// 构建期望的结果字符串
|
||
expectedString := fmt.Sprintf(`路遇笔记标题:%s;路遇笔记内容:%s;最后更新时间:%v`, testResult.Title, testResult.Content, testResult.UpdatedAt)
|
||
|
||
// 比较实际结果和期望结果
|
||
if resultString != expectedString {
|
||
t.Errorf("ToString() failed, expected %q, got %q", expectedString, resultString)
|
||
}
|
||
}
|