Skip to content

Added GPT-3.5-turbo support #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ def index():
result = request.args.get("result")
return render_template("index.html", result=result)

# run on model gpt-3.5-turbo
@app.route("/turbo", methods=("GET", "POST"))
def turbo():
if request.method == "POST":
animal = request.form["animal"]
response = openai.ChatCompletion.create( #Needs OpenAI 0.27 above )
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a expert in zoology"},
{"role": "assistant", "content": "Suggest three names for an animal that is a superhero."},
{"role": "user", "content": "Cat"},
{"role": "assistant", "content": "Captain Sharpclaw, Agent Fluffball, The Incredible Feline"},
{"role": "user", "content": "Dog"},
{"role": "assistant", "content": "Ruff the Protector, Wonder Canine, Sir Barks-a-Lot"},
{"role": "user", "content": animal},
]
)
return redirect(url_for("turbo", result=response['choices'][0]['message']['content']))

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


def generate_prompt(animal):
return """Suggest three names for an animal that is a superhero.
Expand Down
21 changes: 21 additions & 0 deletions templates/index-turbo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<head>
<title>OpenAI Quickstart</title>
<link
rel="shortcut icon"
href="{{ url_for('static', filename='dog.png') }}"
/>
<link rel="stylesheet" href="{{ url_for('static', filename='main.css') }}" />
</head>

<body>
<img src="{{ url_for('static', filename='dog.png') }}" class="icon" />
<h3>Name my pet</h3>
<form action="/turbo" method="post">
<input type="text" name="animal" placeholder="Enter an animal" required />
<input type="submit" value="Generate names" />
</form>
{% if result %}
<div class="result">{{ result }}</div>
{% endif %}
</body>