openai / openai-node

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

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

Closed euclid1990 closed 5 months ago

euclid1990 commented 5 months ago

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

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

pstern-sl commented 5 months ago

Thanks for flagging. We will take a look!

pstern-sl commented 5 months ago

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