Documentation
¶
Index ¶
- Constants
- type Intermediate
- type Mock
- func (svc *Mock) DocExtraction(ctx context.Context) (graph *workflow.Graph, err error)
- func (svc *Mock) IdentifyChunks(ctx context.Context, flow *workflow.Flow, page []byte) (chunks []docextractionflowapi.Rectangle, err error)
- func (svc *Mock) JoinDocTranscriptions(ctx context.Context, flow *workflow.Flow, listPageTexts []string) (docTranscription string, err error)
- func (svc *Mock) JoinPageTranscriptions(ctx context.Context, flow *workflow.Flow, listTranscriptions []string) (listPageTexts []string, err error)
- func (svc *Mock) MockDocExtraction(...) *Mock
- func (svc *Mock) MockIdentifyChunks(...) *Mock
- func (svc *Mock) MockJoinDocTranscriptions(...) *Mock
- func (svc *Mock) MockJoinPageTranscriptions(...) *Mock
- func (svc *Mock) MockScanPDF(...) *Mock
- func (svc *Mock) MockTranscribeChunk(...) *Mock
- func (svc *Mock) OnShutdown(ctx context.Context) (err error)
- func (svc *Mock) OnStartup(ctx context.Context) (err error)
- func (svc *Mock) ScanPDF(ctx context.Context, flow *workflow.Flow, pdf []byte) (pageImages [][]byte, pageCount int, err error)
- func (svc *Mock) TranscribeChunk(ctx context.Context, flow *workflow.Flow, page []byte, ...) (listTranscriptions []string, err error)
- type Service
- func (svc *Service) DocExtraction(ctx context.Context) (graph *workflow.Graph, err error)
- func (svc *Service) IdentifyChunks(ctx context.Context, flow *workflow.Flow, page []byte) (chunks []docextractionflowapi.Rectangle, err error)
- func (svc *Service) Init(initializer func(svc *Service) (err error)) *Service
- func (svc *Service) JoinDocTranscriptions(ctx context.Context, flow *workflow.Flow, listPageTexts []string) (docTranscription string, err error)
- func (svc *Service) JoinPageTranscriptions(ctx context.Context, flow *workflow.Flow, listTranscriptions []string) (listPageTexts []string, err error)
- func (svc *Service) OnShutdown(ctx context.Context) (err error)
- func (svc *Service) OnStartup(ctx context.Context) (err error)
- func (svc *Service) ScanPDF(ctx context.Context, flow *workflow.Flow, pdf []byte) (pageImages [][]byte, pageCount int, err error)
- func (svc *Service) TranscribeChunk(ctx context.Context, flow *workflow.Flow, page []byte, ...) (listTranscriptions []string, err error)
- type ToDo
Constants ¶
const ( Hostname = docextractionflowapi.Hostname Version = 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Intermediate ¶
Intermediate extends and customizes the generic base connector.
func NewIntermediate ¶
func NewIntermediate(impl ToDo) *Intermediate
NewIntermediate creates a new instance of the intermediate.
type Mock ¶
type Mock struct {
*Intermediate
// contains filtered or unexported fields
}
Mock is a mockable version of the microservice, allowing functions, event sinks and web handlers to be mocked.
func (*Mock) DocExtraction ¶
DocExtraction returns the workflow graph, or a mocked graph if MockDocExtraction was called.
func (*Mock) IdentifyChunks ¶
func (svc *Mock) IdentifyChunks(ctx context.Context, flow *workflow.Flow, page []byte) (chunks []docextractionflowapi.Rectangle, err error)
IdentifyChunks executes the mock handler.
func (*Mock) JoinDocTranscriptions ¶
func (svc *Mock) JoinDocTranscriptions(ctx context.Context, flow *workflow.Flow, listPageTexts []string) (docTranscription string, err error)
JoinDocTranscriptions executes the mock handler.
func (*Mock) JoinPageTranscriptions ¶
func (svc *Mock) JoinPageTranscriptions(ctx context.Context, flow *workflow.Flow, listTranscriptions []string) (listPageTexts []string, err error)
JoinPageTranscriptions executes the mock handler.
func (*Mock) MockDocExtraction ¶
func (svc *Mock) MockDocExtraction(handler func(ctx context.Context, flow *workflow.Flow, pdf []byte) (docTranscription string, pageCount int, err error)) *Mock
MockDocExtraction sets up a mock handler for the DocExtraction workflow. The handler receives typed inputs from the workflow's state and returns typed outputs. A nil handler clears the mock.
func (*Mock) MockIdentifyChunks ¶
func (svc *Mock) MockIdentifyChunks(handler func(ctx context.Context, flow *workflow.Flow, page []byte) (chunks []docextractionflowapi.Rectangle, err error)) *Mock
MockIdentifyChunks sets up a mock handler for IdentifyChunks.
func (*Mock) MockJoinDocTranscriptions ¶
func (svc *Mock) MockJoinDocTranscriptions(handler func(ctx context.Context, flow *workflow.Flow, listPageTexts []string) (docTranscription string, err error)) *Mock
MockJoinDocTranscriptions sets up a mock handler for JoinDocTranscriptions.
func (*Mock) MockJoinPageTranscriptions ¶
func (svc *Mock) MockJoinPageTranscriptions(handler func(ctx context.Context, flow *workflow.Flow, listTranscriptions []string) (listPageTexts []string, err error)) *Mock
MockJoinPageTranscriptions sets up a mock handler for JoinPageTranscriptions.
func (*Mock) MockScanPDF ¶
func (svc *Mock) MockScanPDF(handler func(ctx context.Context, flow *workflow.Flow, pdf []byte) (pageImages [][]byte, pageCount int, err error)) *Mock
MockScanPDF sets up a mock handler for ScanPDF.
func (*Mock) MockTranscribeChunk ¶
func (svc *Mock) MockTranscribeChunk(handler func(ctx context.Context, flow *workflow.Flow, page []byte, chunk docextractionflowapi.Rectangle) (listTranscriptions []string, err error)) *Mock
MockTranscribeChunk sets up a mock handler for TranscribeChunk.
func (*Mock) OnShutdown ¶
OnShutdown is called when the microservice is shut down.
type Service ¶
type Service struct {
*Intermediate // IMPORTANT: Do not remove
}
Service implements docextractionflow.verify, a simulated document-extraction pipeline that exercises nested forEach fan-out (pages, then chunks) with two levels of explicit fan-in, per-chunk simulated latency, and a 5% failure rate with bounded retry.
func (*Service) DocExtraction ¶
DocExtraction defines the graph: ScanPDF -forEach(pageImages as page)-> IdentifyChunks -forEach(chunks as chunk)-> TranscribeChunk -[fan-in]-> JoinPageTranscriptions -[fan-in]-> JoinDocTranscriptions.
func (*Service) IdentifyChunks ¶
func (svc *Service) IdentifyChunks(ctx context.Context, flow *workflow.Flow, page []byte) (chunks []docextractionflowapi.Rectangle, err error)
IdentifyChunks runs once per page. It simulates region detection, returning 2-5 chunk rectangles. It is the inner forEach source over chunks.
func (*Service) JoinDocTranscriptions ¶
func (svc *Service) JoinDocTranscriptions(ctx context.Context, flow *workflow.Flow, listPageTexts []string) (docTranscription string, err error)
JoinDocTranscriptions is the outer fan-in (over all pages). It joins the page texts into the final document transcription, one page per line.
func (*Service) JoinPageTranscriptions ¶
func (svc *Service) JoinPageTranscriptions(ctx context.Context, flow *workflow.Flow, listTranscriptions []string) (listPageTexts []string, err error)
JoinPageTranscriptions is the inner fan-in (over a page's chunks). It joins the page's chunk transcriptions and contributes the page text as the single-element listPageTexts delta (append reducer at the outer fan-in).
func (*Service) OnShutdown ¶
OnShutdown is called when the microservice is shut down.
func (*Service) ScanPDF ¶
func (svc *Service) ScanPDF(ctx context.Context, flow *workflow.Flow, pdf []byte) (pageImages [][]byte, pageCount int, err error)
ScanPDF is the entry task. It simulates rasterizing a PDF: a ~100ms delay, then 5-22 pages of random image data (~50-150 KB each). It is the forEach source over pages.
func (*Service) TranscribeChunk ¶
func (svc *Service) TranscribeChunk(ctx context.Context, flow *workflow.Flow, page []byte, chunk docextractionflowapi.Rectangle) (listTranscriptions []string, err error)
TranscribeChunk runs once per chunk. It simulates OCR latency (50-150ms) and a 5% failure rate; on failure it retries via flow.Retry (100 attempts, constant 500ms, no backoff). On success it contributes one transcription as the single-element listTranscriptions delta (append reducer at fan-in).
type ToDo ¶
type ToDo interface {
OnStartup(ctx context.Context) (err error)
OnShutdown(ctx context.Context) (err error)
ScanPDF(ctx context.Context, flow *workflow.Flow, pdf []byte) (pageImages [][]byte, pageCount int, err error) // MARKER: ScanPDF
IdentifyChunks(ctx context.Context, flow *workflow.Flow, page []byte) (chunks []docextractionflowapi.Rectangle, err error) // MARKER: IdentifyChunks
TranscribeChunk(ctx context.Context, flow *workflow.Flow, page []byte, chunk docextractionflowapi.Rectangle) (listTranscriptions []string, err error) // MARKER: TranscribeChunk
JoinPageTranscriptions(ctx context.Context, flow *workflow.Flow, listTranscriptions []string) (listPageTexts []string, err error) // MARKER: JoinPageTranscriptions
JoinDocTranscriptions(ctx context.Context, flow *workflow.Flow, listPageTexts []string) (docTranscription string, err error) // MARKER: JoinDocTranscriptions
DocExtraction(ctx context.Context) (graph *workflow.Graph, err error) // MARKER: DocExtraction
}
ToDo is implemented by the service or mock.