File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525from vertexai .preview .rag .utils import _gapic_utils
2626from vertexai .preview .rag .utils import resources
2727
28+ from google .protobuf import any_pb2
29+
2830
2931def retrieval_query (
3032 text : str ,
@@ -528,7 +530,20 @@ async def async_retrieve_contexts(
528530 response_lro = await client .async_retrieve_contexts (
529531 request = request , timeout = timeout
530532 )
531- response = await response_lro .result ()
533+ try :
534+ response = await response_lro .result ()
535+ except Exception as e :
536+ if response_lro .done ():
537+ raw_op = response_lro .operation
538+ if raw_op .WhichOneof ("result" ) == "response" :
539+ any_response = raw_op .response
540+ inner_any = any_pb2 .Any ()
541+ if any_response .Unpack (inner_any ):
542+ inner_any .type_url = "type.googleapis.com/google.cloud.aiplatform.v1beta1.RagContexts"
543+ rag_contexts = aiplatform_v1beta1 .RagContexts ()
544+ if inner_any .Unpack (rag_contexts ._pb ):
545+ return aiplatform_v1beta1 .AsyncRetrieveContextsResponse (contexts = rag_contexts )
546+ raise e
532547 except Exception as e :
533548 raise RuntimeError (
534549 "Failed in retrieving contexts asynchronously due to: " , e
You can’t perform that action at this time.
0 commit comments