You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to rate-limit a simple netlify serverless function. The function manages to return a response but still throws an error.
Here's the code for the function:
// /netlify/handler.tsimport*asdotenvfrom'dotenv';import{Handler,HandlerEvent,HandlerContext}from"@netlify/functions";import{Configuration,OpenAIApi}from"openai";import{Ratelimit}from"@upstash/ratelimit";import{Redis}from"@upstash/redis";dotenv.config();constconfiguration=newConfiguration({apiKey: process.env.OPENAI_API_KEY});constopenai=newOpenAIApi(configuration);constratelimit=newRatelimit({redis: Redis.fromEnv(),limiter: Ratelimit.fixedWindow(10,"20 s"),});consthandler: Handler=async(event: HandlerEvent,_context: HandlerContext)=>{constquestion=JSON.parse(event.body).body;// check if the selected text is useless.if(question===undefined||question.length<7){return{statusCode: 205,body: JSON.stringify({message: "no text"}),}}// Upstash rate-limiterconstidentifier="api";constsuccess=ratelimit.limit(identifier).then(e=>{returne}).catch(e=>{console.log('Error in upstash fetch:',e)})// <---- error comes from hereif(!success){return{statusCode: 429,body: JSON.stringify({message: "Woah! Slow down."}),}}try{constres=awaitopenai.createCompletion({model: "text-curie-001",prompt: `:Say this is a test: """${question}"""`,max_tokens: 100,temperature: 0,});return{statusCode: 200,body: JSON.stringify({message: res.data.choices[0].text}),}}catch(e){console.log("ERROR has occured",e.response);return{statusCode: 500,body: JSON.stringify({message: "Error"}),};}};export{handler};
Here's the stack trace:
Request from ::1: POST /.netlify/functions/gpt-summarize
(node:87001) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Error in upstash fetch: UpstashError: NOPERM this user has no permissions to run the 'eval' command or its subcommand
at HttpClient.request (/Users/Yash/Code/summarize/node_modules/@upstash/redis/esm/pkg/http.js:93:19)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at EvalCommand.exec (/Users/Yash/Code/summarize/node_modules/@upstash/redis/esm/pkg/commands/command.js:46:35)
at RegionRatelimit.limiter (/Users/Yash/Code/summarize/node_modules/@upstash/ratelimit/esm/single.js:88:44)
at RegionRatelimit.value (/Users/Yash/Code/summarize/node_modules/@upstash/ratelimit/esm/ratelimit.js:62:24)
Response with status 200 in 1763 ms.
After I catch the error, it manages to give me a response though.
Let me know if this a ratelimiter error or if I report it at upstash-redis.
Cheers!
The text was updated successfully, but these errors were encountered:
I'm trying to rate-limit a simple netlify serverless function. The function manages to return a response but still throws an error.
Here's the code for the function:
Here's the stack trace:
After I catch the error, it manages to give me a response though.
Let me know if this a ratelimiter error or if I report it at
upstash-redis
.Cheers!
The text was updated successfully, but these errors were encountered: