cohere-ai / cohere-typescript

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

fetch issue in AWS lambda #112

Closed alex-cortenix closed 10 months ago

alex-cortenix commented 10 months ago

Hello Team,

I am currently attempting to integrate Cohere embed within an AWS Lambda function and have come across a frustrating issue. It appears that the library interferes with the global "fetch" function that is provided by Node.js version 18, resulting in a malfunction that causes other libraries that utilize "fetch" to fail. The specific error message I'm receiving is "TypeError: fetch is not a function." Could anyone suggest a potential solution or workaround for this problem?

Thank you for your assistance.

billytrend-cohere commented 10 months ago

Hey @alex-cortenix thanks for reporting, we're seeing similar issues with #110. Will sync with @dsinghvi and have a fix for you asap.

billytrend-cohere commented 10 months ago

you may have luck depending on 7.6.0 if that unblocks you for now. This was the version that used axios, not fetch. Thanks

billytrend-cohere commented 10 months ago

Closing in favour of https://github.com/fern-api/fern/issues/2555

billytrend-cohere commented 9 months ago

Hey @alex-cortenix this should be working as of 7.7.5. Let me know if you have any further issues! Thanks

Gr33nLight commented 8 months ago

Hello I'm using @langchain/cohere with CohereRerank which uses cohere-ai client version 7.7.7 running on lambda and getting the error

CohereError: fetchFn is not a function

Could this still be related? Anyone managed to make it work with lambda?

Gr33nLight commented 8 months ago

Found the cause of the error, in my case if I update the compiled js code to be const response = yield fetchFn.default insteadof const response = yield fetchFn under makeRequest in Fetcher file, it works. I suspect it has something to do with how require("node-fetch") is used. I'm using node 18