corrected container and other errors

This commit is contained in:
Josako
2024-06-28 14:40:13 +02:00
parent 7a1b51dd0c
commit 9187947f68
105 changed files with 16882 additions and 2279 deletions

View File

@@ -21,7 +21,7 @@ from .document_forms import AddDocumentForm, AddURLForm, EditDocumentForm, EditD
from common.utils.middleware import mw_before_request
from common.utils.celery_utils import current_celery
from common.utils.nginx_utils import prefixed_url_for
from common.utils.view_assistants import form_validation_failed, prepare_table_for_macro
from common.utils.view_assistants import form_validation_failed, prepare_table_for_macro, form_to_dict
document_bp = Blueprint('document_bp', __name__, url_prefix='/document')
@@ -60,8 +60,9 @@ def add_document():
file = form.file.data
filename = secure_filename(file.filename)
extension = filename.rsplit('.', 1)[1].lower()
form_dict = form_to_dict(form)
new_doc, new_doc_vers = create_document_stack(form, file, filename, extension)
new_doc, new_doc_vers = create_document_stack(form_dict, file, filename, extension)
task = current_celery.send_task('create_embeddings', queue='embeddings', args=[
session['tenant']['id'],
@@ -90,6 +91,12 @@ def add_url():
current_app.logger.info(f'Adding document for tenant {session["tenant"]["id"]}')
url = form.url.data
doc_vers = DocumentVersion.query.filter_by(url=url).all()
if doc_vers:
current_app.logger.info(f'A document with url {url} already exists. No new document created.')
flash(f'A document with url {url} already exists. No new document created.', 'info')
return redirect(prefixed_url_for('document_bp.documents'))
# Only when no document with URL exists
html = fetch_html(url)
file = io.BytesIO(html)
@@ -101,8 +108,9 @@ def add_url():
if not filename.endswith('.html'):
filename += '.html'
extension = 'html'
form_dict = form_to_dict(form)
new_doc, new_doc_vers = create_document_stack(form, file, filename, extension)
new_doc, new_doc_vers = create_document_stack(form_dict, file, filename, extension)
task = current_celery.send_task('create_embeddings', queue='embeddings', args=[
session['tenant']['id'],
@@ -373,7 +381,7 @@ def create_document_stack(form, file, filename, extension):
new_doc = create_document(form, filename)
# Create the DocumentVersion
new_doc_vers = create_version_for_document(new_doc, form.url.data, form.language.data, form.user_context.data)
new_doc_vers = create_version_for_document(new_doc, form.get('url', ''), form['language'], form['user_context'])
try:
db.session.add(new_doc)
@@ -404,13 +412,13 @@ def log_session_state(session, msg=""):
def create_document(form, filename):
new_doc = Document()
if form.name.data == '':
if form['name'] == '':
new_doc.name = filename.rsplit('.', 1)[0]
else:
new_doc.name = form.name.data
new_doc.name = form['name']
if form.valid_from.data or form.valid_from.data != '':
new_doc.valid_from = form.valid_from.data
if form['valid_from'] and form['valid_from'] != '':
new_doc.valid_from = form['valid_from']
else:
new_doc.valid_from = dt.now(tz.utc)
new_doc.tenant_id = session['tenant']['id']

View File

@@ -430,7 +430,7 @@ def generate_chat_api_key():
db.session.rollback()
current_app.logger.error(f'Unable to store api key for tenant {tenant.id}. Error: {str(e)}')
return jsonify({'new_api_key': 'API key generated successfully.', 'api_key': new_api_key}), 200
return jsonify({'api_key': new_api_key}), 200
@user_bp.route('/tenant_overview', methods=['GET'])