एक सामग्री समझ विश्लेषक बनाएँ
सुझाव
अधिक जानकारी के लिए टेक्स्ट और इमेज टैब देखें!
अधिकांश परिदृश्यों में, आपको सामग्री समझ स्टूडियो में विज़ुअल इंटरफ़ेस का उपयोग करके विश्लेषक बनाने और परीक्षण करने पर विचार करना चाहिए। हालाँकि, कुछ मामलों में आप API को अपने इच्छित सामग्री फ़ील्ड के लिए स्कीमा की JSON परिभाषा सबमिट करके एक विश्लेषक बनाना चाह सकते हैं।
एक विश्लेषक के लिए स्कीमा को परिभाषित करना
विश्लेषक स्कीमा पर आधारित होते हैं जो उन फ़ील्ड को परिभाषित करते हैं जिन्हें आप किसी सामग्री फ़ाइल से निकालना या जनरेट करना चाहते हैं। अपने सरलतम रूप में, एक स्कीमा फ़ील्ड का एक सेट है, जिसे JSON दस्तावेज़ में निर्दिष्ट किया जा सकता है, जैसा कि विश्लेषक परिभाषा के इस उदाहरण में दिखाया गया है:
{
"description": "Simple business card",
"baseAnalyzerId": "prebuilt-document",
"config": {
"returnDetails": true
},
"fieldSchema": {
"fields": {
"ContactName": {
"type": "string",
"method": "extract",
"description": "Name on business card"
},
"EmailAddress": {
"type": "string",
"method": "extract",
"description": "Email address on business card"
}
}
},
"models": {
"completion": "gpt-4.1",
"embedding": "text-embedding-3-large"
}
}
कस्टम विश्लेषक स्कीमा का यह उदाहरण पूर्व-निर्मित दस्तावेज़ विश्लेषक पर आधारित है, और दो फ़ील्ड का वर्णन करता है जिन्हें आप व्यवसाय कार्ड पर ढूँढने की अपेक्षा करेंगे: ContactName और EmailAddress. दोनों फ़ील्ड्स को स्ट्रिंग डेटा प्रकारों के रूप में परिभाषित किया गया है, और किसी दस्तावेज़ से निकाले जाने की अपेक्षा की जाती है (दूसरे शब्दों में, स्ट्रिंग मानों के दस्तावेज़ में मौजूद होने की अपेक्षा की जाती है ताकि उन्हें "पढ़ा" जा सके; बजाय इसके कि वे फ़ील्ड हों जो दस्तावेज़ के बारे में जानकारी का अनुमान लगाकर उत्पन्न किए जा सकते हैं).
models ऑब्जेक्ट उन जनरेटिव मॉडल को निर्दिष्ट करता है जिनका उपयोग विश्लेषक प्रसंस्करण के लिए करता है।
नोट
यह उदाहरण जानबूझकर सरल है, एक कार्यशील विश्लेषक बनाने के लिए आवश्यक न्यूनतम जानकारी के साथ। हकीकत में, स्कीमा में संभवतः विभिन्न प्रकार के अधिक फ़ील्ड शामिल होंगे, और विश्लेषक परिभाषा में अधिक कॉन्फ़िगरेशन सेटिंग्स शामिल होंगी। JSON में एक नमूना दस्तावेज़ भी शामिल हो सकता है। अधिक विवरण के लिए Azure सामग्री को समझना API दस्तावेज़ देखें।
विश्लेषक बनाने के लिए पायथन एसडीके का उपयोग करना
अपनी विश्लेषक परिभाषा के साथ, आप विश्लेषक बनाने के लिए पायथन एसडीके का उपयोग कर सकते हैं।
ContentUnderstandingClient क्लास एक विधि begin_create_analyzer प्रदान करता है जो आपके लिए अतुल्यकालिक निर्माण प्रक्रिया को संभालता है।
from azure.ai.contentunderstanding import ContentUnderstandingClient
from azure.core.credentials import AzureKeyCredential
# Authenticate the client
endpoint = "<YOUR_ENDPOINT>"
credential = AzureKeyCredential("<YOUR_API_KEY>")
client = ContentUnderstandingClient(endpoint=endpoint, credential=credential)
# Define the analyzer
analyzer_name = "business_card_analyser"
analyzer_definition = {
"description": "Simple business card",
"baseAnalyzerId": "prebuilt-document",
"config": {"returnDetails": True},
"fieldSchema": {
"fields": {
"ContactName": {
"type": "string",
"method": "extract",
"description": "Name on business card"
},
"EmailAddress": {
"type": "string",
"method": "extract",
"description": "Email address on business card"
}
}
},
"models": {
"completion": "gpt-4.1",
"embedding": "text-embedding-3-large"
}
}
# Create the analyzer and wait for completion
poller = client.begin_create_analyzer(analyzer_name, body=analyzer_definition)
result = poller.result()
print(f"Analyzer created: {result.analyzer_id}")
विश्लेषक बनाने के लिए REST API का उपयोग करना
वैकल्पिक रूप से, आप सीधे REST API का उपयोग कर सकते हैं। JSON डेटा को विश्लेषक निर्माण कार्रवाई शुरू करने के लिए अनुरोध शीर्षलेख में API कुंजी के साथ समापन बिंदु के अनुरोध के रूप PUT में सबमिट किया जाता है।
अनुरोध की PUT प्रतिक्रिया में हेडर में एक ऑपरेशन-स्थान शामिल है, जो एक कॉलबैक URL प्रदान करता है जिसका उपयोग आप अनुरोध सबमिट GET करके अनुरोध की स्थिति की जांच करने के लिए कर सकते हैं।
निम्नलिखित पायथन कोड card.json नाम की फ़ाइल की सामग्री के आधार पर एक विश्लेषक बनाने का अनुरोध प्रस्तुत करता है (जिसे पहले वर्णित JSON परिभाषा शामिल करने के लिए माना जाता है):
import json
import requests
# Get the business card schema
with open("card.json", "r") as file:
schema_json = json.load(file)
# Use a PUT request to submit the schema for a new analyzer
analyzer_name = "business_card_analyser"
headers = {
"Ocp-Apim-Subscription-Key": "<YOUR_API_KEY>",
"Content-Type": "application/json"}
url = f"{<YOUR_ENDPOINT>}/contentunderstanding/analyzers/{analyzer_name}?api-version=2025-11-01"
response = requests.put(url, headers=headers, data=json.dumps(schema_json))
# Get the response and extract the ID assigned to the operation
callback_url = response.headers["Operation-Location"]
# Use a GET request to check the status of the operation
result_response = requests.get(callback_url, headers=headers)
# Keep polling until the operation is complete
status = result_response.json().get("status")
while status == "Running":
result_response = requests.get(callback_url, headers=headers)
status = result_response.json().get("status")
print("Done!")