|
25 | 25 |
|
26 | 26 | import os
|
27 | 27 | from azure.ai.projects import AIProjectClient
|
28 |
| -from azure.ai.agents.models import FileSearchTool, ListSortOrder, VectorStoreDataSource, VectorStoreDataSourceAssetType |
| 28 | +from azure.ai.agents.models import FileSearchTool, ListSortOrder, VectorStoreDataSource, VectorStoreDataSourceAssetType, \ |
| 29 | + RunStatus |
29 | 30 | from azure.identity import DefaultAzureCredential
|
30 | 31 |
|
31 | 32 | project_client = AIProjectClient(
|
|
37 | 38 | agents_client = project_client.agents
|
38 | 39 |
|
39 | 40 | # [START upload_file_and_create_agent_with_file_search]
|
40 |
| - # We will upload the local file to Azure and will use it for vector store creation. |
41 |
| - asset_uri = os.environ["AZURE_BLOB_URI"] |
42 |
| - |
43 |
| - # Create a vector store with no file and wait for it to be processed |
| 41 | + # If provided, we will upload the local file to Azure and will use it for vector store creation. |
| 42 | + # Otherwise, we'll use a previously created dataset reference |
| 43 | + if "AZURE_BLOB_URI" in os.environ: |
| 44 | + asset_uri = os.environ["AZURE_BLOB_URI"] |
| 45 | + else: |
| 46 | + dataset_name = os.environ["AZURE_DATASET_NAME"] |
| 47 | + dataset_version = os.environ["AZURE_DATASET_VERSION"] |
| 48 | + dataset = project_client.datasets.get(name=dataset_name, version=dataset_version) |
| 49 | + asset_uri = dataset.id |
| 50 | + |
| 51 | + # Create a vector store and wait for it to be processed |
44 | 52 | ds = VectorStoreDataSource(asset_identifier=asset_uri, asset_type=VectorStoreDataSourceAssetType.URI_ASSET)
|
45 | 53 | vector_store = agents_client.vector_stores.create_and_poll(data_sources=[ds], name="sample_vector_store")
|
46 | 54 | print(f"Created vector store, vector store ID: {vector_store.id}")
|
|
63 | 71 | print(f"Created thread, thread ID: {thread.id}")
|
64 | 72 |
|
65 | 73 | message = agents_client.messages.create(
|
66 |
| - thread_id=thread.id, role="user", content="What feature does Smart Eyewear offer?" |
| 74 | + thread_id=thread.id, role="user", content="What is the content of the files you have access to?" |
67 | 75 | )
|
68 | 76 | print(f"Created message, message ID: {message.id}")
|
69 | 77 |
|
70 | 78 | run = agents_client.runs.create_and_process(thread_id=thread.id, agent_id=agent.id)
|
71 | 79 | print(f"Created run, run ID: {run.id}")
|
72 | 80 |
|
| 81 | + if run.status == RunStatus.FAILED: |
| 82 | + print(f"Run failed with: |{run.last_error}|") |
| 83 | + |
73 | 84 | agents_client.vector_stores.delete(vector_store.id)
|
74 | 85 | print("Deleted vector store")
|
75 | 86 |
|
|
0 commit comments