openai / openai-node

The official Node.js / Typescript library for the OpenAI API
https://www.npmjs.com/package/openai
Apache License 2.0
7.64k stars 819 forks source link

Can't upload file #5

Closed Tohaker closed 2 years ago

Tohaker commented 2 years ago

I'm trying to upload a file that can then be used to create a fine-tune. It's been passed through the CLI validator so I know it's correct, but I keep getting the following error from Axios:

data: {
      error: {
        message: 'The browser (or proxy) sent a request that this server could not understand.',
        type: 'server_error',
        param: null,
        code: null
      }
    }

Here's how I'm trying to upload the file;

const configuration = new Configuration({
    apiKey: process.env.OPENAI_API_KEY,
  });
  const openai = new OpenAIApi(configuration);

await openai.createFile(`${uploadFilename}.jsonl`, "fine-tune");

Am I doing this right? I can't seem to see what the problem could be.

npaez commented 2 years ago

Hi Tohaker, in the examples they are sending the file as a readable stream. Using createReadStream() from the fs module. Did you tried this?

const fs = require("fs");

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(configuration);

const response = await openai.createFile(
  fs.createReadStream("puppy.jsonl"),
  "answers"
);
Tohaker commented 2 years ago

Thanks, that worked. The description in the API differs from how this is implemented, I'll see if I can raise a PR