28
28
VectorStoreDataSource ,
29
29
VectorStoreDataSourceAssetType ,
30
30
ListSortOrder ,
31
- MessageTextContent ,
32
31
)
33
32
from azure .identity .aio import DefaultAzureCredential
34
33
@@ -47,6 +46,10 @@ async def main():
47
46
ds = VectorStoreDataSource (asset_identifier = asset_uri , asset_type = VectorStoreDataSourceAssetType .URI_ASSET )
48
47
vector_store = await agents_client .vector_stores .create_and_poll (data_sources = [ds ], name = "sample_vector_store" )
49
48
print (f"Created vector store, vector store ID: { vector_store .id } " )
49
+ vector_store_files = {}
50
+ async for fle in agents_client .vector_store_files .list (vector_store .id ):
51
+ uploaded_file = await agents_client .files .get (fle .id )
52
+ vector_store_files [fle .id ] = uploaded_file .filename
50
53
51
54
# Create a file search tool
52
55
file_search_tool = FileSearchTool (vector_store_ids = [vector_store .id ])
@@ -80,9 +83,16 @@ async def main():
80
83
81
84
messages = agents_client .messages .list (thread_id = thread .id , order = ListSortOrder .ASCENDING )
82
85
async for msg in messages :
83
- last_part = msg .content [- 1 ]
84
- if isinstance (last_part , MessageTextContent ):
85
- print (f"{ msg .role } : { last_part .text .value } " )
86
+ if msg .text_messages :
87
+ last_text = msg .text_messages [- 1 ].text .value
88
+ for annotation in msg .text_messages [- 1 ].text .annotations :
89
+
90
+ citation = (
91
+ vector_store_files .get (
92
+ annotation .file_citation .file_id , annotation .file_citation .file_id )
93
+ )
94
+ last_text = last_text .replace (annotation .text , f" [{ citation } ]" )
95
+ print (f"{ msg .role } : { last_text } " )
86
96
87
97
88
98
if __name__ == "__main__" :
0 commit comments