31 lines
929 B
Go
31 lines
929 B
Go
package shared
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
|
)
|
|
|
|
// ChunkPromptMaterial prepares the chunk-scoped source material used by D&D
|
|
// extractors when constructing their prompt inputs.
|
|
func ChunkPromptMaterial(req contracts.TypedExtractionRequest) (contracts.LLMInputMaterial, error) {
|
|
material := req.SourceInput.Clone()
|
|
if len(material.Content) == 0 {
|
|
material = contracts.NewLLMInputMaterial("source", req.Chunk.MediaType, req.Chunk.Content, "", "")
|
|
}
|
|
if !bytes.Equal(material.Content, req.Chunk.Content) {
|
|
return contracts.LLMInputMaterial{}, fmt.Errorf("source input must match chunk %q content", req.Chunk.ID)
|
|
}
|
|
if material.Name == "" {
|
|
material.Name = "source"
|
|
}
|
|
if material.MediaType == "" {
|
|
material.MediaType = req.Chunk.MediaType
|
|
}
|
|
if material.SizeBytes == 0 {
|
|
material.SizeBytes = int64(len(material.Content))
|
|
}
|
|
return material, nil
|
|
}
|