@@ -133,20 +133,26 @@ def save_knowledge():
133133
134134 # 3. Trigger Parsing (Run)
135135 print ("Triggering parsing..." )
136- run_payload = {"run" : 1 , "progress" : 0 }
137- run_response = requests .put (f"{ full_url } /datasets/{ dataset_id } /documents/{ doc_id } " , headers = headers , json = run_payload )
136+ # Correcting the trigger logic based on RAGFlow API
137+ # POST /api/v1/datasets/{dataset_id}/documents/run
138+ run_payload = {"ids" : [doc_id ], "run" : 1 }
139+ run_response = requests .post (f"{ full_url } /datasets/{ dataset_id } /documents/run" , headers = headers , json = run_payload )
138140
139141 run_status = "Unknown"
140- if run_response .status_code == 200 and run_response .json ().get ("code" ) == 0 :
141- run_status = "Started"
142+ if run_response .status_code == 200 :
143+ res_json = run_response .json ()
144+ if res_json .get ("code" ) == 0 :
145+ run_status = "Started"
146+ else :
147+ run_status = f"Failed ({ res_json .get ('message' )} )"
142148 else :
143- # Try bulk run endpoint fallback
144- bulk_run_payload = {"ids" : [ doc_id ], "run" : 1 }
145- bulk_response = requests .post (f"{ full_url } /datasets/{ dataset_id } /documents/run " , headers = headers , json = bulk_run_payload )
146- if bulk_response .status_code == 200 and bulk_response .json ().get ("code" ) == 0 :
147- run_status = "Started (Bulk )"
149+ # Try fallback to PUT if POST fails (older API versions)
150+ fallback_payload = {"run" : 1 }
151+ fallback_res = requests .put (f"{ full_url } /datasets/{ dataset_id } /documents/{ doc_id } " , headers = headers , json = fallback_payload )
152+ if fallback_res .status_code == 200 and fallback_res .json ().get ("code" ) == 0 :
153+ run_status = "Started (Fallback PUT )"
148154 else :
149- run_status = f"Failed to trigger ( { run_response .status_code } )"
155+ run_status = f"Failed (POST: { run_response . status_code } , PUT: { fallback_res .status_code } )"
150156
151157 # Return details
152158 print (f"\n --- Save Complete ---" )
0 commit comments