#Help me please

103 messages · Page 1 of 1 (latest)

fast masonBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
limber osprey
#

Ok, we got half an error telling us absolutely nothing except that a server-side error occurred on what ever server you are trying to send a request to. What should we do now?

nova kelp
#

Context?

tiny panther
#

I use API With Open Ai

limber osprey
# tiny panther

Alright. We need to see the code for /app/api/conversation/ then

tiny panther
#

Give me another error

limber osprey
#

No, the code that handles the /api/conversation route

tiny panther
#

404

limber osprey
#

What?

viscid briar
#

i think he got 404 error code

tiny panther
limber osprey
#

Look

tiny panther
#

Give me another error

viscid briar
#

@tiny panther can we see /api/conversation route's code?

limber osprey
#

You have a Next.js app. This app consists of code. The route you are trying to request (/api/conversation) has code as well to handle the request you make to it. I want to see that code

tiny panther
#

Wait

limber osprey
#

I can't really ready any of that

#

Can you just copy and paste the code?

tiny panther
viscid briar
#

its really? please use discord on desktop...

#

that camera photo...

#

and we really cant see the routes

tiny panther
tiny panther
# limber osprey Can you just copy and paste the code?

import { auth } from '@clerk/nextjs';
import { NextResponse } from 'next/server';
import { Configuration, OpenAIApi } from 'openai'

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
})

const openai = new OpenAIApi(configuration)

export async function POST(
req: Request
) {
try {
const { userId } = auth()
const body = await req.json()
const { messages } = body

if (!userId) {
    return new NextResponse('Unauthorized', { status: 401 })
}

if (!configuration.apiKey) {
    return new NextResponse('OpenAI API Key not configured', { status: 
        500 })
}

if (!messages) {
    return new NextResponse('Messages are required', { status: 400 
    })
}

const response = await openai.createChatCompletion({
    model: 'gpt-3.5-turbo',
    messages
})

return NextResponse.json(response.data.choices[0].message)

} catch (error) {
console.log('[conversation_ERROR]', error)
return new NextResponse('Internal error', { status: 500 })
}
}

limber osprey
tiny panther
#

********** Page 2**********

viscid briar
#

you need use /api/conversation. if you get error code then openai not configured , or you got internal error. (see the code)

limber osprey
#

Wait a second

viscid briar
limber osprey
tiny panther
tiny panther
limber osprey
viscid briar
#

if the code got error you get error code 500

#

what the console says?

#

in browser

#

we need more information

tiny panther
limber osprey
# tiny panther

Show us the console output of the console you started the Next.js app with. So the one you typed npm run dev into

tiny panther
#

I use yarn

limber osprey
#

Then that

viscid briar
#

Man.

limber osprey
#

But there should be something inside your non-browser console

viscid briar
#

Its.

tiny panther
#

I see the problem in axios

limber osprey
#

Most likely starting with "[conversation_ERROR]"

limber osprey
#

axios is working fine

limber osprey
# tiny panther

I went on the hunt to find your console. Looks like you are rate limited form the API

#

So you made too many requests in a short time

viscid briar
#

you have try catch. In the try part have a bad code. We cant know wheres the problem. Its not problem of routing. We need to know what the output the response.data.choices[0].message.

#

yape.

#

its the try failed to running jumped to catch and you got response data to error code 500.

tiny panther
#

Look AxiosError

limber osprey
limber osprey
#

On the right side of your console, there are two windows. The top one is your actual console and it probably says "429"

viscid briar
#

my soul is broken now

#

first of all check in part of "try" check all variable, wheres is the error

#

wheres wrong

#

if you put the code github

#

i will help you

limber osprey
tiny panther
limber osprey
#

You are rate limited from the OpenAI API. Case closed, someone close this thread please

viscid briar
tiny panther
#

What do you mean

limber osprey
#

So they temporarily locked you out

#

You have to wait until they let you make requests again

#

There's no fix you can do from your side besides waiting

tiny panther
#

Because of this there is a 500 error

limber osprey
#

Yes

#

Because your try catch fails and therefore returns a 500 error

#

As you told it to

viscid briar
#

yes

tiny panther
limber osprey
tiny panther
#

If you use an account gmail new And I got a new API Will the problem open?

limber osprey
#

No, because your API key stays the same and that's the thing the API identifies you with

viscid briar
#

+1

limber osprey
#

Just wait. Eat something, watch a movie, whatever and then try again

rustic spear
#
  • 1
viscid briar
#

and have to chance you flooding the request to the api

tiny panther
rustic spear
#

pretty good solution if you ask me

tiny panther
#

what is true /api/conversation or /app/api/conversation

limber osprey
#

/api/conversation

tiny panther
#

Thank you my friend for you and your time zorty💪👌