Skip to content

Commit d6a6b94

Browse files
authored
修改ragflow返回的引用文件后缀不正确的问题。
1 parent e40afda commit d6a6b94

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

rag_flow_webapi_pipeline_cs.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import requests
1414
import json
1515

16-
#API_KEY: ragflow的apikey
17-
#AGENT_ID: ragflow的agentid
18-
#HOST: ragflow的host 要加http://或https://头。
19-
#PORT: ragflow的port
16+
#API_KEY: ragflow apikey
17+
#AGENT_ID: ragflow agentid
18+
#HOST: ragflow host start with http:// or https://
19+
#PORT: ragflow port
2020
class Pipeline:
2121
class Valves(BaseModel):
2222
API_KEY: str
@@ -113,13 +113,17 @@ def pipe(
113113
filesList=[]
114114
for chunk in json_data['data']['reference']['chunks']:
115115
if chunk['document_id'] not in filesList:
116-
referenceStr=referenceStr+f"\n\n - ["+chunk['document_name']+f"]({self.valves.HOST}:{self.valves.PORT}/document/{chunk['document_id']}?ext=docx&prefix=document)"
117-
filesList.append(chunk['document_id'])
118-
print(f"chunks is :{len(json_data['data']['reference']['chunks'])}")
119-
print(f"chunks is :{json_data['data']['reference']['chunks']}")
116+
filename = chunk['document_name']
117+
parts = filename.split('.')
118+
last_part = parts[-1].strip()
119+
ext= last_part.lower() if last_part else ''
120+
referenceStr=referenceStr+f"\n\n - ["+chunk['document_name']+f"]({self.valves.HOST}:{self.valves.PORT}/document/{chunk['document_id']}?ext={ext}&prefix=document)"
121+
filesList.append(chunk['document_id'])
122+
#print(f"chunks is :{len(json_data['data']['reference']['chunks'])}")
123+
#print(f"chunks is :{json_data['data']['reference']['chunks']}")
120124
yield referenceStr
121125
else:
122-
print(json_data['data'])
126+
#print(json_data['data'])
123127
yield json_data['data']['answer'][step:]
124128
step=len(json_data['data']['answer'])
125129

0 commit comments

Comments
 (0)