«Собачий бизнес» или как у нас со смекалкой?
Александр
bash
sudo apt-get update
sudo apt-get install python3
sudo apt-get install python3-pip
bash
python3 -m venv myenv
source myenv/bin/activate
bash
pip install flask
pip install openai
python
from flask import Flask, request, render_template
import openai
app = Flask(__name__)
# Установите ваш API-ключ GPT-3 здесь
openai.api_key = 'ВАШ_API_КЛЮЧ'
@app.route('/')
def index():
return render_template('index.html')
@app.route('/ask', methods=['POST'])
def ask():
user_input = request.form['user_input']
response = openai.Completion.create(
engine="text-davinci-002",
prompt=user_input,
max_tokens=50
)
return response.choices[0].text
if __name__ == '__main__':
app.run()
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat Interface</title>
</head>
<body>
<h1>Chat with GPT-3</h1>
<form method="POST" action="/ask">
<input type="text" name="user_input" placeholder="Ask a question...">
<button type="submit">Send</button>
</form>
<div id="chat"></div>
</body>
</html>
bash
python app.py