-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Javascript documented in JSDoc format * Added context close button * Comments * Added PDF view window * Added pdf navigations buttons * PDF display improve * Added delay to submitSettingsToServer() function * v2 applied to arch-ru & seus small fixes css cleaning python cleaning
- Loading branch information
Showing
31 changed files
with
831 additions
and
2,053 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,4 @@ data/ | |
.gitignore | ||
node_modules/ | ||
*.log | ||
*.pyc | ||
python_script/cleanpdf.py | ||
python_script/docxtopdf.py | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,110 @@ | ||
import os | ||
import sys | ||
|
||
from flask import Flask, render_template, request, jsonify, send_from_directory | ||
arch_ru_app = Flask(__name__) | ||
|
||
|
||
sys.path.append(os.path.join(os.path.dirname(__file__), 'python_script')) | ||
from parameters import load_config | ||
|
||
################### | ||
### LOAD CONFIG ### | ||
################### | ||
load_config('arch_ru') | ||
from parameters import CHROMA_ROOT_PATH, EMBEDDING_MODEL, LLM_MODEL, PROMPT_TEMPLATE, DATA_PATH | ||
global DATA_PATH | ||
load_config('arch-ru') | ||
from parameters import CHROMA_ROOT_PATH, EMBEDDING_MODEL, LLM_MODEL, PROMPT_TEMPLATE, DATA_PATH, REPHRASING_PROMPT, STANDALONE_PROMPT, ROUTER_DECISION_PROMPT | ||
from get_llm_function import get_llm_function | ||
from get_rag_chain import get_rag_chain | ||
from ConversationalRagChain import ConversationalRagChain | ||
|
||
rag_conv = ConversationalRagChain.from_llm( | ||
rag_chain=get_rag_chain(), | ||
llm=get_llm_function(LLM_MODEL), | ||
callbacks=None | ||
) | ||
arch_ru_app = Flask(__name__) | ||
|
||
arch_ru_app.config['UPLOAD_FOLDER'] = DATA_PATH | ||
root = "arch-ru" | ||
|
||
|
||
@arch_ru_app.route("/") | ||
def index(): | ||
return render_template('arch_ru_index.html', root=root) | ||
|
||
|
||
def init_app(): | ||
load_rag() | ||
arch_ru_app.config['UPLOAD_FOLDER'] = DATA_PATH | ||
|
||
|
||
def load_rag(settings = None): | ||
global rag_conv | ||
if settings is None : | ||
rag_conv = ConversationalRagChain.from_llm( | ||
rag_chain=get_rag_chain(), | ||
llm=get_llm_function(model_name = LLM_MODEL), | ||
callbacks=None | ||
) | ||
else: | ||
rag_conv = ConversationalRagChain.from_llm( | ||
rag_chain=get_rag_chain(settings), | ||
llm=get_llm_function(model_name = settings["llm_model"]), | ||
callbacks=None | ||
) | ||
|
||
|
||
# Route to get the document list | ||
@arch_ru_app.route('/documents', methods=['GET']) | ||
def list_documents(): | ||
files = os.listdir(arch_ru_app.config['UPLOAD_FOLDER']) | ||
documents = [{"name": f, "url": f"/arch-ru/files/{f}", "extension":os.path.splitext(f)[1][1:]} for f in files] | ||
documents = [{"name": f, "url": f"/{root}/files/{f}", "extension": os.path.splitext(f)[1][1:]} for f in files] | ||
return jsonify(documents) | ||
|
||
|
||
# Route to get a single document | ||
@arch_ru_app.route('/documents/<document_name>', methods=['GET']) | ||
def get_document(document_name): | ||
files = os.listdir(arch_ru_app.config['UPLOAD_FOLDER']) | ||
documents = [{"name": f, "url": f"/{root}/files/{f}", "extension": os.path.splitext(f)[1][1:]} for f in files] | ||
|
||
document = next((doc for doc in documents if doc["name"] == document_name), None) | ||
|
||
if document is None: | ||
return jsonify({'error': 'Document not found'}), 404 | ||
|
||
return jsonify(document) | ||
|
||
# Route to show the pdf | ||
@arch_ru_app.route('/files/<filename>', methods=['GET']) | ||
def serve_file(filename): | ||
return send_from_directory(arch_ru_app.config['UPLOAD_FOLDER'], filename) | ||
|
||
@arch_ru_app.route("/") | ||
def index(): | ||
return render_template('arch_ru_index.html') | ||
|
||
|
||
@arch_ru_app.route("/get", methods=["POST"]) | ||
def chat(): | ||
msg = request.form.get("msg","") | ||
input_query = msg | ||
return get_Chat_response(input_query) | ||
|
||
data = request.get_json() | ||
msg = data.get("msg", "") | ||
return get_Chat_response(msg) | ||
|
||
def get_Chat_response(query): | ||
inputs = {"query": str(query)} | ||
inputs = { | ||
"query": str(query), | ||
"chat_history": [] | ||
} | ||
res = rag_conv._call(inputs) | ||
|
||
output = jsonify({ | ||
'response': res['result'], | ||
'context': res['context'], | ||
'source': res['source'] | ||
'metadatas': res['metadatas'] | ||
}) | ||
return output | ||
|
||
|
||
|
||
@arch_ru_app.route('/update-settings', methods=['POST']) | ||
def update_settings(): | ||
data = request.get_json() | ||
load_rag(settings=data) | ||
return jsonify({'status': 'success', 'message': 'Settings updated successfully'}), 200 | ||
|
||
|
||
@arch_ru_app.route('/clear_chat_history', methods=['POST']) | ||
def clear_chat_history(): | ||
rag_conv.clear_chat_history() | ||
return jsonify({"status": "success"}), 200 | ||
|
||
|
||
if __name__ == '__main__': | ||
arch_ru_app.run(port=6667,debug=False) | ||
init_app() | ||
arch_ru_app.run(port=6667,debug=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.