Azure OpenAI Ingesion Job API returns 404 Resource not found
题意:Azure OpenAI Ingestion Job API 返回 404 资源未找到。
问题背景:
Im following the documentation from Azure on the ingestion job API here: Ingestion Jobs - Create - REST API (Azure Azure AI Services) | Microsoft Learn
我正在按照Azure的文档操作,关于Ingestion Job API的内容在这里:Ingestion Jobs - Create - REST API (Azure Azure AI Services) | Microsoft Learn
No matter the body of my request or the api-key in the request headers, I get { error: { code: '404', message: 'Resource not found' } } from the server. The endpoint im using is the one found in the Azure portal under Azure OpenAI resource -> Resource Management -> Keys and Endpoints -> Endpoint. The Azure OpenAI resource is deployed in Sweden Central.
无论我请求的主体内容或请求头中的 API 密钥如何,服务器返回的都是 `{ error: { code: '404', message: 'Resource not found' } }`。我使用的端点是在 Azure 门户中的 Azure OpenAI 资源 -> 资源管理 -> 密钥和端点 -> 端点下找到的。Azure OpenAI 资源部署在瑞典中部区域。
Here is my request code:
以下是我的请求代码:
const jobId = 'testing2793619'; // The ID of the job to be created
const url = `${openaiEndpoint}/openai/ingestion/jobs/${jobId}?api-version=2024-07-01-preview`;
const requestBody = {
kind: "SystemCompute",
searchServiceConnection: {
kind: "EndpointWithKey",
endpoint: searchEndpoint, // Replace with your Azure AI Search service endpoint,
key: searchAdminApiKey // Replace with your Azure AI Search admin API key
},
datasource: {
kind: "Storage",
connection: {
kind: "ConnectionString",
connectionString: blobStorageConnectionString
},
containerName: "testcontainer",
chunking: {
maxChunkSizeInTokens: 2048 // Customize as needed
}
},
dataRefreshIntervalInHours: 24, // Customize as needed
completionAction: "cleanUpTempAssets" // or "cleanUpTempAssets" depending on your needs
};
try {
const response = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'api-key': openaiApiKey
},
body: JSON.stringify(requestBody)
});
if (response.ok) {
const data = await response.json();
console.log('Request successful:', data);
return data;
} else {
const errorData = await response.json();
console.error('Request failed ingestion:', errorData);
}
} catch (error) {
console.error('Error:', error);
}
问题解决:
The
404 Resource not found
error occurs when trying to create an ingestion job using the Azure OpenAI Ingestion Job API due to an invalid endpoint URL and API key.
Below is how we configure the endpoint URL and API key:
以下是我们配置端点 URL 和 API 密钥的方式:
async function createIngestionJob() {
const endpoint = "https://AzureOpenapiName.openai.azure.com";
const jobId = "ingestion-job"; // Replace with your job ID
const apiVersion = "2024-07-01-preview";
try {
const response = await axios.put(
`${endpoint}/openai/ingestion/jobs/${jobId}?api-version=${apiVersion}`,
requestBody,
{ headers }
);
const headers = {
'api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
};
The javascript code below is for creation of an ingestion job using the Azure OpenAI Service with an endpoint and API version.
以下的 JavaScript 代码用于使用 Azure OpenAI 服务创建一个 Ingestion Job,包括端点和 API 版本的配置。
const axios = require('axios');
async function createIngestionJob() {
const endpoint ="https://AzureOpenapiName.openai.azure.com";
const jobId = "ingestion-job"; // Replace with your job ID
const apiVersion = "2024-07-01-preview";
const headers = {
'api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json',
'mgmt-user-token': 'YOUR_MGMT_USER_TOKEN', // If required
'aml-user-token': 'YOUR_AML_USER_TOKEN' // If required
};
const requestBody = {
"kind": "SystemCompute",
"searchServiceConnection": {
"kind": "EndpointWithManagedIdentity",
"endpoint": "https://aykame-dev-search.search.windows.net"
},
"datasource": {
"kind": "Storage",
"connection": {
"kind": "EndpointWithManagedIdentity",
"endpoint": "https://mystorage.blob.core.windows.net/",
"resourceId": "/subscriptions/1234567-abcd-1234-5678-1234abcd/resourceGroups/my-resource/providers/Microsoft.Storage/storageAccounts/mystorage"
},
"containerName": "container",
"chunking": {
"maxChunkSizeInTokens": 2048
},
"embeddings": [
{
"connection": {
"kind": "RelativeConnection"
},
"deploymentName": "Ada"
}
]
},
"dataRefreshIntervalInHours": 24,
"completionAction": "keepAllAssets"
};
try {
const response = await axios.put(
`${endpoint}/openai/ingestion/jobs/${jobId}?api-version=${apiVersion}`,
requestBody,
{ headers }
);
console.log('Ingestion job created successfully:', response.data);
console.log('Operation location:', response.headers['operation-location']);
} catch (error) {
console.error('Error creating ingestion job:', error.response.data);
}
}
createIngestionJob();