gpt4 book ai didi

node.js - 获取错误 400 OpenAI 文件端点 Node.js

转载 作者:行者123 更新时间:2023-12-02 05:48:02 24 4
gpt4 key购买 nike

我已经尝试了几个小时,尝试了 CSV 数据、JSON 数据,尝试了所有这些,但我总是收到 415 错误或 400 错误;如果我能得到任何帮助,那将是很好的,文档和 AI 本身对尝试注入(inject)数据来训练模型没有任何帮助

文本:

This is a text file for the OpenAI API.
It contains sample data for testing purposes.
Here is another line.
And another.

代码:

const FormData = require('form-data');
const fs = require('fs');
const API_KEY = 'MY_API_KEY';
const formData = new FormData();
formData.append('file', fs.createReadStream('./myfile.txt'), {
filename: 'myfile.txt'
});

axios.post('https://api.openai.com/v1/files', formData, {
headers: {
'Content-Type': `multipart/form-data; boundary=${formData._boundary}`,
"Authorization": "Bearer " + API_KEY
}
})
.then(response => {
// Handle response
})
.catch(err => {
// Handle error
console.log(err)
});

最佳答案

来自 the documentation ,您缺少必填的 purpose 字段...

Request body

file Required
...
purpose Required

The intended purpose of the uploaded documents.

Use "fine-tune" for Fine-tuning. This allows us to validate the format of the uploaded file.

const FormData = require("form-data");
const fs = require("fs");

const API_KEY = "MY_API_KEY";

const formData = new FormData();
formData.append("purpose", "search"); // 👈 adjust accordingly
formData.append("file", fs.createReadStream("./myfile.txt"), "myfile.txt");

axios
.post("https://api.openai.com/v1/files", formData, {
headers: {
...formData.getHeaders(), // this is simpler
authorization: `Bearer ${API_KEY}`,
},
})
.then((response) => {
// Handle response
})
.catch((err) => {
// Handle error
console.log(err.response?.data, err.toJSON());
});

关于node.js - 获取错误 400 OpenAI 文件端点 Node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75129931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com