你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
注释
另有一篇 Foundry 项目快速入门可供参考:快速入门:Azure AI Foundry 快速入门(Foundry 项目)。
本快速入门为以集线器为基础的项目设置本地环境,部署模型,并生成简单的可追踪/可评估的聊天脚本。
先决条件
- Azure 订阅。
- 现有中心项目(或 创建一个项目)。 如果没有,请考虑使用 Foundry 项目快速入门。
设置开发环境
- 安装必备组件(Python、Azure CLI、登录名)。
- 安装软件包:
pip install azure-ai-inference azure-identity azure-ai-projects==1.0.0b10
不同的项目类型需要不同的 azure-ai-projects 版本。 将每个项目保留在其自己的独立环境中,以避免冲突。
部署模型
- 门户:登录,打开中心项目。
- 模型目录:选择 gpt-4o-mini。
- 使用此模型 > 接受默认部署名称 > 部署。
- 成功后:在沙盒中打开进行验证。
生成聊天应用
使用示例代码创建 chat.py:
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
project_connection_string = "<your-connection-string-goes-here>"
project = AIProjectClient.from_connection_string(
conn_str=project_connection_string, credential=DefaultAzureCredential()
)
chat = project.inference.get_chat_completions_client()
response = chat.complete(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "You are an AI assistant that speaks like a techno punk rocker from 2350. Be cool but not too cool. Ya dig?",
},
{"role": "user", "content": "Hey, can you help me with my taxes? I'm a freelancer."},
],
)
print(response.choices[0].message.content)
从项目概述页面插入项目连接字符串(复制、替换代码中的占位符)。
运行:
python chat.py
添加提示模板
使用胡须模板添加get_chat_response(请参阅 chat-template.py 示例),然后使用用户/上下文消息调用。
再次运行以查看模板化响应。
清理资源
完成后删除部署或项目以避免费用。