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();

  • 19
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值