cohere-ai / cohere-typescript

The Cohere TypeScript SDK
https://docs.cohere.ai
MIT License
122 stars 18 forks source link

7.4.0 failing with `Error: Cannot read properties of undefined (reading 'status')` #104

Closed d-e-h-i-o closed 10 months ago

d-e-h-i-o commented 10 months ago

Hi, I just upgraded from 7.2.0 to 7.4.0, and code that was previous working now fails with the following error:

[Error] Error: Cannot read properties of undefined (reading 'status')
    at $n.<anonymous> (https://esm.sh/v134/cohere-ai@7.4.0/esnext/cohere-ai.mjs:13:3937)
    at Generator.next (<anonymous>)
    at f (https://esm.sh/v134/cohere-ai@7.4.0/esnext/cohere-ai.mjs:12:122188)
    at eventLoopTick (ext:core/01_core.js:197:13)

This is the code sample:

    const embeddingResponse = await cohere.embed({
      texts: [text],
      model: "embed-multilingual-v3.0",
      inputType: isQuery ? "search_query" : "search_document",
      truncate: isQuery? "START" : "END", // for queries, we truncate start, since the last message is the most recent one
    });

    let tokenCount;
    tokenCount = (await cohere.tokenize({
      text: embeddingResponse.texts[0]!,
      model: "embed-multilingual-v3.0",
    })).tokens.length;

I can't see from the stack trace which API call caused this (unrelated, I just released that I can get the input token count with embeddingResponse.meta.billed_units.input_tokens instead of a separate call :) )

billytrend-cohere commented 10 months ago

Hey @d-e-h-i-o thanks for flagging, this looks like a bug with our service rather than the sdk and we're looking into it for you!

d-e-h-i-o commented 10 months ago

Hey @d-e-h-i-o thanks for flagging, this looks like a bug with our service rather than the sdk and we're looking into it for you!

@billytrend-cohere Thank you! Just to clarify: Downgrading the SDK did solve the problem.

billytrend-cohere commented 10 months ago

Oh interesting, do you mind trying again with 7.4.0 just to confirm that it wasn't a transient issue? I can't repro at either version but still investigating

d-e-h-i-o commented 10 months ago

Oh interesting, do you mind trying again with 7.4.0 just to confirm that it wasn't a transient issue? I can't repro at either version but still investigating

You're right, it was not related to the upgrade. I upgraded again, and it's working now.

billytrend-cohere commented 10 months ago

Ok that's great. We are definitely going to improve the error messaging on this though. Thanks for trying out the different scenarios.

billytrend-cohere commented 10 months ago

Logging should be better as of cohere-ai@7.5.1!