feat: init commint
This commit is contained in:
@@ -20,6 +20,7 @@ from apps.knowledge.services import retrieve_knowledge
|
||||
from apps.modelhub.models import ModelDeployment
|
||||
from apps.tickets.materials import SUPPORTED_EXTENSIONS
|
||||
from apps.tickets.models import (
|
||||
Ticket,
|
||||
TicketActorSource,
|
||||
TicketAttachment,
|
||||
TicketDraft,
|
||||
@@ -317,6 +318,8 @@ def serialize_draft(draft: TicketDraft, *, ticket_serializer=None) -> dict:
|
||||
"message_timeline": normalized_timeline,
|
||||
"missing_fields": draft.missing_fields,
|
||||
"questions": draft.questions,
|
||||
"blocking_missing_fields": draft.blocking_missing_fields,
|
||||
"blocking_questions": draft.blocking_questions,
|
||||
"guided_rounds": draft.guided_rounds,
|
||||
"agent_run_public_id": str(draft.latest_agent_run.public_id)
|
||||
if draft.latest_agent_run_id
|
||||
@@ -711,8 +714,8 @@ def _auto_create_ticket(
|
||||
TicketMessageTimelineItem.objects.filter(draft=draft).update(ticket=ticket)
|
||||
sync_ticket_missing_info_work_item(
|
||||
ticket,
|
||||
combined_missing_fields,
|
||||
questions=draft.questions,
|
||||
draft.blocking_missing_fields,
|
||||
questions=draft.blocking_questions,
|
||||
draft_public_id=str(draft.public_id),
|
||||
actor=draft.created_by,
|
||||
)
|
||||
@@ -730,6 +733,25 @@ def _auto_create_ticket(
|
||||
)
|
||||
audit_draft(draft, "draft_auto_created")
|
||||
complete_ticket_intake_failure_work_item(draft, actor=draft.created_by)
|
||||
ticket_id = ticket.id
|
||||
initiated_by_id = draft.created_by_id
|
||||
blocking_missing_fields = list(draft.blocking_missing_fields)
|
||||
blocking_questions = list(draft.blocking_questions)
|
||||
|
||||
def start_automation() -> None:
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from apps.tickets.automation import start_ticket_automation
|
||||
|
||||
actor = get_user_model().objects.filter(id=initiated_by_id).first()
|
||||
start_ticket_automation(
|
||||
Ticket.objects.get(id=ticket_id),
|
||||
initiated_by=actor,
|
||||
blocking_missing_fields=blocking_missing_fields,
|
||||
blocking_questions=blocking_questions,
|
||||
)
|
||||
|
||||
transaction.on_commit(start_automation)
|
||||
return draft
|
||||
|
||||
|
||||
@@ -803,10 +825,14 @@ def execute_draft_analysis(draft_id: int, run_id: int) -> None:
|
||||
fields = run.final_output.get("fields")
|
||||
missing_fields = run.final_output.get("missing_fields")
|
||||
questions = run.final_output.get("questions")
|
||||
blocking_missing_fields = run.final_output.get("blocking_missing_fields", [])
|
||||
blocking_questions = run.final_output.get("blocking_questions", [])
|
||||
if (
|
||||
not isinstance(fields, dict)
|
||||
or not isinstance(missing_fields, list)
|
||||
or not isinstance(questions, list)
|
||||
or not isinstance(blocking_missing_fields, list)
|
||||
or not isinstance(blocking_questions, list)
|
||||
):
|
||||
_mark_analysis_failed(
|
||||
draft,
|
||||
@@ -830,6 +856,11 @@ def execute_draft_analysis(draft_id: int, run_id: int) -> None:
|
||||
if raw_value and normalized_datetime is None and code not in missing_fields:
|
||||
missing_fields.append(code)
|
||||
missing_fields = [str(item) for item in missing_fields if str(item) in ALLOWED_FIELD_CODES]
|
||||
blocking_missing_fields = [
|
||||
str(item)
|
||||
for item in blocking_missing_fields
|
||||
if str(item) in ALLOWED_FIELD_CODES
|
||||
]
|
||||
source_corpus = " ".join(
|
||||
[
|
||||
draft.source_text,
|
||||
@@ -856,6 +887,11 @@ def execute_draft_analysis(draft_id: int, run_id: int) -> None:
|
||||
fields.update(manual_fields)
|
||||
missing_fields = [code for code in missing_fields if not fields.get(code)]
|
||||
questions = [str(item).replace("\r", " ").replace("\n", " ").strip() for item in questions]
|
||||
blocking_questions = [
|
||||
str(item).replace("\r", " ").replace("\n", " ").strip()
|
||||
for item in blocking_questions
|
||||
if str(item).strip()
|
||||
]
|
||||
field_evidence, confidence_by_field = _normalize_field_evidence(
|
||||
run.final_output.get("field_evidence")
|
||||
)
|
||||
@@ -884,6 +920,8 @@ def execute_draft_analysis(draft_id: int, run_id: int) -> None:
|
||||
"message_timeline": message_timeline,
|
||||
"missing_fields": missing_fields,
|
||||
"questions": questions,
|
||||
"blocking_missing_fields": blocking_missing_fields,
|
||||
"blocking_questions": blocking_questions,
|
||||
},
|
||||
created_by=draft.created_by,
|
||||
)
|
||||
@@ -895,6 +933,8 @@ def execute_draft_analysis(draft_id: int, run_id: int) -> None:
|
||||
draft.message_timeline = message_timeline
|
||||
draft.missing_fields = missing_fields
|
||||
draft.questions = questions
|
||||
draft.blocking_missing_fields = blocking_missing_fields
|
||||
draft.blocking_questions = blocking_questions
|
||||
draft.latest_artifact = artifact
|
||||
draft.status = "needs_input"
|
||||
draft.error_code = ""
|
||||
|
||||
Reference in New Issue
Block a user