fix: split workbench core mysql access
This commit is contained in:
+41
-3
@@ -198,6 +198,7 @@ func (s *Service) GenerateDocument(ctx context.Context, sourceText, titleHint, d
|
||||
if err != nil {
|
||||
return DocumentResult{}, err
|
||||
}
|
||||
usage := usageFromResponse(resp)
|
||||
var out struct {
|
||||
Title string `json:"title"`
|
||||
Summary string `json:"summary"`
|
||||
@@ -206,7 +207,7 @@ func (s *Service) GenerateDocument(ctx context.Context, sourceText, titleHint, d
|
||||
Sections []DocumentSection `json:"sections"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(ExtractJSONObject(resp.Content)), &out); err != nil {
|
||||
return DocumentResult{}, fmt.Errorf("%w: %v", ErrBadOutput, err)
|
||||
return fallbackDocument(sourceText, titleHint, documentType, usage, "AI 输出格式异常,已使用兜底文档。"), nil
|
||||
}
|
||||
out.Title = strings.TrimSpace(firstNonEmpty(out.Title, titleHint, "智能文档"))
|
||||
out.ContentMarkdown = strings.TrimSpace(out.ContentMarkdown)
|
||||
@@ -217,7 +218,7 @@ func (s *Service) GenerateDocument(ctx context.Context, sourceText, titleHint, d
|
||||
out.ContentPlain = plainFromSections(out.Sections)
|
||||
}
|
||||
if out.ContentMarkdown == "" {
|
||||
return DocumentResult{}, ErrBadOutput
|
||||
return fallbackDocument(sourceText, titleHint, documentType, usage, "AI 输出缺少文档正文,已使用兜底文档。"), nil
|
||||
}
|
||||
return DocumentResult{
|
||||
Title: out.Title,
|
||||
@@ -225,10 +226,47 @@ func (s *Service) GenerateDocument(ctx context.Context, sourceText, titleHint, d
|
||||
ContentPlain: strings.TrimSpace(out.ContentPlain),
|
||||
Sections: out.Sections,
|
||||
Summary: strings.TrimSpace(out.Summary),
|
||||
Usage: usageFromResponse(resp),
|
||||
Usage: usage,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func fallbackDocument(sourceText, titleHint, documentType string, usage Usage, reason string) DocumentResult {
|
||||
title := firstNonEmpty(titleHint, documentTypeTitle(documentType), excerptPlain(sourceText, 30), "智能文档")
|
||||
source := strings.TrimSpace(sourceText)
|
||||
if source == "" {
|
||||
source = "用户未提供有效原文。"
|
||||
}
|
||||
sections := []DocumentSection{
|
||||
{Heading: "处理说明", Content: reason},
|
||||
{Heading: "用户输入", Content: source},
|
||||
{Heading: "后续建议", Content: "建议检查原始输入是否完整,或重新发起生成以获取更完整的智能文档。"},
|
||||
}
|
||||
contentMarkdown := markdownFromSections(sections)
|
||||
return DocumentResult{
|
||||
Title: title,
|
||||
ContentMarkdown: contentMarkdown,
|
||||
ContentPlain: plainFromSections(sections),
|
||||
Sections: sections,
|
||||
Summary: excerptPlain(source, 120),
|
||||
Usage: usage,
|
||||
}
|
||||
}
|
||||
|
||||
func documentTypeTitle(documentType string) string {
|
||||
switch strings.TrimSpace(documentType) {
|
||||
case "meeting_minutes":
|
||||
return "会议纪要"
|
||||
case "speech":
|
||||
return "演讲稿"
|
||||
case "proposal":
|
||||
return "方案文档"
|
||||
case "summary":
|
||||
return "内容总结"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) AnalyzeTable(ctx context.Context, input TableAnalysisInput) (TableAnalysisResult, error) {
|
||||
if s == nil || s.client == nil {
|
||||
return TableAnalysisResult{}, ErrNotConfigured
|
||||
|
||||
Reference in New Issue
Block a user