#flask

20 messages · Page 1 of 1 (latest)

silent shuttle
#

I am having issues running the test app on the openai website, I am trying to configure my API keys so that I can use them in a simple python app.

The dependencies were installed but some were not I suppose.

Also how do I turn off the flask server? #1037561751362863144

silent shuttle
#

UPDATE: I was able to get the app runnin finally, the issue was with installing wrong packages. Once all the right packages were installed, the app started running fine, However, I am getting an internal server error.

Could this be because chatGPT is down?

#

@verbal cove sorry to tag you bro, but if you have any clues on how to deal with this..

verbal cove
#

Hey, it looks like you did not install the dependencies correctly, this probably is causing the error

verbal cove
silent shuttle
#

can i individually go through the list in requirements.txt to check if each one is installed correctly?

#

||Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/flask/app.py", line 2525, in wsgi_app response = self.full_dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^||
|| File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/flask/app.py", line 1822, in full_dispatch_request rv = self.handle_user_exception(e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^||
|| File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/flask/app.py", line 1820, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^||
|| File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/flask/app.py", line 1796, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^||
|| File "/Users/rohitgaikwad/Desktop/openai-quickstart-python/app.py", line 16, in index response = openai.Completion.create( ^^^^^^^^^^^^^^^^^^^^^^^^^||
|| File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/completion.py", line 25, in create return super().create(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^||
|| File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 149, in create ) = cls.__prepare_create_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^||
|| File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 106, in __prepare_create_request requestor = api_requestor.APIRequestor( ^^^^^^^^^^^^^^^^^^^^^^^^^^^||
|| File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_requestor.py", line 130, in __init__ self.api_key = key or util.default_api_key() ^^^^^^^^^^^^^^^^^^^^^^||
|| File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/util.py", line 186, in default_api_key raise openai.error.AuthenticationError( openai.error.AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>', or you can set the environment variable OPENAI_API_KEY=<API-KEY>). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'. You can generate API keys in the OpenAI web interface. See https://onboard.openai.com for details, or email support@openai.com if you have any questions.||

#

@verbal cove there is a lot going on , phew. I know its something to do with the API key, but i cant find those files that the error message mentions.

verbal cove
#

Looks like you didn't add an API key at all?

#

Where is your code for sending an OpenAI request?

silent shuttle
#

i did in the .env file and the app.py file

#

'import os
import openai
from dotenv import load_dotenv
load_dotenv()

from flask import Flask, redirect, render_template, request, url_for

app = Flask(name)
openai.api_key = os.getenv("J**************lbkFJfCT8MqCBTvE9N5NrZs7i")

@app.route("/", methods=("GET", "POST"))
def index():
if request.method == "POST":
animal = request.form["animal"]
response = openai.Completion.create(
model="text-davinci-003",
prompt=generate_prompt(animal),
temperature=0.6,
)
return redirect(url_for("index", result=response.choices[0].text))

result = request.args.get("result")
return render_template("index.html", result=result)

def generate_prompt(animal):
return """Suggest three names for an animal that is a superhero.

Animal: Cat
Names: Captain Sharpclaw, Agent Fluffball, The Incredible Feline
Animal: Dog
Names: Ruff the Protector, Wonder Canine, Sir Barks-a-Lot
Animal: {}
Names:""".format(
animal.capitalize()
)'

verbal cove
#

Can I see how you make the request tho? Did you set your api key with openai.api_key = "KEY"?

#

Yeah, looks like you didn't initialize the API

#

Setting the key should work!

silent shuttle
#

i did it here, where else?

#

openai.api_key = os.getenv("J**lbkFJfCT8MqCBTvE9N5NrZs7i")

verbal cove
#

Are you sure that's an OpenAI API key? OpenAI keys start with sk-

silent shuttle
#

youre right