Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpt.ts configuration error #5

Open
EdwinBayingana opened this issue Oct 30, 2023 · 3 comments
Open

gpt.ts configuration error #5

EdwinBayingana opened this issue Oct 30, 2023 · 3 comments

Comments

@EdwinBayingana
Copy link

Hey guys, I have had an error for the past few hours related to the gpt.ts file configuration and after inspecting through the setup, I noticed that this:

The initial openai setup:

import { Configuration, OpenAIApi } from 'openai'; const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration);

The error I was getting:
Screen Shot 2023-10-30 at 12 23 55

@EdwinBayingana
Copy link
Author

EdwinBayingana commented Oct 30, 2023

After some research online, I found out that the configuration has been changed to this:

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

After changing the openai setup above, you can also edit the response like this:

const response = await openai.chat.completions.create({
      temperature: temperature,
      model: model,
      messages: [
        {
          role: 'system',
          content: system_prompt + output_format_prompt + error_msg,
        },
        { role: 'user', content: user_prompt.toString() },
      ],
    });

    let res: string =
      response.choices[0].message?.content?.replace(/'/g, '"') ?? '';

I left everything else as @Elliott-Chong had set it up in this repository, and this new setup has worked for me:

Screen Shot 2023-10-30 at 12 29 32

@EdwinBayingana
Copy link
Author

To anyone who meets the same issue, you can try adding this slight change in gpt.ts

Cheers.

@niks0707
Copy link

niks0707 commented May 16, 2024

C:\Users\nikhi\Desktop\quizmify>npm run dev

[email protected] dev
next dev

▲ Next.js 14.2.3

✓ Starting...
✓ Ready in 3.3s
○ Compiling /api/questions ...
✓ Compiled /api/questions in 1012ms (162 modules)
An unexpected error occurred: RateLimitError: 429 You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.
at APIError.generate (webpack-internal:///(rsc)/./node_modules/openai/error.mjs:76:20)
at OpenAI.makeStatusError (webpack-internal:///(rsc)/./node_modules/openai/core.mjs:292:65)
at OpenAI.makeRequest (webpack-internal:///(rsc)/./node_modules/openai/core.mjs:335:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async strict_output (webpack-internal:///(rsc)/./src/lib/gpt.ts:33:26)
at async POST (webpack-internal:///(rsc)/./src/app/api/questions/route.ts:19:25)
at async C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:53446
at async e_.execute (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:44747)
at async e_.handle (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:54700)
at async doRender (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\base-server.js:1377:42)
at async cacheEntry.responseCache.get.routeKind (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\base-server.js:1599:28)
at async DevServer.renderToResponseWithComponentsImpl (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\base-server.js:1507:28)
at async DevServer.renderPageComponent (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\base-server.js:1924:24)
at async DevServer.renderToResponseImpl (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\base-server.js:1962:32)
at async DevServer.pipeImpl (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\base-server.js:920:25)
at async NextNodeServer.handleCatchallRenderRequest (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\next-server.js:272:17)
at async DevServer.handleRequestImpl (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\base-server.js:816:17)
at async C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\dev\next-dev-server.js:339:20
at async Span.traceAsyncFn (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\trace\trace.js:154:20)
at async DevServer.handleRequest (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\dev\next-dev-server.js:336:24)
at async invokeRender (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\lib\router-server.js:174:21)
at async handleRequest (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\lib\router-server.js:353:24)
at async requestHandlerImpl (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\lib\router-server.js:377:13)
at async Server.requestListener (C:\Users\nikhi\Desktop\quizmify\node_modules\next\dist\server\lib\start-server.js:141:13) {
status: 429,
headers: {
'alt-svc': 'h3=":443"; ma=86400',
'cf-cache-status': 'DYNAMIC',
'cf-ray': '88518b985b888ee8-BOM',
connection: 'keep-alive',
'content-length': '337',
'content-type': 'application/json; charset=utf-8',
date: 'Fri, 17 May 2024 06:28:04 GMT',
server: 'cloudflare',
'set-cookie': '__cf_bm=FOjWaSBx77Yv9U_aLRztYb3pda0dvNXMfAmnUjSDweo-1715927284-1.0.1.1-VNOElSqzMlpZ96E_7R7aTRFsNiH_yoCoCBnZaneXPG85gr1YZGAvv4P.2DQx1aYtOQvBoA9fekpYO.UyBeZm0A; path=/; expires=Fri, 17-May-24 06:58:04 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None, _cfuvid=s0QWyl_qf4QWuBrCGgcfTSrZdid35M9_Z4h8XIx3uuU-1715927284804-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None',
'strict-transport-security': 'max-age=15724800; includeSubDomains',
vary: 'Origin',
'x-request-id': 'req_e5869ba7a6d30fd18dbc6bbbe3084a06'
},
request_id: 'req_e5869ba7a6d30fd18dbc6bbbe3084a06',
error: {
message: 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.',
type: 'insufficient_quota',
param: null,
code: 'insufficient_quota'
},
code: 'insufficient_quota',
param: null,
type: 'insufficient_quota'
}
POST /api/questions 500 in 3895ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants