Openai with Python Anywhere update.
Source code here...
from flask import Flask
import openai
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def chatbot():
# Set up the OpenAI API client
openai.api_key = "***************************************"
# Set up the model and prompt
model_engine = "text-davinci-003"
prompt = "Hello, how are you today?"
# Generate a response
completion = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
response = completion.choices[0].text
print(response)
Bash
Well I started a Bash console and the made a virtual environment with Python 10.
$ mkvirtualenv my-virtualenv --python=python3.10
Then I did a pip install openai.
Successfully installed aiohttp-3.8.4 aiosignal-1.3.1 async-timeout-4.0.2 attrs-23.1.0 certifi-2022.12.7 charset-normalizer-3.1.0 frozenlist-1.3.3 idna-3.4 multidict-6.0.4 openai-0.27.6 requests-2.2
Then I ran the command:
python path/to/mysite/flask_app.py
and it came back with no errors
Code Editor
I left the bash console and went back to the source code and refreshed/ran the code again and I am still getting an error posted below.
import openai
ModuleNotFoundError: No module named 'openai'
Any Thoughts?