You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
4.0 KiB
99 lines
4.0 KiB
package echomeet
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
"yunyan/pb"
|
|
"encoding/json"
|
|
)
|
|
|
|
// @Summary 会议记录智能总结
|
|
// @Description 按指定模板和语言对已有会议记录进行翻译与 AI 总结
|
|
// @Tags Echomeet
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param user body pb.EchomeetSummaryReq true "请求数据"
|
|
// @Success 200 {object} comm.HttpResult{data=pb.EchomeetAddRecordResp} "响应数据"
|
|
// @Router /api/home/echomeet_summary [post]
|
|
func (this *apiComp) Summary(session comm.IUserSession, req *pb.EchomeetSummaryReq) (resp *pb.EchomeetAddRecordResp, errdata *pb.ErrorData) {
|
|
var (
|
|
model *pb.DBEchoMeetRecord
|
|
err error
|
|
)
|
|
if model, err = this.module.model.getrecord(req.Id); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
// 确定目标语言
|
|
language := model.Tolanguage
|
|
if req.Tolanguage != "" {
|
|
language = req.Tolanguage
|
|
}
|
|
// 确定模板:tid 优先,其次 req.Templateid,最后沿用记录中的 templateid
|
|
tid := req.Tid
|
|
templateid := req.Templateid
|
|
if tid == "" && templateid == 0 {
|
|
templateid = model.Templateid
|
|
}
|
|
// templateid 是某一语种的主键,按主键查到的还是原语种模板。
|
|
// 仅公共模板(id<起点)有多语言版本,切换语言时通过 tid 反查对应版本;
|
|
// 私有模板(id>=起点)单条、无多语言版本,保持按主键解析,不反查 tid。
|
|
if tid == "" && templateid != 0 && templateid < templatePrivateIdStart {
|
|
if base, berr := this.module.cache.GetTemplateForId(templateid); berr == nil && base.Tid != "" {
|
|
tid = base.Tid
|
|
}
|
|
}
|
|
tmpl, err := this.module.cache.ResolveTemplate(tid, templateid, language)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_TemplateNotFound,
|
|
Message: "模板不存在或不支持该语言",
|
|
}
|
|
return
|
|
}
|
|
model.Templateid = tmpl.Id
|
|
// 选定服务商:请求显式指定优先,否则沿用记录已有的服务商,再否则按配置默认/语言路由。
|
|
// translate 与 AI 总结都会走这个服务商。
|
|
svc := req.ServiceType
|
|
if svc == pb.TranscribeService_TranscribeService_Unknown || svc == pb.TranscribeService_TranscribeService_Auto {
|
|
svc = model.ServiceType
|
|
}
|
|
model.ServiceType = this.module.providers.ResolveServiceType(svc, model.Formlanguage)
|
|
// 总结所用文本大模型:客户端显式指定则更新,否则沿用记录已有(为空再回退默认)。
|
|
if req.SummaryModel != "" {
|
|
model.SummaryModel = req.SummaryModel
|
|
} else if model.SummaryModel == "" {
|
|
model.SummaryModel = this.module.providers.DefaultSummaryId()
|
|
}
|
|
this.module.Infof("Summary id:%d → service:%s summaryModel:%s", model.Id, ServiceTypeName(model.ServiceType), model.SummaryModel)
|
|
// 是否需要重新翻译:
|
|
// - 客户端显式传入 tolanguage(重新总结操作,强制重译以保证 Translate 与 Tolanguage 一致);或
|
|
// - 目标语言变化;或
|
|
// - 当前 Translate 为空(上次翻译失败/缺失,需要补做)。
|
|
// 强制重译的代价是多一次翻译调用,换取避免「Tolanguage 已改但 Translate 仍是旧语种」的状态污染。
|
|
needTranslate := req.Tolanguage != "" || language != model.Tolanguage || model.Translate == ""
|
|
this.module.Infof("Summary id:%d → language:%s (model.Tolanguage:%s, Translate空=%v) needTranslate=%v",
|
|
model.Id, language, model.Tolanguage, model.Translate == "", needTranslate)
|
|
if needTranslate {
|
|
var contexts []*pb.ContextStruct
|
|
if err = json.Unmarshal([]byte(model.Original), &contexts); err != nil {
|
|
this.module.Errorf("Summary id:%d 解析 Original 失败 err:%v", model.Id, err)
|
|
} else {
|
|
prevTo := model.Tolanguage
|
|
model.Tolanguage = language
|
|
if terr := this.module.tasks.TranslateProcess(model, contexts); terr != nil {
|
|
// 翻译失败时回滚 Tolanguage,避免下次因 language==Tolanguage 而跳过重试
|
|
model.Tolanguage = prevTo
|
|
}
|
|
}
|
|
this.module.model.saverecord(model)
|
|
}
|
|
_ = this.module.tasks.SubmitAITask(model)
|
|
resp = &pb.EchomeetAddRecordResp{
|
|
Record: model,
|
|
}
|
|
return
|
|
}
|
|
|