If your work has blocked ChatGPT then you can use this python script to get around it.
Install python3 3.8+ and flask using pip3 install flask and pip3 install openai
# Code as follows
from flask import Flask, request, render_template_string
import openai
# Replace ‘your-api-key’ with your actual OpenAI API key
openai.api_key = ‘xxx’
app = Flask(__name__)
conversation_history = [{“role”: “system”, “content”: “You are a helpful assistant.”}]
def ask_chatgpt(messages):
response = openai.ChatCompletion.create(
model=”gpt-3.5-turbo”,
messages=messages
)
return response[‘choices’][0][‘message’][‘content’].strip()
@app.route(“/”, methods=[“GET”, “POST”])
def index():
global conversation_history
answer = “”
if request.method == “POST”:
question = request.form[“question”]
use_context = request.form.get(“use_context”)
if use_context == “no”:
# Reset the conversation history except the system message
conversation_history = [{“role”: “system”, “content”: “You are a helpful assistant.”}]
conversation_history.append({“role”: “user”, “content”: question})
answer = ask_chatgpt(conversation_history)
conversation_history.append({“role”: “assistant”, “content”: answer})
return render_template_string(TEMPLATE, answer=answer)
TEMPLATE = “””
Ask a question
{% if answer %}
Answer:
{% endif %}
“””
if __name__ == “__main__”:
app.run(debug=True)