-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.py
31 lines (26 loc) · 1.04 KB
/
index.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
from llama_index import GPTSimpleVectorIndex, LLMPredictor, PromptHelper
from langchain import OpenAI
import flask
from flask import request, jsonify
from flask_cors import CORS
max_input_size = 3700
num_outputs = 300
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
prompt_helper = PromptHelper.from_llm_predictor(llm_predictor)
app = flask.Flask(__name__)
CORS(app)
index = GPTSimpleVectorIndex.load_from_disk('index.json')
@app.route('/ask', methods=['GET'])
def ask():
history = request.args.get('history')
query = ''
if history == 'none':
query = 'System:\n' + 'You a Yearn Finance assistant.\n\n' + 'Anon:\n' + request.args.get('query') + '\n\nAI:\n'
else:
query = history + '\n\n' + 'Anon:\n' + request.args.get('query') + '\n\nAI:\n'
print(query)
response = index.query(query, response_mode="default", prompt_helper=prompt_helper)
print(response.response.strip())
return jsonify(response.response.strip())
def create_app():
return app