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

openai.createEmbedding() bug: cannot pass in array for "input" param

Open Johnrobmiller opened this issue 2 years ago • 2 comments

Describe the bug

When I pass in an array of strings for the "input" param as specified here, the connection times out and eventually I get an error 500 with the error message: "Error: read ECONNRESET".

Passing in a non-array string for "input" works fine.

I am using Next.js using their serverless endpoints testing on localhost.

To Reproduce

Reproduction info in description

Code snippets

try {
    const promptEmbeddingsRes = await openAi.createEmbedding({
      model: 'text-embedding-ada-002',
      input: ['test', 'test', 'test'], 
    })
    console.log('prompt embeddings', promptEmbeddingRes.data.data)
    return res.status(200).json(promptEmbeddingsRes.data.data)
  } catch (e) {
    console.error('Error creating embedding: ', e)
    return res.status(500).send("Error creating embedding: " + e)
  }

OS

macOS

Node version

v16

Library version

3.1

Johnrobmiller avatar Feb 09 '23 19:02 Johnrobmiller

Whoops, I stuck promptEmbeddingRes.data.data in the .json(), and that was not allowed. Once i fixed that, the api worked fine.

Johnrobmiller avatar Feb 09 '23 20:02 Johnrobmiller

Nope, the error happened again after that json issue was fixed, so reopening this

Johnrobmiller avatar Feb 09 '23 21:02 Johnrobmiller

Hey! I'm facing this issue in the streaming APIs as well

aashutoshrathi avatar May 22 '23 20:05 aashutoshrathi

I believe this is fixed in v4 of this library – please reopen with further details if that's not the case.

rattrayalex avatar Jul 08 '23 19:07 rattrayalex