75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
package grammar
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/eric/audita/internal/core/schema"
|
|
"gitea.maximumdirect.net/eric/audita/internal/framework/contracts"
|
|
"gitea.maximumdirect.net/eric/audita/internal/framework/promptcontext"
|
|
"gitea.maximumdirect.net/eric/audita/internal/prompts"
|
|
)
|
|
|
|
type promptSegment struct {
|
|
ID int `json:"id"`
|
|
Speaker string `json:"speaker"`
|
|
Start float64 `json:"start"`
|
|
End float64 `json:"end"`
|
|
Text string `json:"text"`
|
|
Categories []string `json:"categories,omitempty"`
|
|
}
|
|
|
|
type promptTranscriptSection struct {
|
|
SectionIndex int `json:"section_index"`
|
|
Segments []promptSegment `json:"segments"`
|
|
}
|
|
|
|
// BuildProposalMessages constrains corrections to punctuation/capitalization/
|
|
// spacing cleanup with strict meaning guards.
|
|
func BuildProposalMessages(transcript *schema.Transcript, glossary *schema.Glossary, sectionIndex int, transcriptDescription string) ([]contracts.LLMMessage, error) {
|
|
glossaryJSON, err := json.MarshalIndent(glossary, "", " ")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("marshal glossary prompt context: %w", err)
|
|
}
|
|
|
|
sectionPayload := promptTranscriptSection{
|
|
SectionIndex: sectionIndex,
|
|
Segments: make([]promptSegment, 0),
|
|
}
|
|
if transcript != nil {
|
|
for _, s := range transcript.Segments {
|
|
sectionPayload.Segments = append(sectionPayload.Segments, promptSegment{
|
|
ID: s.ID,
|
|
Speaker: s.Speaker,
|
|
Start: s.Start,
|
|
End: s.End,
|
|
Text: s.Text,
|
|
Categories: append([]string(nil), s.Categories...),
|
|
})
|
|
}
|
|
}
|
|
|
|
sectionJSON, err := json.MarshalIndent(sectionPayload, "", " ")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("marshal transcript prompt context: %w", err)
|
|
}
|
|
|
|
system, user, _, err := prompts.RenderUserSystem(prompts.PromptIDModuleGrammarProposal, map[string]string{
|
|
"TranscriptDescriptionBlock": promptcontext.TranscriptDescriptionBlock(transcriptDescription),
|
|
"GlossaryJSON": string(glossaryJSON),
|
|
"SectionJSON": string(sectionJSON),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return []contracts.LLMMessage{
|
|
{Role: "system", Content: system},
|
|
{Role: "user", Content: user},
|
|
}, nil
|
|
}
|
|
|
|
func proposalPromptMetadata() prompts.Metadata {
|
|
return prompts.MustLookupMetadata(prompts.PromptIDModuleGrammarProposal)
|
|
}
|