corrected container and other errors
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
{% extends "base.html" %}
|
||||
{% from "macros.html" import render_field %}
|
||||
{% block title %}Update Document Language{% endblock %}
|
||||
{% block title %}Update Document Version{% endblock %}
|
||||
|
||||
{% block content_title %}Update Document Language{% endblock %}
|
||||
{% block content_description %}Update document language for {{ doc_details }}.{% endblock %}
|
||||
{% block content_title %}Update Document Version{% endblock %}
|
||||
{% block content_description %}Update document version for {{ doc_details }}.{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
@@ -13,6 +13,6 @@
|
||||
{% for field in form %}
|
||||
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||
{% endfor %}
|
||||
<button type="submit" class="btn btn-primary">Update Document</button>
|
||||
<button type="submit" class="btn btn-primary">Update Document Version</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
@@ -62,7 +62,14 @@
|
||||
{{ render_included_field(field, disabled_fields=license_fields, include_fields=license_fields) }}
|
||||
{% endfor %}
|
||||
<!-- Register API Key Button -->
|
||||
<button type="button" class="btn btn-primary" onclick="checkAndRegisterApiKey()">Register API Key</button>
|
||||
<button type="button" class="btn btn-primary" onclick="generateNewApiKey()">Register API Key</button>
|
||||
<!-- API Key Display Field -->
|
||||
<div id="api-key-field" style="display:none;">
|
||||
<label for="api-key">API Key:</label>
|
||||
<input type="text" id="api-key" class="form-control" readonly>
|
||||
<button type="button" id="copy-button" class="btn btn-primary">Copy to Clipboard</button>
|
||||
<p id="copy-message" style="display:none;color:green;">API key copied to clipboard</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- HTML Chunking Settings Tab -->
|
||||
<div class="tab-pane fade" id="html-chunking-tab" role="tabpanel">
|
||||
@@ -89,26 +96,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!-- Modal HTML -->
|
||||
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="confirmModalLabel">Confirm New API Key</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body" id="modal-body-content">
|
||||
Are you sure you want to register a new API key? This will replace the existing key.
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" id="confirmNewKeyBtn">Confirm</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -118,78 +105,88 @@
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
function checkAndRegisterApiKey() {
|
||||
// First, check if an API key already exists
|
||||
$.ajax({
|
||||
url: '/user/check_chat_api_key',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
if (response.api_key_exists) {
|
||||
$('#confirmModal').modal('show');
|
||||
} else {
|
||||
generateNewApiKey();
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
alert('Error checking API key: ' + error.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('confirmNewKeyBtn').addEventListener('click', function () {
|
||||
generateNewApiKey();
|
||||
});
|
||||
|
||||
function generateNewApiKey() {
|
||||
$.ajax({
|
||||
url: '/user/generate_chat_api_key',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
$('#modal-body-content').html(`
|
||||
<p>New API key generated: <span id="new-api-key">${response.api_key}</span></p>
|
||||
<button class="btn btn-primary" onclick="copyToClipboard('#new-api-key')">Copy to Clipboard</button>
|
||||
<p id="copy-message" style="display:none;color:green;">API key copied to clipboard</p>
|
||||
`);
|
||||
$('#confirmNewKeyBtn').hide();
|
||||
$('.btn-secondary').text('OK');
|
||||
},
|
||||
error: function(error) {
|
||||
alert('Error generating new API key: ' + error.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function copyToClipboard(element) {
|
||||
const text = $(element).text();
|
||||
navigator.clipboard.writeText(text).then(function() {
|
||||
$('#copy-message').show().delay(2000).fadeOut();
|
||||
}).catch(function(error) {
|
||||
alert('Failed to copy text: ' + error);
|
||||
function generateNewApiKey() {
|
||||
$.ajax({
|
||||
url: '/user/generate_chat_api_key',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
success: function(response) {
|
||||
$('#api-key').val(response.api_key);
|
||||
$('#api-key-field').show();
|
||||
},
|
||||
error: function(error) {
|
||||
alert('Error generating new API key: ' + error.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
// JavaScript to detect user's timezone
|
||||
document.addEventListener('DOMContentLoaded', (event) => {
|
||||
// Detect timezone
|
||||
const userTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
|
||||
// Send timezone to the server via a POST request
|
||||
fetch('/set_user_timezone', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ timezone: userTimezone })
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
console.log('Timezone sent to server successfully');
|
||||
} else {
|
||||
console.error('Failed to send timezone to server');
|
||||
}
|
||||
});
|
||||
function copyToClipboard(selector) {
|
||||
const element = document.querySelector(selector);
|
||||
if (element) {
|
||||
const text = element.value;
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(text).then(function() {
|
||||
showCopyMessage();
|
||||
}).catch(function(error) {
|
||||
alert('Failed to copy text: ' + error);
|
||||
});
|
||||
} else {
|
||||
fallbackCopyToClipboard(text);
|
||||
}
|
||||
} else {
|
||||
console.error('Element not found for selector:', selector);
|
||||
}
|
||||
}
|
||||
|
||||
function fallbackCopyToClipboard(text) {
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = text;
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
showCopyMessage();
|
||||
} catch (err) {
|
||||
alert('Fallback: Oops, unable to copy', err);
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
|
||||
function showCopyMessage() {
|
||||
const message = document.getElementById('copy-message');
|
||||
if (message) {
|
||||
message.style.display = 'block';
|
||||
setTimeout(function() {
|
||||
message.style.display = 'none';
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('copy-button').addEventListener('click', function() {
|
||||
copyToClipboard('#api-key');
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
// JavaScript to detect user's timezone
|
||||
document.addEventListener('DOMContentLoaded', (event) => {
|
||||
// Detect timezone
|
||||
const userTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
|
||||
// Send timezone to the server via a POST request
|
||||
fetch('/set_user_timezone', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ timezone: userTimezone })
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
console.log('Timezone sent to server successfully');
|
||||
} else {
|
||||
console.error('Failed to send timezone to server');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -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']
|
||||
|
||||
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user