#API isn't responding

27 messages · Page 1 of 1 (latest)

candid mason
#

Hi. I'm trying to put a little chat service in my website but it doesn't show respond (from API) but only shows text user puts. I'm not sure what should I fix from here. Am I approaching in a wrong way?

prisma meteor
#

This API endpoint doesn't exist

#

and then you'd pass the model, in your case, text-davinci-003 as a param named model in the POST req

warm ivy
candid mason
#

Appreciate for comments. @warm ivy @prisma meteor I edited that way, however, I got this error. I copied and pasted my API key so my API key is not wrong. https://beta.openai.com/account/api-keys it says API keys have never been used. Am I putting request in a wrong way?

sick forum
#

You really should delete your photo @candid mason

#

For obvious reasons

#

Also, you're not putting in the API key correctly

#

Why are you using requests? OpenAI has a python module to do all the heavy lifting for you

#

Lastly, exposing your API key in your JavaScript file is a surefire way to get yourself banned, or maxed out

#

Please, I'm not being over the top. Do not ever put your API key somewhere that can be read. It's like taping your key to the front door

#

Change the JS code to send a request to a backend server such as Flask. Get rid of your python code as well, use the OpenAI module "import openai". You can then set your key properly with openai.api_key = ""

#

If you are hellbent on using requests - there's no immediate benefits but whatever, you need to include the API key in your header, not in the JSON data

warm ivy
#

Python code

#
import openai

openai.api_key = "sp-TCCYbWOYsENTERYOUKEYFJcADpWRhkMPDkfpeca1xv"

def talk_with_model(prompt, filter_level=None):
    if filter_level == "off":
        prompt = "filter=off" + prompt
    elif filter_level == "low":
        prompt = "filter=low" + prompt
    completions = openai.Completion.create(
        model="text-davinci-003",
        prompt=prompt,
        max_tokens=2048,
        n=1,
        stop=None,
        temperature=0.5,
    )
    message = completions.choices[0].text
    return message.strip()

while True:
    user_input = input("You: ")
    if user_input == "exit":
        break
    elif user_input == "vulgar":
        filter_level = "off"
    elif user_input == "clean":
        filter_level = "low"
    else:
        filter_level = None
    response = talk_with_model(user_input, filter_level)
    print("ChatGPT: ",response)
sick forum
#

For the love of security can y'all stop posting your API keys

sick forum
#

Your key is in the code @warm ivy

warm ivy
#

im silly but not that silly

sick forum
#

Ok thank goodness

#

The first guy unfortunately didn't get the memo

warm ivy
prisma meteor
#

@candid mason I’ve deleted your image that had an API key in it

sick forum
#

@warm ivy thank you for the kind words