- Created a new eveai_chat plugin to support the new dynamic possibilities of the Specialists. Currently only supports standard Rag retrievers (i.e. no extra arguments).
This commit is contained in:
@@ -13,6 +13,7 @@ import json
|
||||
|
||||
from common.models.document import Document, DocumentVersion, Catalog, Retriever, Processor
|
||||
from common.extensions import db
|
||||
from common.models.interaction import Specialist, SpecialistRetriever
|
||||
from common.utils.document_utils import validate_file_type, create_document_stack, start_embedding_task, process_url, \
|
||||
edit_document, \
|
||||
edit_document_version, refresh_document
|
||||
@@ -663,6 +664,8 @@ def handle_library_selection():
|
||||
action = request.form['action']
|
||||
|
||||
match action:
|
||||
case 'create_default_rag_library':
|
||||
create_default_rag_library()
|
||||
case 're_embed_latest_versions':
|
||||
re_embed_latest_versions()
|
||||
case 'refresh_all_documents':
|
||||
@@ -671,6 +674,86 @@ def handle_library_selection():
|
||||
return redirect(prefixed_url_for('document_bp.library_operations'))
|
||||
|
||||
|
||||
def create_default_rag_library():
|
||||
# Check if no catalog exists. If non exists, no processors, retrievers or specialist can exists
|
||||
catalogs = Catalog.query.all()
|
||||
if catalogs:
|
||||
flash("Default RAG Library can only be created if no catalogs are defined!", 'danger')
|
||||
return redirect(prefixed_url_for('document_bp.library_operations'))
|
||||
|
||||
timestamp = dt.now(tz=tz.utc)
|
||||
try:
|
||||
cat = Catalog(
|
||||
name='Default RAG Catalog',
|
||||
description='Default RAG Catalog',
|
||||
type="STANDARD_CATALOG",
|
||||
min_chunk_size=2000,
|
||||
max_chunk_size=3000,
|
||||
)
|
||||
set_logging_information(cat, timestamp)
|
||||
|
||||
db.session.add(cat)
|
||||
db.session.commit()
|
||||
|
||||
proc = Processor(
|
||||
name='Default HTML Processor',
|
||||
description='Default HTML Processor',
|
||||
catalog_id=cat.id,
|
||||
type="HTML Processor",
|
||||
configuration={
|
||||
"html_tags": "p, h1, h2, h3, h4, h5, h6, li, table, thead, tbody, tr, td",
|
||||
"html_end_tags": "p, li, table",
|
||||
"html_excluded_classes": "",
|
||||
"html_excluded_elements": "header, footer, nav, script",
|
||||
"html_included_elements": "article, main"
|
||||
}
|
||||
)
|
||||
set_logging_information(proc, timestamp)
|
||||
|
||||
retr = Retriever(
|
||||
name='Default RAG Retriever',
|
||||
description='Default RAG Retriever',
|
||||
catalog_id=cat.id,
|
||||
type="STANDARD_RAG",
|
||||
configuration={
|
||||
"es_k": "8",
|
||||
"es_similarity_threshold": 0.3
|
||||
}
|
||||
)
|
||||
set_logging_information(retr, timestamp)
|
||||
|
||||
db.session.add(proc)
|
||||
db.session.add(retr)
|
||||
db.session.commit()
|
||||
|
||||
spec = Specialist(
|
||||
name='Default RAG Specialist',
|
||||
description='Default RAG Specialist',
|
||||
type='STANDARD_RAG',
|
||||
configuration={"temperature": "0.3", "specialist_context": "To be specified"}
|
||||
)
|
||||
set_logging_information(spec, timestamp)
|
||||
|
||||
db.session.add(spec)
|
||||
db.session.commit()
|
||||
|
||||
spec_retr = SpecialistRetriever(
|
||||
specialist_id=spec.id,
|
||||
retriever_id=retr.id,
|
||||
)
|
||||
|
||||
db.session.add(spec_retr)
|
||||
db.session.commit()
|
||||
|
||||
except SQLAlchemyError as e:
|
||||
db.session.rollback()
|
||||
flash(f'Failed to create Default RAG Library. Error: {e}', 'danger')
|
||||
current_app.logger.error(f'Failed to create Default RAG Library'
|
||||
f'for tenant {session['tenant']['id']}. Error: {str(e)}')
|
||||
|
||||
return redirect(prefixed_url_for('document_bp.library_operations'))
|
||||
|
||||
|
||||
@document_bp.route('/document_versions_list', methods=['GET'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
def document_versions_list():
|
||||
|
||||
Reference in New Issue
Block a user