cohere-ai/cohere-typescript

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

Gr33nLight opened this issue · 9 comments

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.

RUNTIME.type === "node" ? require("node-fetch") : typeof fetch == "function" ? fetch : require("node-fetch");

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

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

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

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,
});

@dsinghvi Hello Is there an ETA for a fix?

@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

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

Pull request with the fix is prepared - #140

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!