azure-ai-projects 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- azure_ai_projects-1.0.0/AGENTS_MIGRATION_GUIDE.md +519 -0
- azure_ai_projects-1.0.0/CHANGELOG.md +248 -0
- azure_ai_projects-1.0.0/LICENSE +21 -0
- azure_ai_projects-1.0.0/MANIFEST.in +7 -0
- azure_ai_projects-1.0.0/PKG-INFO +506 -0
- azure_ai_projects-1.0.0/README.md +477 -0
- azure_ai_projects-1.0.0/azure/__init__.py +1 -0
- azure_ai_projects-1.0.0/azure/ai/__init__.py +1 -0
- azure_ai_projects-1.0.0/azure/ai/projects/__init__.py +32 -0
- azure_ai_projects-1.0.0/azure/ai/projects/_client.py +116 -0
- azure_ai_projects-1.0.0/azure/ai/projects/_configuration.py +69 -0
- azure_ai_projects-1.0.0/azure/ai/projects/_model_base.py +1232 -0
- azure_ai_projects-1.0.0/azure/ai/projects/_patch.py +285 -0
- azure_ai_projects-1.0.0/azure/ai/projects/_serialization.py +2032 -0
- azure_ai_projects-1.0.0/azure/ai/projects/_utils/__init__.py +6 -0
- azure_ai_projects-1.0.0/azure/ai/projects/_utils/model_base.py +1232 -0
- azure_ai_projects-1.0.0/azure/ai/projects/_utils/serialization.py +2032 -0
- azure_ai_projects-1.0.0/azure/ai/projects/_validation.py +50 -0
- azure_ai_projects-1.0.0/azure/ai/projects/_vendor.py +50 -0
- azure_ai_projects-1.0.0/azure/ai/projects/_version.py +9 -0
- azure_ai_projects-1.0.0/azure/ai/projects/aio/__init__.py +29 -0
- azure_ai_projects-1.0.0/azure/ai/projects/aio/_client.py +118 -0
- azure_ai_projects-1.0.0/azure/ai/projects/aio/_configuration.py +69 -0
- azure_ai_projects-1.0.0/azure/ai/projects/aio/_patch.py +248 -0
- azure_ai_projects-1.0.0/azure/ai/projects/aio/_vendor.py +40 -0
- azure_ai_projects-1.0.0/azure/ai/projects/aio/operations/__init__.py +31 -0
- azure_ai_projects-1.0.0/azure/ai/projects/aio/operations/_operations.py +1619 -0
- azure_ai_projects-1.0.0/azure/ai/projects/aio/operations/_patch.py +28 -0
- azure_ai_projects-1.0.0/azure/ai/projects/aio/operations/_patch_connections_async.py +66 -0
- azure_ai_projects-1.0.0/azure/ai/projects/aio/operations/_patch_datasets_async.py +222 -0
- azure_ai_projects-1.0.0/azure/ai/projects/aio/operations/_patch_telemetry_async.py +74 -0
- azure_ai_projects-1.0.0/azure/ai/projects/models/__init__.py +88 -0
- azure_ai_projects-1.0.0/azure/ai/projects/models/_enums.py +84 -0
- azure_ai_projects-1.0.0/azure/ai/projects/models/_models.py +1040 -0
- azure_ai_projects-1.0.0/azure/ai/projects/models/_patch.py +23 -0
- azure_ai_projects-1.0.0/azure/ai/projects/models/_patch_evaluations.py +47 -0
- azure_ai_projects-1.0.0/azure/ai/projects/operations/__init__.py +31 -0
- azure_ai_projects-1.0.0/azure/ai/projects/operations/_operations.py +2030 -0
- azure_ai_projects-1.0.0/azure/ai/projects/operations/_patch.py +28 -0
- azure_ai_projects-1.0.0/azure/ai/projects/operations/_patch_connections.py +64 -0
- azure_ai_projects-1.0.0/azure/ai/projects/operations/_patch_datasets.py +221 -0
- azure_ai_projects-1.0.0/azure/ai/projects/operations/_patch_telemetry.py +68 -0
- azure_ai_projects-1.0.0/azure/ai/projects/py.typed +1 -0
- azure_ai_projects-1.0.0/azure_ai_projects.egg-info/PKG-INFO +506 -0
- azure_ai_projects-1.0.0/azure_ai_projects.egg-info/SOURCES.txt +95 -0
- azure_ai_projects-1.0.0/azure_ai_projects.egg-info/dependency_links.txt +1 -0
- azure_ai_projects-1.0.0/azure_ai_projects.egg-info/not-zip-safe +1 -0
- azure_ai_projects-1.0.0/azure_ai_projects.egg-info/requires.txt +5 -0
- azure_ai_projects-1.0.0/azure_ai_projects.egg-info/top_level.txt +1 -0
- azure_ai_projects-1.0.0/pyproject.toml +28 -0
- azure_ai_projects-1.0.0/samples/agents/README.md +8 -0
- azure_ai_projects-1.0.0/samples/agents/sample_agents.py +51 -0
- azure_ai_projects-1.0.0/samples/agents/sample_agents_async.py +56 -0
- azure_ai_projects-1.0.0/samples/connections/sample_connections.py +66 -0
- azure_ai_projects-1.0.0/samples/connections/sample_connections_async.py +72 -0
- azure_ai_projects-1.0.0/samples/datasets/sample_datasets.py +94 -0
- azure_ai_projects-1.0.0/samples/datasets/sample_datasets_async.py +102 -0
- azure_ai_projects-1.0.0/samples/datasets/sample_datasets_download.py +87 -0
- azure_ai_projects-1.0.0/samples/deployments/sample_deployments.py +67 -0
- azure_ai_projects-1.0.0/samples/deployments/sample_deployments_async.py +73 -0
- azure_ai_projects-1.0.0/samples/indexes/sample_indexes.py +68 -0
- azure_ai_projects-1.0.0/samples/indexes/sample_indexes_async.py +74 -0
- azure_ai_projects-1.0.0/samples/inference/azure-ai-inference/sample_chat_completions_with_azure_ai_inference_client.py +53 -0
- azure_ai_projects-1.0.0/samples/inference/azure-ai-inference/sample_chat_completions_with_azure_ai_inference_client_and_azure_monitor_tracing.py +70 -0
- azure_ai_projects-1.0.0/samples/inference/azure-ai-inference/sample_chat_completions_with_azure_ai_inference_client_and_console_tracing.py +82 -0
- azure_ai_projects-1.0.0/samples/inference/azure-ai-inference/sample_chat_completions_with_azure_ai_inference_client_async.py +60 -0
- azure_ai_projects-1.0.0/samples/inference/azure-ai-inference/sample_image_embeddings_with_azure_ai_inference_client.py +64 -0
- azure_ai_projects-1.0.0/samples/inference/azure-ai-inference/sample_image_embeddings_with_azure_ai_inference_client_async.py +71 -0
- azure_ai_projects-1.0.0/samples/inference/azure-ai-inference/sample_text_embeddings_with_azure_ai_inference_client.py +55 -0
- azure_ai_projects-1.0.0/samples/inference/azure-ai-inference/sample_text_embeddings_with_azure_ai_inference_client_async.py +65 -0
- azure_ai_projects-1.0.0/samples/inference/azure-openai/sample_chat_completions_with_azure_openai_client.py +76 -0
- azure_ai_projects-1.0.0/samples/inference/azure-openai/sample_chat_completions_with_azure_openai_client_and_azure_monitor_tracing.py +69 -0
- azure_ai_projects-1.0.0/samples/inference/azure-openai/sample_chat_completions_with_azure_openai_client_and_console_tracing.py +81 -0
- azure_ai_projects-1.0.0/samples/inference/azure-openai/sample_chat_completions_with_azure_openai_client_async.py +85 -0
- azure_ai_projects-1.0.0/samples/inference/azure-openai/sample_responses_with_azure_openai_client.py +69 -0
- azure_ai_projects-1.0.0/samples/inference/azure-openai/sample_responses_with_azure_openai_client_async.py +76 -0
- azure_ai_projects-1.0.0/samples/telemetry/sample_telemetry.py +36 -0
- azure_ai_projects-1.0.0/samples/telemetry/sample_telemetry_async.py +45 -0
- azure_ai_projects-1.0.0/setup.cfg +4 -0
- azure_ai_projects-1.0.0/setup.py +77 -0
- azure_ai_projects-1.0.0/tests/conftest.py +110 -0
- azure_ai_projects-1.0.0/tests/samples/test_samples.py +309 -0
- azure_ai_projects-1.0.0/tests/test_agents.py +45 -0
- azure_ai_projects-1.0.0/tests/test_agents_async.py +45 -0
- azure_ai_projects-1.0.0/tests/test_base.py +193 -0
- azure_ai_projects-1.0.0/tests/test_connections.py +64 -0
- azure_ai_projects-1.0.0/tests/test_connections_async.py +64 -0
- azure_ai_projects-1.0.0/tests/test_datasets.py +199 -0
- azure_ai_projects-1.0.0/tests/test_datasets_async.py +200 -0
- azure_ai_projects-1.0.0/tests/test_deployments.py +54 -0
- azure_ai_projects-1.0.0/tests/test_deployments_async.py +54 -0
- azure_ai_projects-1.0.0/tests/test_indexes.py +86 -0
- azure_ai_projects-1.0.0/tests/test_indexes_async.py +86 -0
- azure_ai_projects-1.0.0/tests/test_inference.py +129 -0
- azure_ai_projects-1.0.0/tests/test_inference_async.py +133 -0
- azure_ai_projects-1.0.0/tests/test_telemetry.py +37 -0
- azure_ai_projects-1.0.0/tests/test_telemetry_async.py +38 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
# Agents migration guide from Hub-based projects to Endpoint-based projects
|
|
2
|
+
|
|
3
|
+
This guide describes migration from hub-based to Endpoint-based projects. To create a Endpoint-based project, please use one of the deployment scripts on [foundry samples repository](https://github.com/azure-ai-foundry/foundry-samples/tree/main/samples/microsoft/infrastructure-setup) appropriate for your scenario, also you can use Azure AI Foundry UI. The support of hub-based projects was dropped in `azure-ai-projects` version `1.0.0b11`. In this document, we show the operation implementation of before `1.0.0b11` in **Hub-based** section, followed by code for `azure-ai-projects` version `1.0.0b11` or later in **Endpoint-based**.
|
|
4
|
+
|
|
5
|
+
## Import changes
|
|
6
|
+
|
|
7
|
+
| Hub-based | Endpoint-based |
|
|
8
|
+
|-|-|
|
|
9
|
+
| `azure.ai.projects` | `azure.ai.projects` |
|
|
10
|
+
| `azure.ai.projects.models` | `azure.ai.agents.models` |
|
|
11
|
+
| Agents were moved to a new package. | `azure.ai.agents` |
|
|
12
|
+
|
|
13
|
+
## Class structure changes
|
|
14
|
+
|
|
15
|
+
Agents Operations
|
|
16
|
+
|
|
17
|
+
| Hub-based | Endpoint-based |
|
|
18
|
+
|-|-|
|
|
19
|
+
| `project_client.agents.create_agent` | `project_client.agents.create_agent` |
|
|
20
|
+
| `project_client.agents.list_agents` | `project_client.agents.list_agents` |
|
|
21
|
+
| `project_client.agents.get_agent` | `project_client.agents.get_agent` |
|
|
22
|
+
| `project_client.agents.update_agent` | `project_client.agents.update_agent` |
|
|
23
|
+
| `project_client.agents.delete_agents` | `project_client.agents.delete_agent` |
|
|
24
|
+
| `project_client.agents.create_thread_and_run` | `project_client.agents.create_thread_and_run` |
|
|
25
|
+
| `project_client.agents.enable_auto_function_calls` | `project_client.agents.enable_auto_function_calls` |
|
|
26
|
+
| The new method was added in new SDK version. | `project_client.agents.create_thread_and_process_run` |
|
|
27
|
+
|
|
28
|
+
Threads Operations
|
|
29
|
+
|
|
30
|
+
| Hub-based | Endpoint-based |
|
|
31
|
+
|-|-|
|
|
32
|
+
| `project_client.agents.create_thread` | `project_client.agents.threads.create` |
|
|
33
|
+
| `project_client.agents.get_thread` | `project_client.agents.threads.get` |
|
|
34
|
+
| `project_client.agents.update_thread` | `project_client.agents.threads.update` |
|
|
35
|
+
| `project_client.agents.list_threads` | `project_client.agents.threads.list` |
|
|
36
|
+
| `project_client.agents.delete_thread` | `project_client.agents.threads.delete` |
|
|
37
|
+
|
|
38
|
+
Messages Operations
|
|
39
|
+
|
|
40
|
+
| Hub-based | Endpoint-based |
|
|
41
|
+
|-|-|
|
|
42
|
+
| `project_client.agents.create_message` | `project_client.agents.messages.create` |
|
|
43
|
+
| `project_client.agents.list_messages` | `project_client.agents.messages.list` |
|
|
44
|
+
| `project_client.agents.get_message` | `project_client.agents.messages.get` |
|
|
45
|
+
| `project_client.agents.update_message` | `project_client.agents.messages.update` |
|
|
46
|
+
| `OpenAIPageableListOfThreadMessage.get_last_message_by_role` | `project_client.agents.messages.get_last_message_by_role` |
|
|
47
|
+
| `OpenAIPageableListOfThreadMessage.get_last_text_message_by_role` | `project_client.agents.messages.get_last_message_text_by_role` |
|
|
48
|
+
|
|
49
|
+
Runs Operations
|
|
50
|
+
|
|
51
|
+
| Hub-based | Endpoint-based |
|
|
52
|
+
|-|-|
|
|
53
|
+
| `project_client.agents.create_run` | `project_client.agents.runs.create` |
|
|
54
|
+
| `project_client.agents.get_run` | `project_client.agents.runs.get` |
|
|
55
|
+
| `project_client.agents.list_run` | `project_client.agents.runs.list` |
|
|
56
|
+
| `project_client.agents.update_run` | `project_client.agents.runs.update` |
|
|
57
|
+
| `project_client.agents.create_and_process_run` | `project_client.agents.runs.create_and_process` |
|
|
58
|
+
| `project_client.agents.create_stream` | `project_client.agents.runs.stream` |
|
|
59
|
+
| `project_client.agents.submit_tool_outputs_to_run` | `project_client.agents.runs.submit_tool_outputs` |
|
|
60
|
+
| `project_client.agents.submit_tool_outputs_to_run` | `project_client.agents.runs.submit_tool_outputs_stream` |
|
|
61
|
+
| `project_client.agents.cancel_run` | `project_client.agents.runs.cancel` |
|
|
62
|
+
|
|
63
|
+
Run Steps Operations
|
|
64
|
+
|
|
65
|
+
| Hub-based | Endpoint-based |
|
|
66
|
+
|-|-|
|
|
67
|
+
| `project_client.agents.get_run_step` | `project_client.agents.run_steps.get` |
|
|
68
|
+
| `project_client.agents.list_run_steps` | `project_client.agents.run_steps.list` |
|
|
69
|
+
|
|
70
|
+
Vector Stores Operations
|
|
71
|
+
|
|
72
|
+
| Hub-based | Endpoint-based |
|
|
73
|
+
|-|-|
|
|
74
|
+
| `project_client.agents.create_vector_store_and_poll` | `project_client.agents.vector_stores.create_and_poll |
|
|
75
|
+
| `project_client.agents.create_vector_store` | `project_client.agents.vector_stores.create |
|
|
76
|
+
| `project_client.agents.list_vector_stores` | `project_client.agents.vector_stores.list |
|
|
77
|
+
| `project_client.agents.get_vector_store` | `project_client.agents.vector_stores.get |
|
|
78
|
+
| `project_client.agents.modify_vector_store` | `project_client.agents.vector_stores.modify |
|
|
79
|
+
| `project_client.agents.delete_vector_store` | `project_client.agents.vector_stores.delete |
|
|
80
|
+
|
|
81
|
+
Vector Store Files Operations
|
|
82
|
+
|
|
83
|
+
| Hub-based | Endpoint-based |
|
|
84
|
+
|-|-|
|
|
85
|
+
| `project_client.agents.create_vector_store_file_and_poll` | `project_client.agents.vector_store_files.create_and_poll` |
|
|
86
|
+
| `project_client.agents.list_vector_store_files` | `project_client.agents.vector_store_files.list` |
|
|
87
|
+
| `project_client.agents.create_vector_store_file` | `project_client.agents.vector_store_files.create` |
|
|
88
|
+
| `project_client.agents.get_vector_store_file` | `project_client.agents.vector_store_files.get` |
|
|
89
|
+
| `project_client.agents.delete_vector_store_file` | `project_client.agents.vector_store_files.delete` |
|
|
90
|
+
|
|
91
|
+
Vector Store File Batches Operations
|
|
92
|
+
|
|
93
|
+
| Hub-based | Endpoint-based |
|
|
94
|
+
|-|-|
|
|
95
|
+
| `project_client.agents.create_vector_store_file_and_poll` | `project_client.agents.vector_store_file_batches.create_and_poll`|
|
|
96
|
+
| `project_client.agents.create_vector_store_file_batch` | `project_client.agents.vector_store_file_batches.create`|
|
|
97
|
+
| `project_client.agents.get_vector_store_file_batch` | `project_client.agents.vector_store_file_batches.get`|
|
|
98
|
+
| `project_client.agents.list_vector_store_file_batch_files` | `project_client.agents.vector_store_file_batches.list_files`|
|
|
99
|
+
| `project_client.agents.cancel_vector_store_file_batch` | `project_client.agents.vector_store_file_batches.cancel`|
|
|
100
|
+
|
|
101
|
+
Files Operations
|
|
102
|
+
|
|
103
|
+
| Hub-based | Endpoint-based |
|
|
104
|
+
|-|-|
|
|
105
|
+
| `project_client.agents.upload_file_and_poll` | `project_client.agents.files.upload_and_poll` |
|
|
106
|
+
| `project_client.agents.upload_file` | `project_client.agents.files.upload` |
|
|
107
|
+
| `project_client.agents.save_file` | `project_client.agents.files.save` |
|
|
108
|
+
| `project_client.agents.get_file` | `project_client.agents.files.get` |
|
|
109
|
+
| `project_client.agents.list_files` | `project_client.agents.files.list` |
|
|
110
|
+
| `project_client.agents.delete_file` | `project_client.agents.files.delete` |
|
|
111
|
+
|
|
112
|
+
## API changes
|
|
113
|
+
|
|
114
|
+
1. Create project. The connection string is replaced by the endpoint. The project endpoint URL has the form https://\<your-ai-services-account-name\>.services.ai.azure.com/api/projects/\<your-project-name\>. It can be found in your Azure AI Foundry Project overview page.
|
|
115
|
+
|
|
116
|
+
**Hub-based**
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
project_client = AIProjectClient.from_connection_string(
|
|
120
|
+
credential=DefaultAzureCredential(),
|
|
121
|
+
conn_str=connection_string,
|
|
122
|
+
)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Endpoint-based**
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
project_client = AIProjectClient(endpoint=endpoint, credential=DefaultAzureCredential())
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
2. Crate an agent. In the new versions of SDK, the agent can be created using project client or directly created by using `AgentsClient` constructor. In the code below, `project_client.agents`is an `AgentsClient` instance so `project_client.agents` and `agents_client` can be used interchangeably. For simplicity we will use ` project_client.agents `.
|
|
132
|
+
|
|
133
|
+
**Hub-based**
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
agent = project_client.agents.create_agent(
|
|
137
|
+
model= "gpt-4o",
|
|
138
|
+
name="my-assistant",
|
|
139
|
+
instructions="You are helpful assistant",
|
|
140
|
+
)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Endpoint-based**
|
|
144
|
+
|
|
145
|
+
Agent is instantiated using `AIProjectClient`
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
agent = project_client.agents.create_agent(
|
|
149
|
+
model="gpt-4o",
|
|
150
|
+
name="my-agent",
|
|
151
|
+
instructions="You are helpful agent",
|
|
152
|
+
)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Agent is instantiated using `AgentsClient` constructor:
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from azure.ai.agents import AgentsClient
|
|
159
|
+
|
|
160
|
+
agents_client = AgentsClient(
|
|
161
|
+
endpoint=connection_string,
|
|
162
|
+
credential=DefaultAzureCredential(),
|
|
163
|
+
)
|
|
164
|
+
agent = agents_client.create_agent(
|
|
165
|
+
model="gpt-4o",
|
|
166
|
+
name="my-agent",
|
|
167
|
+
instructions="You are helpful agent",
|
|
168
|
+
)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
3. List agents. New version of SDK allows more convenient ways of listing threads, messages and agents by returning `ItemPaged` and `AsyncItemPaged`. The list of returned items is split by pages, which may be consequently returned to user. Below we will demonstrate this mechanism for agents. The `limit` parameter defines the number of items on the page. This example is also applicable for listing threads, runs, run steps, vector stores, files in vector store, and messages.
|
|
172
|
+
|
|
173
|
+
**Hub-based**
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
has_more = True
|
|
177
|
+
last_id = None
|
|
178
|
+
while has_more:
|
|
179
|
+
agents_list = project_client.agents.list_agents(after=last_id)
|
|
180
|
+
for agent in agents_list.data:
|
|
181
|
+
print(agent.id)
|
|
182
|
+
has_more = agents_list.has_more
|
|
183
|
+
last_id = agents_list.last_id
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Endpoint-based**
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
agents = project_client.agents.list_agents(limit=2)
|
|
190
|
+
# Iterate items by page. Each page will be limited by two items.
|
|
191
|
+
for i, page in enumerate(agents.by_page()):
|
|
192
|
+
print(f"Items on page {i}")
|
|
193
|
+
for one_agent in page:
|
|
194
|
+
print(one_agent.id)
|
|
195
|
+
|
|
196
|
+
# Iterate over all agents. Note, the agent list object needs to be re instantiated, the same object cannot be reused after iteration.
|
|
197
|
+
agents = project_client.agents.list_agents(limit=2)
|
|
198
|
+
for one_agent in agents:
|
|
199
|
+
print(one_agent.id)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
4. Delete agent. In versions azure-ai-projects 1.0.0b11, all deletion operations used to return deletion status, for example, deletion of agent was returning `AgentDeletionStatus`. In 1.0.0b11 and later, these operations do not return a value.
|
|
203
|
+
|
|
204
|
+
**Hub-based**
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
deletion_status = project_client.agents.delete_agent(agent.id)
|
|
208
|
+
print(deletion_status.deleted)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Endpoint-based**
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
project_client.agents.delete_agent(agent.id)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
5. Create a thread.
|
|
218
|
+
|
|
219
|
+
**Hub-based**
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
thread = project_client.agents.create_thread()
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Endpoint-based**
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
thread = project_client.agents.threads.create()
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
6. List threads.
|
|
232
|
+
|
|
233
|
+
**Hub-based**
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
with project_client:
|
|
237
|
+
last_id = None
|
|
238
|
+
has_more = True
|
|
239
|
+
page = 0
|
|
240
|
+
while has_more:
|
|
241
|
+
threads = project_client.agents.list_threads(limit=2, after=last_id)
|
|
242
|
+
print(f"Items on page {page}")
|
|
243
|
+
for thread in threads.data:
|
|
244
|
+
print(thread.id)
|
|
245
|
+
has_more = threads.has_more
|
|
246
|
+
last_id = threads.last_id
|
|
247
|
+
page += 1
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**Endpoint-based**
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
threads = project_client.agents.threads.list(limit=2)
|
|
254
|
+
# Iterate items by page. Each page will be limited by two items.
|
|
255
|
+
for i, page in enumerate(threads.by_page()):
|
|
256
|
+
print(f"Items on page {i}")
|
|
257
|
+
for thread in page:
|
|
258
|
+
print(thread.id)
|
|
259
|
+
|
|
260
|
+
# Iterate over all threads. Note, the thread list object needs to be re-instantiated, the same object cannot be reused after iteration.
|
|
261
|
+
threads = project_client.agents.threads.list(limit=2)
|
|
262
|
+
for thread in threads:
|
|
263
|
+
print(thread.id)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
7. Delete the thread. In previous SDK thread deletion used to return ` ThreadDeletionStatus` object, while in new version it does not return value.
|
|
267
|
+
|
|
268
|
+
**Hub-based**
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
delete_status = project_client.agents.delete_thread(tread_id)
|
|
272
|
+
print(delete_status.deleted)
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
**Endpoint-based**
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
project_client.agents.threads.delete(tread_id)
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
8. Create the message on a thread.
|
|
282
|
+
|
|
283
|
+
**Hub-based**
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
message = project_client.agents.create_message(thread_id=thread.id, role="user", content="The message text.")
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**Endpoint-based**
|
|
290
|
+
|
|
291
|
+
```python
|
|
292
|
+
message = agents_client.messages.create(thread_id=thread.id, role="user", content=" The message text."")
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
9. Create and get the run.
|
|
296
|
+
|
|
297
|
+
**Hub-based**
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
run = project_client.agents.runs.create(thread_id=thread.id, agent_id=agent.id)
|
|
301
|
+
run = project_client.agents.get_run(thread_id=thread.id, run_id=run.id)
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**Endpoint-based**
|
|
305
|
+
|
|
306
|
+
```python
|
|
307
|
+
run = project_client.agents.runs.create(thread_id=thread.id, agent_id=agent.id)
|
|
308
|
+
run = project_client.agents.runs.get(thread_id=thread.id, run_id=run.id)
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
10. List Runs.
|
|
312
|
+
|
|
313
|
+
**Hub-based**
|
|
314
|
+
|
|
315
|
+
```python
|
|
316
|
+
has_more = True
|
|
317
|
+
last_id = None
|
|
318
|
+
while has_more:
|
|
319
|
+
runs_list = project_client.agents.list_runs(thread.id)
|
|
320
|
+
for one_run in runs_list.data:
|
|
321
|
+
print(one_run.id)
|
|
322
|
+
has_more = runs_list.has_more
|
|
323
|
+
last_id = runs_list.last_id
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**Endpoint-based**
|
|
327
|
+
|
|
328
|
+
```python
|
|
329
|
+
runs = project_client.agents.runs.list(thread.id)
|
|
330
|
+
for one_run in runs:
|
|
331
|
+
print(one_run.id)
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
11. List Run steps.
|
|
335
|
+
|
|
336
|
+
**Hub-based**
|
|
337
|
+
|
|
338
|
+
```python
|
|
339
|
+
has_more = True
|
|
340
|
+
last_id = None
|
|
341
|
+
while has_more:
|
|
342
|
+
runs_step_list = project_client.agents.list_run_steps(thread.id, run.id)
|
|
343
|
+
for one_run_step in runs_step_list.data:
|
|
344
|
+
print(one_run_step.id)
|
|
345
|
+
has_more = runs_step_list.has_more
|
|
346
|
+
last_id = runs_step_list.last_id
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
**Endpoint-based**
|
|
350
|
+
|
|
351
|
+
```python
|
|
352
|
+
run_steps = project_client.agents.run_steps.list(thread.id, run.id)
|
|
353
|
+
for one_run_step in run_steps:
|
|
354
|
+
print(one_run_step.id)
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
12. Using streams.
|
|
358
|
+
|
|
359
|
+
**Hub-based**
|
|
360
|
+
|
|
361
|
+
```python
|
|
362
|
+
with project_client.agents.create_stream(thread_id=thread.id, agent_id=agent.id) as stream:
|
|
363
|
+
for event_type, event_data, func_return in stream:
|
|
364
|
+
print(f"Received data.")
|
|
365
|
+
print(f"Streaming receive Event Type: {event_type}")
|
|
366
|
+
print(f"Event Data: {str(event_data)[:100]}...")
|
|
367
|
+
print(f"Event Function return: {func_return}\n")
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
**Endpoint-based**
|
|
371
|
+
|
|
372
|
+
```python
|
|
373
|
+
with project_client.agents.runs.stream(thread_id=thread.id, agent_id=agent.id, event_handler=MyEventHandler()) as stream:
|
|
374
|
+
for event_type, event_data, func_return in stream:
|
|
375
|
+
print(f"Received data.")
|
|
376
|
+
print(f"Streaming receive Event Type: {event_type}")
|
|
377
|
+
print(f"Event Data: {str(event_data)[:100]}...")
|
|
378
|
+
print(f"Event Function return: {func_return}\n")
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
13. List messages.
|
|
382
|
+
|
|
383
|
+
**Hub-based**
|
|
384
|
+
|
|
385
|
+
```python
|
|
386
|
+
messages = project_client.agents.list_messages(thread_id=thread.id)
|
|
387
|
+
# In code below we assume that the number of messages fits one page for brevity.
|
|
388
|
+
for data_point in reversed(messages.data):
|
|
389
|
+
last_message_content = data_point.content[-1]
|
|
390
|
+
if isinstance(last_message_content, MessageTextContent):
|
|
391
|
+
print(f"{data_point.role}: {last_message_content.text.value}")
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
**Endpoint-based**
|
|
395
|
+
|
|
396
|
+
```python
|
|
397
|
+
messages = project_client.agents.messages.list(thread_id=thread.id)
|
|
398
|
+
for msg in messages:
|
|
399
|
+
if msg.text_messages:
|
|
400
|
+
last_text = msg.text_messages[-1]
|
|
401
|
+
print(f"{msg.role}: {last_text.text.value}")
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
14. Create, list and delete files are now handled by file operations, again, delete call in new SDK version does not return a value.
|
|
405
|
+
|
|
406
|
+
**Hub-based**
|
|
407
|
+
|
|
408
|
+
```python
|
|
409
|
+
# Create file
|
|
410
|
+
file = project_client.agents.upload_file_and_poll(file_path="product_info_1.md", purpose=FilePurpose.AGENTS)
|
|
411
|
+
# List and enumerate files
|
|
412
|
+
files = project_client.agents.list_files()
|
|
413
|
+
for one_file in files.data:
|
|
414
|
+
print(one_file.id)
|
|
415
|
+
# Delete file.
|
|
416
|
+
delete_status = project_client.agents.delete_file(file.id)
|
|
417
|
+
print(delete_status.deleted)
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
**Endpoint-based**
|
|
421
|
+
|
|
422
|
+
```python
|
|
423
|
+
# Create file
|
|
424
|
+
file = project_client.agents.files.upload_and_poll(file_path=asset_file_path, purpose=FilePurpose.AGENTS)
|
|
425
|
+
# List and enumerate files
|
|
426
|
+
files = project_client.agents.files.list()
|
|
427
|
+
for one_file in files.data:
|
|
428
|
+
print(one_file.id)
|
|
429
|
+
# Delete file.
|
|
430
|
+
project_client.agents.files.delete(file_id=file.id)
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
15. Create, list vector store files list and delete vector stores.
|
|
434
|
+
|
|
435
|
+
**Hub-based**
|
|
436
|
+
|
|
437
|
+
```python
|
|
438
|
+
# Create a vector store with no file and wait for it to be processed
|
|
439
|
+
vector_store = project_client.agents.create_vector_store_and_poll(file_ids=[file.id], name="sample_vector_store")
|
|
440
|
+
# List vector stores
|
|
441
|
+
has_more = True
|
|
442
|
+
last_id = None
|
|
443
|
+
while has_more:
|
|
444
|
+
vector_store_list = project_client.agents.list_vector_stores(after=last_id)
|
|
445
|
+
for one_vector_store in vector_store_list.data:
|
|
446
|
+
print(one_vector_store.id)
|
|
447
|
+
has_more = vector_store_list.has_more
|
|
448
|
+
last_id = vector_store_list.last_id
|
|
449
|
+
# List files in the vector store.
|
|
450
|
+
has_more = True
|
|
451
|
+
last_id = None
|
|
452
|
+
while has_more:
|
|
453
|
+
vector_store_file_list = project_client.agents.list_vector_store_files(vector_store.id, after=last_id)
|
|
454
|
+
for one_file in vector_store_file_list.data:
|
|
455
|
+
print(one_file.id)
|
|
456
|
+
has_more = vector_store_file_list.has_more
|
|
457
|
+
last_id = vector_store_file_list.last_id
|
|
458
|
+
# Delete file from vector store
|
|
459
|
+
project_client.agents.delete_vector_store_file(vector_store.id, file.id)
|
|
460
|
+
# Delete vector store.
|
|
461
|
+
deletion_status = project_client.agents.delete_vector_store(vector_store.id)
|
|
462
|
+
print(deletion_status.deleted)
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
**Endpoint-based**
|
|
466
|
+
|
|
467
|
+
```python
|
|
468
|
+
# Create a vector store with no file and wait for it to be processed
|
|
469
|
+
vector_store = project_client.agents.vector_stores.create_and_poll(file_ids=[file.id], name="my_vectorstore")
|
|
470
|
+
# List vector stores
|
|
471
|
+
vector_store_list = project_client.agents.vector_stores.list()
|
|
472
|
+
for one_vector_store in vector_store_list:
|
|
473
|
+
print(one_vector_store.id)
|
|
474
|
+
# List files in the vector store.
|
|
475
|
+
vector_store_file_list = project_client.agents.vector_store_files.list(vector_store.id)
|
|
476
|
+
for one_file in vector_store_file_list:
|
|
477
|
+
print(one_file.id)
|
|
478
|
+
# Delete file from vector store
|
|
479
|
+
project_client.agents.vector_store_files.delete(vector_store.id, file.id)
|
|
480
|
+
# Delete vector store.
|
|
481
|
+
project_client.agents.vector_stores.delete(vector_store.id)
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
16. Vector store batch file search.
|
|
485
|
+
|
|
486
|
+
**Hub-based**
|
|
487
|
+
|
|
488
|
+
```python
|
|
489
|
+
# Batch upload files
|
|
490
|
+
vector_store_file_batch = project_client.agents.create_vector_store_file_batch_and_poll(
|
|
491
|
+
vector_store_id=vector_store.id, file_ids=[file.id]
|
|
492
|
+
)
|
|
493
|
+
# List file in the batch
|
|
494
|
+
has_more = True
|
|
495
|
+
last_id = None
|
|
496
|
+
while has_more:
|
|
497
|
+
files = project_client.agents.list_vector_store_file_batch_files(vector_store.id, vector_store_file_batch.id, after=last_id)
|
|
498
|
+
for one_file in files.data:
|
|
499
|
+
print(one_file.id)
|
|
500
|
+
has_more = files.has_more
|
|
501
|
+
last_id = files.last_id
|
|
502
|
+
# Try to cancel batch upload
|
|
503
|
+
vector_store_file_batch = project_client.agents.cancel_vector_store_file_batch(vector_store.id, vector_store_file_batch.id)
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
**Endpoint-based**
|
|
507
|
+
|
|
508
|
+
```python
|
|
509
|
+
# Batch upload files
|
|
510
|
+
vector_store_file_batch = project_client.agents.vector_store_file_batches.create_and_poll(
|
|
511
|
+
vector_store_id=vector_store.id, file_ids=[file.id]
|
|
512
|
+
)
|
|
513
|
+
# List file in the batch
|
|
514
|
+
files = project_client.agents.vector_store_file_batches.list_files(vector_store.id, vector_store_file_batch.id)
|
|
515
|
+
for one_file in files:
|
|
516
|
+
print(one_file.id)
|
|
517
|
+
# Try to cancel batch upload
|
|
518
|
+
project_client.agents.vector_store_file_batches.cancel(vector_store.id, vector_store_file_batch.id)
|
|
519
|
+
```
|