Skip to content

Commit 3a1f15e

Browse files
authored
fixed black and remove documentation for file search in blob store through message attachment (Azure#38876)
1 parent 8f3af53 commit 3a1f15e

File tree

5 files changed

+353
-541
lines changed

5 files changed

+353
-541
lines changed

sdk/ai/azure-ai-projects/README.md

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ Here is an example to use `tools` and `tool_resources`:
289289
```python
290290
file_search_tool = FileSearchTool(vector_store_ids=[vector_store.id])
291291

292-
# notices that FileSearchTool as tool and tool_resources must be added or the assistant unable to search the file
292+
# Notices that FileSearchTool as tool and tool_resources must be added or the assistant unable to search the file
293293
agent = project_client.agents.create_agent(
294294
model="gpt-4-1106-preview",
295295
name="my-assistant",
@@ -396,7 +396,7 @@ print(f"Uploaded file, file ID: {file.id}")
396396

397397
code_interpreter = CodeInterpreterTool(file_ids=[file.id])
398398

399-
# create agent with code interpreter tool and tools_resources
399+
# Create agent with code interpreter tool and tools_resources
400400
agent = project_client.agents.create_agent(
401401
model="gpt-4-1106-preview",
402402
name="my-assistant",
@@ -432,6 +432,7 @@ with project_client:
432432
name="my-assistant",
433433
instructions="You are a helpful assistant",
434434
tools=bing.definitions,
435+
headers={"x-ms-enable-preview": "true"},
435436
)
436437
```
437438

@@ -466,6 +467,7 @@ with project_client:
466467
instructions="You are a helpful assistant",
467468
tools=ai_search.definitions,
468469
tool_resources=ai_search.resources,
470+
headers={"x-ms-enable-preview": "true"},
469471
)
470472
```
471473

@@ -510,7 +512,10 @@ toolset = AsyncToolSet()
510512
toolset.add(functions)
511513

512514
agent = await project_client.agents.create_agent(
513-
model="gpt-4-1106-preview", name="my-assistant", instructions="You are a helpful assistant", toolset=toolset
515+
model="gpt-4-1106-preview",
516+
name="my-assistant",
517+
instructions="You are a helpful assistant",
518+
toolset=toolset,
514519
)
515520
```
516521

@@ -572,21 +577,14 @@ auth = OpenApiAnonymousAuthDetails()
572577

573578
# Initialize agent OpenApi tool using the read in OpenAPI spec
574579
openapi = OpenApiTool(
575-
name="get_weather",
576-
spec=openapi_spec,
577-
description="Retrieve weather information for a location",
578-
auth=auth
580+
name="get_weather", spec=openapi_spec, description="Retrieve weather information for a location", auth=auth
579581
)
580582

581583
# Create agent with OpenApi tool and process assistant run
582584
with project_client:
583585
agent = project_client.agents.create_agent(
584-
model="gpt-4o-mini",
585-
name="my-assistant",
586-
instructions="You are a helpful assistant",
587-
tools=openapi.definitions
586+
model="gpt-4o-mini", name="my-assistant", instructions="You are a helpful assistant", tools=openapi.definitions
588587
)
589-
590588
```
591589

592590
<!-- END SNIPPET -->
@@ -670,7 +668,7 @@ Here is an example to pass `CodeInterpreterTool` as tool:
670668
<!-- SNIPPET:sample_agents_with_code_interpreter_file_attachment.create_agent_and_message_with_code_interpreter_file_attachment -->
671669

672670
```python
673-
# notice that CodeInterpreter must be enabled in the agent creation,
671+
# Notice that CodeInterpreter must be enabled in the agent creation,
674672
# otherwise the agent will not be able to see the file attachment for code interpretation
675673
agent = project_client.agents.create_agent(
676674
model="gpt-4-1106-preview",
@@ -683,10 +681,10 @@ print(f"Created agent, agent ID: {agent.id}")
683681
thread = project_client.agents.create_thread()
684682
print(f"Created thread, thread ID: {thread.id}")
685683

686-
# create an attachment
684+
# Create an attachment
687685
attachment = MessageAttachment(file_id=file.id, tools=CodeInterpreterTool().definitions)
688686

689-
# create a message
687+
# Create a message
690688
message = project_client.agents.create_message(
691689
thread_id=thread.id,
692690
role="user",
@@ -697,23 +695,6 @@ message = project_client.agents.create_message(
697695

698696
<!-- END SNIPPET -->
699697

700-
Azure blob storage can be used as a message attachment. In this case `VectorStoreDataSource` have to be used as a data source:
701-
702-
<!-- SNIPPET:sample_agents_vector_store_batch_enterprise_file_search.upload_file_and_create_message_with_code_interpreter -->
703-
704-
```python
705-
# We will upload the local file to Azure and will use it for vector store creation.
706-
_, asset_uri = project_client.upload_file("./product_info_1.md")
707-
ds = VectorStoreDataSource(asset_identifier=asset_uri, asset_type=VectorStoreDataSourceAssetType.URI_ASSET)
708-
709-
# Create a message with the attachment
710-
attachment = MessageAttachment(data_source=ds, tools=code_interpreter.definitions)
711-
message = project_client.agents.create_message(
712-
thread_id=thread.id, role="user", content="What does the attachment say?", attachments=[attachment]
713-
)
714-
```
715-
716-
<!-- END SNIPPET -->
717698

718699
#### Create Run, Run_and_Process, or Stream
719700

@@ -728,9 +709,9 @@ Here is an example of `create_run` and poll until the run is completed:
728709
```python
729710
run = project_client.agents.create_run(thread_id=thread.id, assistant_id=agent.id)
730711

731-
# poll the run as long as run status is queued or in progress
712+
# Poll the run as long as run status is queued or in progress
732713
while run.status in ["queued", "in_progress", "requires_action"]:
733-
# wait for a second
714+
# Wait for a second
734715
time.sleep(1)
735716
run = project_client.agents.get_run(thread_id=thread.id, run_id=run.id)
736717
```

sdk/ai/azure-ai-projects/samples/agents/sample_agents_openapi.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,17 @@
4040

4141
# Initialize agent OpenApi tool using the read in OpenAPI spec
4242
openapi = OpenApiTool(
43-
name="get_weather",
44-
spec=openapi_spec,
45-
description="Retrieve weather information for a location",
46-
auth=auth
43+
name="get_weather", spec=openapi_spec, description="Retrieve weather information for a location", auth=auth
4744
)
4845

4946
# Create agent with OpenApi tool and process assistant run
5047
with project_client:
5148
agent = project_client.agents.create_agent(
52-
model="gpt-4o-mini",
53-
name="my-assistant",
54-
instructions="You are a helpful assistant",
55-
tools=openapi.definitions
49+
model="gpt-4o-mini", name="my-assistant", instructions="You are a helpful assistant", tools=openapi.definitions
5650
)
5751

58-
# [END create_agent_with_openapi]
59-
52+
# [END create_agent_with_openapi]
53+
6054
print(f"Created agent, ID: {agent.id}")
6155

6256
# Create thread for communication

0 commit comments

Comments
 (0)