Azure Ai Projects - Microsoft Foundry SDKs — Azure AI Projects - Microsoft Foundry SDKs
v1.0Build AI 应用s using the Azure AI Projects Python SDK (azure-AI-projects). Use when working with Foundry project 命令行工具ents, creating versioned 代理s with Prompt代理Definition, 运行ning evaluations, managing connections/部署ments/data设置s/索引es, or using OpenAI-compatible 命令行工具ents. This is the high-level Foundry SDK - for low-level 代理 operations, use azure-AI-代理s-python 技能.
运行时依赖
安装命令
点击复制技能文档
Azure AI Projects Python SDK (Foundry SDK)
Build AI 应用s on Azure AI Foundry using the azure-AI-projects SDK.
安装ation pip 安装 azure-AI-projects azure-身份
环境 Variables AZURE_AI_PROJECT_端点="https://.服务s.AI.azure.com/API/projects/" AZURE_AI_模型_部署MENT_NAME="gpt-4o-mini"
Authentication 导入 os from azure.身份 导入 DefaultAzure凭证 from azure.AI.projects 导入 AIProject命令行工具ent
凭证 = DefaultAzure凭证() 命令行工具ent = AIProject命令行工具ent( 端点=os.environ["AZURE_AI_PROJECT_端点"], 凭证=凭证, )
命令行工具ent Operations Overview Operation 访问 Purpose 命令行工具ent.代理s .代理s. 代理 CRUD, versions, threads, 运行s 命令行工具ent.connections .connections. 列出/获取 project connections 命令行工具ent.部署ments .部署ments. 列出 模型 部署ments 命令行工具ent.data设置s .data设置s. Data设置 management 命令行工具ent.索引es .索引es. 索引 management 命令行工具ent.evaluations .evaluations. 运行 evaluations 命令行工具ent.red_teams .red_teams.* Red team operations Two 命令行工具ent 应用roaches
- AIProject命令行工具ent (Native Foundry)
命令行工具ent = AIProject命令行工具ent( 端点=os.environ["AZURE_AI_PROJECT_端点"], 凭证=DefaultAzure凭证(), )
# Use Foundry-native operations 代理 = 命令行工具ent.代理s.创建_代理( 模型=os.environ["AZURE_AI_模型_部署MENT_NAME"], name="my-代理", instructions="You are helpful.", )
- OpenAI-Compatible 命令行工具ent
# Use standard OpenAI API 响应 = openAI_命令行工具ent.chat.completions.创建( 模型=os.environ["AZURE_AI_模型_部署MENT_NAME"], messages=[{"角色": "user", "content": "Hello!"}], )
代理 Operations 创建 代理 (Basic) 代理 = 命令行工具ent.代理s.创建_代理( 模型=os.environ["AZURE_AI_模型_部署MENT_NAME"], name="my-代理", instructions="You are a helpful 助手.", )
创建 代理 with 工具s from azure.AI.代理s 导入 Code解释器工具, File搜索工具
代理 = 命令行工具ent.代理s.创建_代理( 模型=os.environ["AZURE_AI_模型_部署MENT_NAME"], name="工具-代理", instructions="You can 执行 code and 搜索 files.", 工具s=[Code解释器工具(), File搜索工具()], )
Versioned 代理s with Prompt代理Definition from azure.AI.projects.模型s 导入 Prompt代理Definition
# 创建 a versioned 代理 代理_version = 命令行工具ent.代理s.创建_version( 代理_name="customer-support-代理", definition=Prompt代理Definition( 模型=os.environ["AZURE_AI_模型_部署MENT_NAME"], instructions="You are a customer support specia列出.", 工具s=[], # 添加 工具s as needed ), version_label="v1.0", )
See references/代理s.md for detAIled 代理 patterns.
工具s Overview 工具 Class Use Case Code 解释器 Code解释器工具 执行 Python, 生成 files File 搜索 File搜索工具 RAG over 上传ed documents Bing Grounding BingGrounding工具 网页 搜索 (requires connection) Azure AI 搜索 AzureAI搜索工具 搜索 your 索引es Function Calling Function工具 Call your Python functions OpenAPI OpenAPI工具 Call REST APIs MCP Mcp工具 模型 上下文 Protocol servers Memory 搜索 Memory搜索工具 搜索 代理 memory stores 分享Point 分享pointGrounding工具 搜索 分享Point content
See references/工具s.md for all 工具 patterns.
Thread and Message Flow # 1. 创建 thread thread = 命令行工具ent.代理s.threads.创建()
# 2. 添加 message 命令行工具ent.代理s.messages.创建( thread_id=thread.id, 角色="user", content="What's the weather like?", )
# 3. 创建 and process 运行 运行 = 命令行工具ent.代理s.运行s.创建_and_process( thread_id=thread.id, 代理_id=代理.id, )
# 4. 获取 响应 if 运行.状态 == "completed": messages = 命令行工具ent.代理s.messages.列出(thread_id=thread.id) for msg in messages: if msg.角色 == "助手": print(msg.content[0].text.value)
Connections # 列出 all connections connections = 命令行工具ent.connections.列出() for conn in connections: print(f"{conn.name}: {conn.connection_type}")
# 获取 specific connection connection = 命令行工具ent.connections.获取(connection_name="my-搜索-connection")
See references/connections.md for connection patterns.
部署ments # 列出 avAIlable 模型 部署ments 部署ments = 命令行工具ent.部署ments.列出() for 部署ment in 部署ments: print(f"{部署ment.name}: {部署ment.模型}")
See references/部署ments.md for 部署ment patterns.
Data设置s and 索引es # 列出 data设置s data设置s = 命令行工具ent.data设置s.列出()
# 列出 索引es 索引es = 命令行工具ent.索引es.列出()
See references/data设置s-索引es.md for data operations.
Evaluation # Using OpenAI 命令行工具ent for evals openAI_命令行工具ent = 命令行工具ent.获取_openAI_命令行工具ent()
# 创建 evaluation with built-in evaluators eval_运行 = openAI_命令行工具ent.evals.运行s.创建( eval_id="my-eval", name="质量-检查", data_source={ "type": "custom", "item_references": [{"item_id": "test-1"}], }, 测试_criteria=[