cohere-ai / cohere-typescript

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

Error running on AWS lambda node 18 TypeError: fetchFn is not a function #136

Closed Gr33nLight closed 6 months ago

Gr33nLight commented 6 months ago

Possibly related to #112 which i commented on. I'm running on aws lambda and the following line returns an instance of node-fetch but its not callable unless I add fetchFn.default to it. The error Is

TypeError: fetchFn is not a function

RUNTIME.type is correctly logged as "node" from my tests, the issue appears to be related to the way the required instance is used.

https://github.com/cohere-ai/cohere-typescript/blob/48fd526c969effde139a246a4dc1a1ea1b9f6fa3/src/core/fetcher/Fetcher.ts#L83

dsinghvi commented 6 months ago

@Gr33nLight Thanks for flagging this issue. We are actively working on this and will be releasing a patch soon.

Gr33nLight commented 6 months ago

Ok, a suggestion could be checking for the availability for the global fetch first (instead of after like now) because its available by default in node 18 and if not, fallback to requiring node-fetch

dsinghvi commented 6 months ago

Ok, a suggestion could be checking for the availability for the global fetch first (instead of after like now) because its available by default in node 18 and if not, fallback to requiring node-fetch

@Gr33nLight we moved away from that because experimental versions of fetch in node don't support things like file upload

learnuidev commented 6 months ago

I am running into this same issue with nextjs

Steps to reproduce:

  1. Create nextjs v14 project and add api route.
  2. Install cohere-ai version 7.7.7 and try calling the re-rank method
  3. You get this error
 ⨯ CohereError: fetchFn is not a function
    at CohereClient.eval (webpack-internal:///(rsc)/./node_modules/cohere-ai/Client.js:528:27)
    at Generator.next (<anonymous>)
    at fulfilled (webpack-internal:///(rsc)/./node_modules/cohere-ai/Client.js:46:32)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Code

import { CohereClient } from "cohere-ai";

const cohereClient = new CohereClient({ token: appConfig.cohereAPIKey });

const reranked = await cohereClient.rerank({
    query,
    documents: docs,
    topN: 3,
});
Gr33nLight commented 6 months ago

@dsinghvi Hello Is there an ETA for a fix?

vishalobrizum commented 6 months ago

@dsinghvi Hello Is there an ETA for a fix?

If you use the endpoint directly and not the sdk it should work. Link here: https://docs.cohere.com/reference/chat

RobertHH-IS commented 6 months ago

I am now also getting this issue again - is there an eta on this fix!

The old error: CohereError: fetchFn is not a function

is back. Still running node 20, next 14.1

karol-f commented 6 months ago

Pull request with the fix is prepared - https://github.com/cohere-ai/cohere-typescript/pull/140

billytrend-cohere commented 6 months ago

Hey all thanks for your patience. This should be fixed in 7.8.0. Please let me know if there are further issues or more feedback!