openai-node icon indicating copy to clipboard operation
openai-node copied to clipboard

Type '"batch"' is not assignable to type '"fine-tune" | "assistants"

Open euclid1990 opened this issue 9 months ago • 2 comments

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • [X] This is an issue with the Node library

Describe the bug

According to the document Uploading Your Batch Input File. I tried the following code:

import fs from "fs";
import OpenAI from "openai";

const openai = new OpenAI();

async function main() {
  const file = await openai.files.create({
    file: fs.createReadStream("batchinput.jsonl"),
    purpose: "batch",
  });

  console.log(file);
}

main();

However, it outputs the error:

TSError: ⨯ Unable to compile TypeScript:
worker/generate.ts:18:4 - error TS2322: Type '"batch"' is not assignable to type '"fine-tune" | "assistants"'.

18    purpose: "batch",
      ~~~~~~~

  node_modules/openai/resources/files.d.ts:119:5
    119     purpose: 'fine-tune' | 'assistants';
            ~~~~~~~
    The expected type comes from property 'purpose' which is declared here on type 'FileCreateParams'

Maybe the type batch is missing in this line of the openai package source code:

https://github.com/openai/openai-node/blob/7196ac9310d58d057fb2a575e60c1718bf6341a2/src/resources/files.ts#L185

We can fix it by adding batch

purpose: 'fine-tune' | 'assistants' | 'batch';

To Reproduce

Easy to reproduce: look at official documentation page - https://platform.openai.com/docs/guides/batch/2-uploading-your-batch-input-file Run above code in nodejs / typescript.

Code snippets

No response

OS

macOS

Node version

v20.11.0

Library version

v4.42.0

euclid1990 avatar May 08 '24 15:05 euclid1990

Thanks for flagging. We will take a look!

pstern-sl avatar May 08 '24 19:05 pstern-sl

This is resolved in 4.43 which should be merged shortly! Thank you for reporting. https://github.com/openai/openai-node/pull/832

pstern-sl avatar May 08 '24 20:05 pstern-sl