mirror of
https://github.com/wassname/stampy-chat.git
synced 2026-09-25 14:10:17 +08:00
semantic search working in flask
This commit is contained in:
+24
-6
@@ -1,13 +1,31 @@
|
||||
from flask import Flask, jsonify
|
||||
from flask import Flask, jsonify, request
|
||||
from flask_cors import CORS, cross_origin
|
||||
from get_blocks import get_top_k_blocks
|
||||
import dataclasses
|
||||
import os
|
||||
import openai
|
||||
|
||||
app = Flask(__name__)
|
||||
cors = CORS(app)
|
||||
app.config['CORS_HEADERS'] = 'Content-Type'
|
||||
|
||||
# -------------------------------- general setup -------------------------------
|
||||
|
||||
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
|
||||
openai.api_key = OPENAI_API_KEY
|
||||
|
||||
# ------------------------------- semantic search ------------------------------
|
||||
|
||||
@app.route('/semantic', methods=['POST'])
|
||||
@cross_origin()
|
||||
def semantic():
|
||||
query = request.json['query']
|
||||
return jsonify([dataclasses.asdict(block) for block in get_top_k_blocks(query)])
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return jsonify({"general kenobi": "hello there"})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port=5000)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__': app.run(debug=True, port=3000)
|
||||
|
||||
Reference in New Issue
Block a user