callcenter 프로젝트 완료
- 상담 기록 분석 및 요약 - 상담 기록 db 저장 - 상담 평가 - 상담 평가 db 저장
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
from backend.ai.llm import hugging_llm
|
||||
from langchain_core.prompts import ChatPromptTemplate
|
||||
from backend.prompts.all_prompt import SUMMARY_SYSTEM_PROMPT
|
||||
from backend.repository.models import CallHistory
|
||||
from backend.schemas.summary_schema import CallSummary, CallCreate
|
||||
from backend.prompts.all_prompt import SUMMARY_SYSTEM_PROMPT, CALL_EVALUATION_PROMPT
|
||||
from backend.repository.models import CallHistory, CallEvaluation
|
||||
from backend.schemas.summary_schema import CallSummary, CallCreate, CallEvaluationResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from backend.schemas.summary_schema import CallRequest
|
||||
@@ -41,15 +41,51 @@ def save_call_history(db, data):
|
||||
|
||||
return history
|
||||
|
||||
def evaluate_call():
|
||||
def evaluate_call(transcript:str):
|
||||
"""상담 평가"""
|
||||
structured_llm = hugging_llm.with_structured_output(CallEvaluationResponse)
|
||||
prompt = ChatPromptTemplate.from_template(CALL_EVALUATION_PROMPT)
|
||||
|
||||
pass
|
||||
chain = prompt | structured_llm
|
||||
return chain.invoke({"transcript":transcript})
|
||||
|
||||
def save_call_evaluation():
|
||||
def calculate_score(evaluation):
|
||||
score = 0
|
||||
|
||||
if evaluation.identity_verification:
|
||||
score += 25
|
||||
|
||||
if evaluation.empathy:
|
||||
score += 25
|
||||
|
||||
if evaluation.issue_resolution:
|
||||
score += 25
|
||||
|
||||
if evaluation.survey_guidance:
|
||||
score += 25
|
||||
|
||||
return score
|
||||
|
||||
def save_call_evaluation(db:Session, call_id:int, evaluation:CallEvaluationResponse):
|
||||
"""상담 평가 내용 저장"""
|
||||
score = calculate_score(evaluation)
|
||||
|
||||
entity = CallEvaluation(
|
||||
call_id = call_id,
|
||||
identity_verification = evaluation.identity_verification,
|
||||
identity_verification_reason = evaluation.identity_verification_reason,
|
||||
empathy = evaluation.empathy,
|
||||
empathy_reason = evaluation.empathy_reason,
|
||||
issue_resolution = evaluation.issue_resolution,
|
||||
issue_resolution_reason = evaluation.issue_resolution_reason,
|
||||
survey_guidance = evaluation.survey_guidance,
|
||||
survey_guidance_reason = evaluation.survey_guidance_reason,
|
||||
score = score,
|
||||
)
|
||||
db.add(entity)
|
||||
db.commit()
|
||||
db.refresh(entity)
|
||||
|
||||
pass
|
||||
|
||||
def create_call_history(req: CallRequest, db:Session):
|
||||
# 요약
|
||||
@@ -66,7 +102,19 @@ def create_call_history(req: CallRequest, db:Session):
|
||||
customer_issue = summary.customer_issue,
|
||||
resolution = summary.resolution
|
||||
)
|
||||
history = save_call_history(db = db, data = call_data)
|
||||
|
||||
return save_call_history(db = db, data = call_data)
|
||||
|
||||
# 상담 평가
|
||||
evaluation = evaluate_call(req.transcript)
|
||||
# 평가 저장
|
||||
save_call_evaluation(db = db, call_id=history.call_id, evaluation=evaluation)
|
||||
|
||||
return CallSummary(
|
||||
summary=summary.summary,
|
||||
keywords=summary.keywords,
|
||||
category=summary.category,
|
||||
sentiment=summary.sentiment,
|
||||
action_items=summary.action_items,
|
||||
customer_issue=summary.customer_issue,
|
||||
resolution=summary.resolution,
|
||||
)
|
||||
Reference in New Issue
Block a user