في هذه البداية السريعة ستبدأ باستخدام النماذج والوكلاء في Foundry.
ستفعل:
- توليد استجابة من نموذج
- إنشاء وكيل مع طلب معرف
- أجر محادثة متعددة الأدوار مع الوكيل
المتطلبات الأساسية
نموذج تم نشره في Microsoft Foundry. إذا لم يكن لديك نموذج، أولا أكمل Quickstart: إعداد موارد Microsoft Foundry.
نصيحة
أو، تجاوز خطوة النشر وجرب نموذجا فوريا (معاينة) بدلا من ذلك. إنشاء مشروع في غرب الولايات المتحدة 3 لاستخدام نماذج الوصول الفوري. لا تحتوي النماذج الفورية على توزيع، لذا استخدم اسم gpt-5-mini النموذج أينما تطلب العينات اسم نشر.
أوقات تشغيل اللغة المطلوبة، الأدوات العالمية، والإضافات تعليمة Visual Studio برمجية كما هو موضح في جهز بيئة التطوير الخاصة بك.
الحصول على التعليمات البرمجية وتعيين القيم الخاصة بك
لا تقرأ عينات Python متغيرات البيئة. في كل ملف، استبدل قيم العنصر النائب هذه:
-
your_project_endpoint: نقطة نهاية المشروع الخاص بك، بالتنسيق https://<resource-name>.services.ai.azure.com/api/projects/<project-name>.
-
your_agent_name: اسم لوكيلك، مثل MyAgent.
تستخدم العينات النشر الذي أنشأته gpt-5-mini في إعداد Microsoft موارد Foundry. إذا قمت بنشر نموذج باسم مختلف، فقم بتحديث اسم النموذج في نموذج التعليمات البرمجية.
تابع المتابعة أدناه أو احصل على الرمز:
لا تقرأ عينات C# متغيرات البيئة. في كل ملف، استبدل قيم العنصر النائب هذه:
-
your_project_endpoint: نقطة نهاية المشروع الخاص بك، بالتنسيق https://<resource-name>.services.ai.azure.com/api/projects/<project-name>.
-
your_agent_name: اسم لوكيلك، مثل MyAgent.
تستخدم العينات النشر الذي أنشأته gpt-5-mini في إعداد Microsoft موارد Foundry. إذا قمت بنشر نموذج باسم مختلف، فقم بتحديث اسم النموذج في نموذج التعليمات البرمجية.
تابع المتابعة أدناه أو احصل على الرمز:
لا تقرأ نماذج TypeScript متغيرات البيئة. في كل ملف، استبدل هذه القيم بنقطة نهاية المشروع واسم عامل مثل MyAgent:
const FOUNDRY_PROJECT_ENDPOINT = "https://<resource-name>.services.ai.azure.com/api/projects/<project-name>";
const FOUNDRY_AGENT_NAME = "MyAgent";
تستخدم العينات النشر الذي أنشأته gpt-5-mini في إعداد Microsoft موارد Foundry. إذا قمت بنشر نموذج باسم مختلف، فقم بتحديث اسم النموذج في نموذج التعليمات البرمجية.
تابع المتابعة أدناه أو احصل على الرمز:
لا تقرأ عينات Java متغيرات البيئة. في كل ملف، استبدل هذه القيم بنقطة نهاية المشروع واسم عامل مثل MyAgent:
String foundryProjectEndpoint = "https://<resource-name>.services.ai.azure.com/api/projects/<project-name>";
String foundryAgentName = "MyAgent";
تستخدم العينات النشر الذي أنشأته gpt-5-mini في إعداد Microsoft موارد Foundry. إذا قمت بنشر نموذج باسم مختلف، فقم بتحديث اسم النموذج في نموذج التعليمات البرمجية.
تابع المتابعة أدناه أو احصل على الرمز:
في كل عنوان URL للطلب، استبدل YOUR-FOUNDRY-RESOURCE-NAME و YOUR-PROJECT-NAME بالقيم من نقطة نهاية المشروع، والتي تحتوي على النموذج https://<resource-name>.services.ai.azure.com/api/projects/<project-name>.
يقرأ طلب الدردشة مع العامل اسم العامل من متغير بيئة:
FOUNDRY_AGENT_NAME=MyAgent
تستخدم العينات النشر الذي أنشأته gpt-5-mini في إعداد Microsoft موارد Foundry. إذا قمت بنشر نموذج باسم مختلف، فقم بتحديث model القيمة في نص الطلب.
تابع المتابعة أدناه أو احصل على الرمز:
لا حاجة لأي كود عند استخدام بوابة Foundry.
تثبيت والتحقق من صحتك
تأكد من تثبيت النسخة الصحيحة من الحزم كما هو موضح هنا.
تثبيت النسخة الحالية من azure-ai-projects. يستخدم هذا الإصدار واجهة برمجة تطبيقات مشاريع Foundry (الجديدة). تصادق العينات باستخدام DefaultAzureCredential، الذي يأتي من azure-identity.
pip install "azure-ai-projects>=2.3.0" azure-identity
سجل الدخول باستخدام أمر CLI az login للمصادقة قبل تشغيل سكريبتات Python.
حزم التثبيت:
إضافة حزم NuGet باستخدام واجهة سطر .NET في الطرفية المتكاملة: تستخدم هذه الحزم واجهة برمجة التطبيقات Foundry (الجديدة) API.
dotnet add package Azure.AI.Projects
dotnet add package Azure.AI.Projects.Agents
dotnet add package Azure.AI.Extensions.OpenAI
dotnet add package Azure.Identity
سجل الدخول باستخدام أمر CLI az login للمصادقة قبل تشغيل سكريبتات C#.
تثبيت النسخة الحالية من @azure/ai-projects. يستخدم هذا الإصدار واجهة برمجة تطبيقات مشاريع Foundry (الجديدة):
npm install @azure/ai-projects @azure/identity
سجل الدخول باستخدام أمر CLI az login للمصادقة قبل تشغيل سكريبتات TypeScript.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-ai-agents</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.57.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.18.1</version>
</dependency>
- سجل الدخول باستخدام أمر CLI
az login للمصادقة قبل تشغيل سكريبتات Java الخاصة بك.
قم بتسجيل الدخول باستخدام أمر CLI az login للمصادقة قبل تشغيل الأمر التالي.
احصل على رمز وصول مؤقت. ستنتهي صلاحيتها خلال 60-90 دقيقة، وستحتاج إلى تحديث بعد ذلك.
az account get-access-token --scope https://ai.azure.com/.default
احفظ النتائج كمتغير AZURE_AI_AUTH_TOKENبيئي .
لا حاجة لأي تثبيت لاستخدام بوابة Foundry.
نصيحة
يستخدم الكود Azure مشاريع الذكاء الاصطناعي 2.x وهو غير متوافق مع مشاريع الذكاء الاصطناعي Azure 1.x.
انظر وثائق Foundry (الكلاسيكية) لإصدار مشاريع الذكاء الاصطناعي Azure 1.x.
دردشة مع عارضة أزياء
التفاعل مع النموذج هو الحجر الأساسي لتطبيقات الذكاء الاصطناعي. أرسل مدخلا واستلم ردا من النموذج:
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
# Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint"
# Create project and openai clients to call Foundry API
project = AIProjectClient(
endpoint=FOUNDRY_PROJECT_ENDPOINT,
credential=DefaultAzureCredential(),
)
openai = project.get_openai_client()
# Run a responses API call
response = openai.responses.create(
model="gpt-5-mini", # supports all Foundry direct models
input="What is the size of France in square miles?",
)
if not response.output_text or not response.output_text.strip():
raise RuntimeError("Response output text was empty.")
print(f"Response output: {response.output_text}")
using Azure.Identity;
using Azure.AI.Projects;
using Azure.AI.Extensions.OpenAI;
using OpenAI.Responses;
#pragma warning disable OPENAI001
// Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
var foundryProjectEndpoint = "your_project_endpoint";
// Create project client to call Foundry API
AIProjectClient projectClient = new(
endpoint: new Uri(foundryProjectEndpoint),
tokenProvider: new DefaultAzureCredential());
// Run a responses API call
ProjectResponsesClient responseClient = projectClient.ProjectOpenAIClient.GetProjectResponsesClientForModel(
"gpt-5-mini"); // supports all Foundry direct models
ResponseResult response = await responseClient.CreateResponseAsync(
"What is the size of France in square miles?");
string outputText = response.GetOutputText();
if (string.IsNullOrWhiteSpace(outputText))
{
throw new InvalidOperationException("Response output text was empty.");
}
Console.WriteLine(outputText);
import { DefaultAzureCredential } from "@azure/identity";
import { AIProjectClient } from "@azure/ai-projects";
// Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
const FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint";
async function main(): Promise<void> {
// Create project and openai clients to call Foundry API
const project = new AIProjectClient(FOUNDRY_PROJECT_ENDPOINT, new DefaultAzureCredential());
const openai = project.getOpenAIClient();
// Run a responses API call
const response = await openai.responses.create({
model: "gpt-5-mini",
input: "What is the size of France in square miles?",
});
console.log(`Response output: ${response.output_text}`);
}
main().catch(console.error);
package com.azure.ai.foundry.samples;
import com.azure.ai.agents.AgentsClientBuilder;
import com.azure.ai.agents.ResponsesClient;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.openai.models.responses.Response;
import com.openai.models.responses.ResponseCreateParams;
public class CreateResponse {
public static void main(String[] args) {
// Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
String foundryProjectEndpoint = "your_project_endpoint";
// Create responses client to call Foundry API
ResponsesClient responsesClient = new AgentsClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint(foundryProjectEndpoint)
.buildResponsesClient();
// Run a responses API call
ResponseCreateParams responseRequest = new ResponseCreateParams.Builder()
.input("What is the size of France in square miles?")
.model("gpt-5-mini")
.build();
Response response = responsesClient.getResponseService().create(responseRequest);
System.out.println(response.output());
}
}
استبدلها YOUR-FOUNDRY-RESOURCE-NAME بقيمك:
curl -X POST https://YOUR-FOUNDRY-RESOURCE-NAME.services.ai.azure.com/api/projects/YOUR-PROJECT-NAME/openai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AZURE_AI_AUTH_TOKEN" \
-d '{
"model": "gpt-5-mini",
"input": "What is the size of France in square miles?"
}'
بعد نشر النموذج، يتم نقلك تلقائيا من Home إلى قسم البناء . تم اختيار نموذجك الجديد وجاهز لتجربته.
نصيحة
إذا تخطيت النشر، فحدد Test in playground من الصفحة الرئيسية. حدد نموذج الوصول الفوري الذي تريد استخدامه، مثل gpt-5-mini. (أثناء المعاينة، تتوفر نماذج الوصول الفوري هذه فقط للمشاريع في غرب الولايات المتحدة 3.)
ابدأ بالدردشة مع عارضك، على سبيل المثال، "اكتب لي قصيدة عن الزهور."
بعد تشغيل الكود، ترى استجابة مولدة بواسطة نموذج في وحدة التحكم (على سبيل المثال، قصيدة قصيرة أو إجابة على طلبك). هذا يؤكد أن نقطة نهاية مشروعك، والمصادقة، ونشر النموذج تعمل بشكل صحيح.
نصيحة
يستخدم الكود Azure مشاريع الذكاء الاصطناعي 2.x وهو غير متوافق مع مشاريع الذكاء الاصطناعي Azure 1.x.
انظر وثائق Foundry (الكلاسيكية) لإصدار مشاريع الذكاء الاصطناعي Azure 1.x.
إنشاء وكيل
أنشئ وكيلا باستخدام النموذج المنشور الخاص بك.
الوكيل هو الذي يحدد السلوك الأساسي. بمجرد إنشائها، يضمن استجابات متسقة في تفاعلات المستخدمين دون تكرار التعليمات في كل مرة. يمكنك تحديث أو حذف الوكلاء في أي وقت.
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import PromptAgentDefinition
# Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint"
FOUNDRY_AGENT_NAME = "your-agent-name"
# Create project client to call Foundry API
project = AIProjectClient(
endpoint=FOUNDRY_PROJECT_ENDPOINT,
credential=DefaultAzureCredential(),
)
# Create an agent with a model and instructions
agent = project.agents.create_version(
agent_name=FOUNDRY_AGENT_NAME,
definition=PromptAgentDefinition(
model="gpt-5-mini", # supports all Foundry direct models
instructions="You are a helpful assistant that answers general questions",
),
)
print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})")
using Azure.Identity;
using Azure.AI.Projects;
using Azure.AI.Projects.Agents;
using Azure.AI.Extensions.OpenAI;
// Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
var foundryProjectEndpoint = "your_project_endpoint";
var foundryAgentName = "your-agent-name";
// Create project client to call Foundry API
AIProjectClient projectClient = new(
endpoint: new Uri(foundryProjectEndpoint),
tokenProvider: new DefaultAzureCredential());
// Create an agent with a model and instructions
ProjectsAgentDefinition agentDefinition = new DeclarativeAgentDefinition("gpt-5-mini") // supports all Foundry direct models
{
Instructions = "You are a helpful assistant that answers general questions",
};
ProjectsAgentVersion agent = projectClient.AgentAdministrationClient.CreateAgentVersion(
foundryAgentName,
options: new(agentDefinition));
Console.WriteLine($"Agent created (id: {agent.Id}, name: {agent.Name}, version: {agent.Version})");
import { DefaultAzureCredential } from "@azure/identity";
import { AIProjectClient } from "@azure/ai-projects";
// Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
const FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint";
const FOUNDRY_AGENT_NAME = "your_agent_name";
async function main(): Promise<void> {
// Create project client to call Foundry API
const project = new AIProjectClient(FOUNDRY_PROJECT_ENDPOINT, new DefaultAzureCredential());
// Create an agent with a model and instructions
const agent = await project.agents.createVersion(FOUNDRY_AGENT_NAME, {
kind: "prompt",
model: "gpt-5-mini", //supports all Foundry direct models
instructions: "You are a helpful assistant that answers general questions",
});
console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`);
}
main().catch(console.error);
package com.azure.ai.foundry.samples;
import com.azure.ai.agents.AgentsClient;
import com.azure.ai.agents.AgentsClientBuilder;
import com.azure.ai.agents.models.AgentVersionDetails;
import com.azure.ai.agents.models.PromptAgentDefinition;
import com.azure.identity.DefaultAzureCredentialBuilder;
public class CreateAgent {
public static void main(String[] args) {
// Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
String foundryProjectEndpoint = "your_project_endpoint";
String foundryAgentName = "your-agent-name";
// Create agents client to call Foundry API
AgentsClient agentsClient = new AgentsClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint(foundryProjectEndpoint)
.buildAgentsClient();
// Create an agent with a model and instructions
PromptAgentDefinition request = new PromptAgentDefinition("gpt-5-mini") // supports all Foundry direct models
.setInstructions("You are a helpful assistant that answers general questions");
AgentVersionDetails agent = agentsClient.createAgentVersion(foundryAgentName, request);
System.out.println("Agent ID: " + agent.getId());
System.out.println("Agent Name: " + agent.getName());
System.out.println("Agent Version: " + agent.getVersion());
}
}
استبدلها YOUR-FOUNDRY-RESOURCE-NAME بقيمك:
curl -X POST https://YOUR-FOUNDRY-RESOURCE-NAME.services.ai.azure.com/api/projects/YOUR-PROJECT-NAME/agents?api-version=v1 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AZURE_AI_AUTH_TOKEN" \
-d '{
"name": "MyAgent",
"definition": {
"kind": "prompt",
"model": "gpt-5-mini",
"instructions": "You are a helpful assistant that answers general questions"
}
}'
الآن أنشئ وكيلا وتفاعل معه.
- لا يزال في قسم البناء ، اختر الوكلاء في اللوحة اليسرى.
- اختر إنشاء وكيل وأعطه اسما مثل "MyAgent".
تؤكد النتائج أن الوكيل تم إنشاؤه. بالنسبة لتبويب SDK، ترى اسم الوكيل ومعرفه مطبوعين على وحدة التحكم.
نصيحة
يستخدم الكود Azure مشاريع الذكاء الاصطناعي 2.x وهو غير متوافق مع مشاريع الذكاء الاصطناعي Azure 1.x.
انظر وثائق Foundry (الكلاسيكية) لإصدار مشاريع الذكاء الاصطناعي Azure 1.x.
تحدث مع وكيل
استخدم الوكيل الذي تم إنشاؤه مسبقا المسمى "MyAgent" للتفاعل من خلال طرح سؤال ومتابعة ذات صلة. تحافظ المحادثة على التاريخ عبر هذه التفاعلات.
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import PromptAgentDefinition
# Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint"
FOUNDRY_AGENT_NAME = "your-agent-name"
# Create project and openai clients to call Foundry API
project = AIProjectClient(
endpoint=FOUNDRY_PROJECT_ENDPOINT,
credential=DefaultAzureCredential(),
)
# Create the agent (or a new version, if it already exists)
project.agents.create_version(
agent_name=FOUNDRY_AGENT_NAME,
definition=PromptAgentDefinition(
model="gpt-5-mini",
instructions="You are a helpful assistant that answers general questions",
),
)
# Get an OpenAI client pre-bound to the specified agent
openai = project.get_openai_client(agent_name=FOUNDRY_AGENT_NAME)
# Create a conversation for multi-turn chat
conversation = openai.conversations.create()
# Chat with the agent to answer questions
response = openai.responses.create(
conversation=conversation.id,
input="What is the size of France in square miles?",
)
print(response.output_text)
# Ask a follow-up question in the same conversation
response = openai.responses.create(
conversation=conversation.id,
input="And what is the capital city?",
)
print(response.output_text)
using Azure.Identity;
using Azure.AI.Projects;
using Azure.AI.Projects.Agents;
using Azure.AI.Extensions.OpenAI;
using OpenAI.Responses;
#pragma warning disable OPENAI001
// Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
var foundryProjectEndpoint = "your_project_endpoint";
var foundryAgentName = "your-agent-name";
// Create project client to call Foundry API
AIProjectClient projectClient = new(
endpoint: new Uri(foundryProjectEndpoint),
tokenProvider: new DefaultAzureCredential());
// Create the agent (or a new version, if it already exists)
ProjectsAgentDefinition agentDefinition = new DeclarativeAgentDefinition("gpt-5-mini") // supports all Foundry direct models
{
Instructions = "You are a helpful assistant that answers general questions",
};
projectClient.AgentAdministrationClient.CreateAgentVersion(
foundryAgentName,
options: new(agentDefinition));
// Create a conversation for multi-turn chat
ProjectConversation conversation = projectClient.ProjectOpenAIClient.GetProjectConversationsClient().CreateProjectConversation();
// Chat with the agent to answer questions
ProjectResponsesClient responsesClient = projectClient.ProjectOpenAIClient.GetProjectResponsesClientForAgent(
defaultAgent: foundryAgentName,
defaultConversationId: conversation.Id);
ResponseResult response = responsesClient.CreateResponse("What is the size of France in square miles?");
Console.WriteLine(response.GetOutputText());
// Ask a follow-up question in the same conversation
response = responsesClient.CreateResponse("And what is the capital city?");
Console.WriteLine(response.GetOutputText());
import { DefaultAzureCredential } from "@azure/identity";
import { AIProjectClient } from "@azure/ai-projects";
// Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
const FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint";
const FOUNDRY_AGENT_NAME = "your-agent-name";
async function createAgentVersion(projectEndpoint: string, agentName: string): Promise<void> {
const credential = new DefaultAzureCredential();
const token = await credential.getToken("https://ai.azure.com/.default");
if (!token) {
throw new Error("Failed to acquire a Foundry access token");
}
const response = await fetch(
`${projectEndpoint.replace(/\/$/, "")}/agents/${encodeURIComponent(agentName)}/versions?api-version=v1`,
{
method: "POST",
headers: {
"Authorization": ["Bearer", token.token].join(" "),
"Content-Type": "application/json",
},
body: JSON.stringify({
definition: {
kind: "prompt",
model: "gpt-5-mini", //supports all Foundry direct models
instructions: "You are a helpful assistant that answers general questions",
},
}),
},
);
if (!response.ok) {
throw new Error(`Failed to create agent version: ${response.status} ${await response.text()}`);
}
}
async function main(): Promise<void> {
// Create project and openai clients to call Foundry API
const project = new AIProjectClient(FOUNDRY_PROJECT_ENDPOINT, new DefaultAzureCredential());
// Create the agent (or a new version, if it already exists)
await createAgentVersion(FOUNDRY_PROJECT_ENDPOINT, FOUNDRY_AGENT_NAME);
const openai = project.getOpenAIClient({
azureConfig: { allowPreview: true, agentName: FOUNDRY_AGENT_NAME },
});
// Create a conversation for multi-turn chat
const conversation = await openai.conversations.create();
// Chat with the agent to answer questions
const response = await openai.responses.create({
conversation: conversation.id,
input: "What is the size of France in square miles?",
});
console.log(response.output_text);
// Ask a follow-up question in the same conversation
const response2 = await openai.responses.create({
conversation: conversation.id,
input: "And what is the capital city?",
});
console.log(response2.output_text);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
package com.azure.ai.foundry.samples;
import com.azure.ai.agents.AgentsClient;
import com.azure.ai.agents.AgentsClientBuilder;
import com.azure.ai.agents.models.PromptAgentDefinition;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.openai.client.OpenAIClient;
import com.openai.models.conversations.Conversation;
import com.openai.models.responses.Response;
import com.openai.models.responses.ResponseCreateParams;
public class ChatWithAgent {
public static void main(String[] args) {
// Format: "https://resource_name.services.ai.azure.com/api/projects/project_name"
String foundryProjectEndpoint = "your_project_endpoint";
String foundryAgentName = "your-agent-name";
AgentsClientBuilder builder = new AgentsClientBuilder()
.credential(new DefaultAzureCredentialBuilder().build())
.endpoint(foundryProjectEndpoint);
// Create the agent (or a new version, if it already exists)
AgentsClient agentsClient = builder.buildAgentsClient();
PromptAgentDefinition agentDefinition = new PromptAgentDefinition("gpt-5-mini") // supports all Foundry direct models
.setInstructions("You are a helpful assistant that answers general questions");
agentsClient.createAgentVersion(foundryAgentName, agentDefinition);
// Create an OpenAI client bound to the agent endpoint
OpenAIClient openai = builder.buildAgentScopedOpenAIClient(foundryAgentName);
// Create a conversation for multi-turn chat
Conversation conversation = openai.conversations().create();
// Chat with the agent to answer questions
Response response = openai.responses().create(
ResponseCreateParams.builder()
.conversation(conversation.id())
.input("What is the size of France in square miles?")
.build());
printResponse(response);
// Ask a follow-up question in the same conversation
Response followUp = openai.responses().create(
ResponseCreateParams.builder()
.conversation(conversation.id())
.input("And what is the capital city?")
.build());
printResponse(followUp);
}
private static void printResponse(Response response) {
response.output().forEach(item -> item.message().ifPresent(message ->
message.content().forEach(content -> content.outputText().ifPresent(
text -> System.out.println(text.text())))));
}
}
استبدلها YOUR-FOUNDRY-RESOURCE-NAME بقيمك:
# Generate a response using the agent
curl -X POST "https://YOUR-FOUNDRY-RESOURCE-NAME.services.ai.azure.com/api/projects/YOUR-PROJECT-NAME/agents/${FOUNDRY_AGENT_NAME}/endpoint/protocols/openai/responses?api-version=v1" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AZURE_AI_AUTH_TOKEN" \
-d '{
"input": [{"role": "user", "content": "What is the size of France in square miles?"}]
}'
# Optional Step: Create a conversation to use with the agent
curl -X POST "https://YOUR-FOUNDRY-RESOURCE-NAME.services.ai.azure.com/api/projects/YOUR-PROJECT-NAME/agents/${FOUNDRY_AGENT_NAME}/endpoint/protocols/openai/conversations?api-version=v1" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AZURE_AI_AUTH_TOKEN" \
-d '{
"items": [
{
"type": "message",
"role": "user",
"content": [
{
"type": "input_text",
"text": "What is the size of France in square miles?"
}
]
}
]
}'
# Lets say Conversation ID created is conv_123456789. Use this in the next step
#Optional Step: Ask a follow-up question in the same conversation
curl -X POST "https://YOUR-FOUNDRY-RESOURCE-NAME.services.ai.azure.com/api/projects/YOUR-PROJECT-NAME/agents/${FOUNDRY_AGENT_NAME}/endpoint/protocols/openai/responses?api-version=v1" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AZURE_AI_AUTH_TOKEN" \
-d '{
"conversation": "<CONVERSATION_ID>",
"input": [{"role": "user", "content": "And what is the capital?"}]
}'
تفاعل مع وكيلك.
- أضف تعليمات مثل: "أنت مساعد كتابة مفيد."
- ابدأ بالدردشة مع وكيلك، على سبيل المثال، "اكتب قصيدة عن الشمس."
- تابع ب "ماذا عن هايكو؟"
ترى ردود الوكيل على كلتا الطلبات. يظهر الرد اللاحق أن العميل يحافظ على سجل المحادثات عبر الأدوار.
نصيحة
يستخدم الكود Azure مشاريع الذكاء الاصطناعي 2.x وهو غير متوافق مع مشاريع الذكاء الاصطناعي Azure 1.x.
انظر وثائق Foundry (الكلاسيكية) لإصدار مشاريع الذكاء الاصطناعي Azure 1.x.
موارد التنظيف
إذا لم تعد بحاجة لأي من الموارد التي أنشأتها، احذف مجموعة الموارد المرتبطة بمشروعك.
- في بوابة Azure، اختر مجموعة الموارد، ثم اختر Delete. تأكد أنك تريد حذف مجموعة الموارد.
الخطوة التالية