I'm trying to run a python script to interact with openai API on my website (I'm looking to embed completions within a web app I have).
At the moment - I'm simply trying to get the code to run without anything other than the.py script.
I have this code on a file called script.py in my hosted (apache server) website. I visit it by going to www.nessify.co.uk/cgi-bin/script.py :
#!/usr/bin/env python2
import os
import openai
openai.api_key = os.getenv("API_KEY")
response = openai.Completion.create(
model="text-davinci-003",
prompt="List 10 science fiction books:",
temperature=0.5,
max_tokens=200,
top_p=1,
frequency_penalty=0.52,
presence_penalty=0.5,
stop=["11."]
)
print("Content-type: text/html\n")
print("<html><body>")
print("<h1>Current Date and Time</h1>")
print("<p>", response,"</p>")
print("</body></html>")
I'm expecting a list of books to be outputed onto a webpage.
But - Get these errors in the console:
and then
Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received.
I can't see why it doesn't work.
I have run other python on the script.py file (that does simple maths) and it executes - so I know the server is running the script ok...
sussed it thanks to a hint from @John Gordon.
error log says:
The error log says this: nessify.co.uk [Sun Jan 29 17:57:00 2023] [error] [client 40.77.167.52:0] AH01215: ImportError: No module named openai: /home/cluster-sites/5/n/nessify.co.uk/public_html/cgi-bin/script.py - the module isn't there
The module isn't there...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.