-
Notifications
You must be signed in to change notification settings - Fork 12
/
app.py
43 lines (36 loc) · 1.1 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from flask import Flask, render_template, request, jsonify
import vertexai
from vertexai.language_models import ChatModel
import os
app = Flask(__name__)
PROJECT_ID = "tt-dev-001"
LOCATION = "us-central1"
vertexai.init(project=PROJECT_ID, location=LOCATION)
def create_session():
chat_model = ChatModel.from_pretrained("chat-bison@001")
chat = chat_model.start_chat()
return chat
def response(chat, message):
parameters = {
"temperature": 0.2,
"max_output_tokens": 256,
"top_p": 0.8,
"top_k": 40
}
result = chat.send_message(message, **parameters)
return result.text
@app.route('/')
def index():
return render_template('index.html')
@app.route('/palm2', methods=['GET', 'POST'])
def vertex_palm():
user_input = ""
if request.method == 'GET':
user_input = request.args.get('user_input')
else:
user_input = request.form['user_input']
chat_model = create_session()
content = response(chat_model,user_input)
return jsonify(content=content)
if __name__ == '__main__':
app.run(debug=True, port=8080, host='0.0.0.0')