File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
src/openlayer/lib/integrations Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -574,6 +574,23 @@ def _handle_chain_end(
574574 if run_id not in self .steps :
575575 return
576576
577+ # Check if this is a ConversationalRetrievalChain with source documents
578+ if isinstance (outputs , dict ) and "source_documents" in outputs :
579+ source_docs = outputs ["source_documents" ]
580+ if source_docs :
581+ # Extract content from source documents
582+ context_list = []
583+ for doc in source_docs :
584+ if hasattr (doc , "page_content" ):
585+ context_list .append (doc .page_content )
586+ else :
587+ context_list .append (str (doc ))
588+
589+ if context_list :
590+ current_trace = tracer .get_current_trace ()
591+ if current_trace :
592+ current_trace .update_metadata (context = context_list )
593+
577594 self ._end_step (
578595 run_id = run_id ,
579596 parent_run_id = parent_run_id ,
@@ -754,6 +771,10 @@ def _handle_retriever_end(
754771 else :
755772 doc_contents .append (str (doc ))
756773
774+ current_trace = tracer .get_current_trace ()
775+ if current_trace :
776+ current_trace .update_metadata (context = doc_contents )
777+
757778 self ._end_step (
758779 run_id = run_id ,
759780 parent_run_id = parent_run_id ,
You can’t perform that action at this time.
0 commit comments