Skip to content

Instantly share code, notes, and snippets.

@EnkrateiaLucca
Created May 7, 2023 12:14
Show Gist options
  • Save EnkrateiaLucca/f67cf1458fa92245849bb4f2e0c32c0f to your computer and use it in GitHub Desktop.
Save EnkrateiaLucca/f67cf1458fa92245849bb4f2e0c32c0f to your computer and use it in GitHub Desktop.
Learning app
from flask import Flask, render_template, request
import openai
import os
# Set up the API key
openai.api_key = "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"
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
topic = request.form['topic']
system_profile = "You are an AI trained to provide helpful examples on various topics and concepts."
prompt_question = f"Provide a variety of examples for the concept of {topic}."
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": system_profile},
{"role": "user", "content": prompt_question},
]
)
examples = response["choices"][0]["message"]["content"]
return render_template('index.html', examples=examples)
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment