我正在按照 Azure 关于数据摄取作业 API 的文档进行操作,文档链接在这里:https://learn.microsoft.com/en-us/rest/api/azureopenai/ingestion-jobs/create?view=rest-azureopenai-2024-07-01-preview&tabs=HTTP
无论我的请求体或请求头中的 api-key 是什么,我都从服务器收到 { error: { code: ‘404’, message: ‘Resource not found’ } } 的响应。我使用的端点是在 Azure 门户中 Azure OpenAI 资源 -> 资源管理 -> 密钥和端点 -> 端点下找到的。Azure OpenAI 资源部署在瑞典中部。
这是我的请求代码:
const jobId = 'testing2793619'; // 要创建的作业的 ID const url = `${openaiEndpoint}/openai/ingestion/jobs/${jobId}?api-version=2024-07-01-preview`; const requestBody = { kind: "SystemCompute", searchServiceConnection: { kind: "EndpointWithKey", endpoint: searchEndpoint, // 替换为您的 Azure AI Search 服务端点, key: searchAdminApiKey // 替换为您的 Azure AI Search 管理员 API 密钥 }, datasource: { kind: "Storage", connection: { kind: "ConnectionString", connectionString: blobStorageConnectionString }, containerName: "testcontainer", chunking: { maxChunkSizeInTokens: 2048 // 根据需要自定义 } }, dataRefreshIntervalInHours: 24, // 根据需要自定义 completionAction: "cleanUpTempAssets" // 或 "cleanUpTempAssets",根据您的需求 }; 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('请求成功:', data); return data; } else { const errorData = await response.json(); console.error('请求失败摄取:', errorData); } } catch (error) { console.error('错误:', error); }
回答:
404 资源未找到
错误在尝试使用 Azure OpenAI 数据摄取作业 API 创建摄取作业时发生,这是由于无效的端点 URL 和 API 密钥导致的。
以下是我们配置端点 URL 和 API 密钥的方式:
async function createIngestionJob() { const endpoint = "https://AzureOpenapiName.openai.azure.com"; const jobId = "ingestion-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' };
下面的 JavaScript 代码用于使用 Azure OpenAI 服务创建一个摄取作业,包含端点和 API 版本。
const axios = require('axios');async function createIngestionJob() { const endpoint ="https://AzureOpenapiName.openai.azure.com"; const jobId = "ingestion-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', // 如果需要 'aml-user-token': 'YOUR_AML_USER_TOKEN' // 如果需要 }; 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('摄取作业创建成功:', response.data); console.log('操作位置:', response.headers['operation-location']); } catch (error) { console.error('创建摄取作业时出错:', error.response.data); }}createIngestionJob();