VFP AI 插件开发花絮10:知识库检索
ClearSet Classlib To AnythingLLM.VCX*!* ==========================================*!* AnythingLLMManager 使用示例*!* ==========================================#DEFINE API_KEY [BSVBF9K-ZB948M5-JQWYQSR-X77F0TP]#DEFINE ServerURL [http://127.0.0.1:3001]#DEFINE ExePath [C:\Users\niuji\AppData\Local\Programs\AnythingLLM\AnythingLLM.exe]Local loObj As AnythingLLMManager of AnythingLLM.VCXm.loObj = CreateObject([AnythingLLMManager], API_KEY, .T.)With m.loObj.cServerUrl = ServerURL.cExePath = ExePathEndWith*!* 1. 判断服务是否启动If m.loObj.IsRunning()? [AnythingLLM 已启动]Else? [AnythingLLM 未启动]? [错误码:] + Transform(m.loObj.nLastErrorCode)? [错误消息:] + m.loObj.cLastError?*!* 2. 启动服务If m.loObj.Start(30)? "AnythingLLM 启动成功!"Else? "AnythingLLM 启动失败!"EndIfEndIf*!* 3. 获取工作区的 slug?? "默认工作区 Slug:" + m.loObj.ListAllWorkSpaces()?? "默认工作区名称:" + m.loObj.cWorkSpace? "默认工作区 Slug:" + m.loObj.cWorkspaceSlug?*!* 4. 预热知识库If m.loObj.Warmup()? "知识库预热成功!"Else? "知识库预热失败!"EndIf?*!* 5. 知识库检索m.loJSON = m.loObj.VectorSearch([VFP是什么?], 2)? "片段数:" + Transform(m.lojson.results.length )? "标题:" + m.lojson.results.Item(0).metadata.title? "相似度:" + Transform(m.lojson.results.Item(0).score)? "内容:" + Leftc(STREXTRACT(m.loJSON.results.Item(0).text, '</document_metadata>', '', 1, 2), 300) + "......"?? "标题:" + m.lojson.results.Item(1).metadata.title? "相似度:" + Transform(m.lojson.results.Item(1).score)? "内容:" + Leftc(STREXTRACT(m.loJSON.results.Item(1).text, '</document_metadata>', '', 1, 2), 300) + "......"

夜雨聆风