Overhaul extraction pipeline with new TradeItem model, conversation flow, and dedicated extraction endpoint. Add sidebar navigation with NavMenu component and landing page. Introduce few-shot prompting service and tests. Add prompt settings and email upload specs. Update OpenSpec tooling with improved export-spec and extract-feature commands. Archive completed changes and export full specs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2.7 KiB
2.7 KiB
1. Example Folder Structure
- 1.1 Create directory structure:
examples/extraction/few-shot/andexamples/extraction/evaluation/ - 1.2 Add placeholder example
01/withinput.html(sample email HTML) andoutput.json(sample ExtractionResult JSON matching TradeItem schema). Use realistic but anonymized data. - 1.3 Add placeholder example
02/with a different email pattern (e.g., single swap, different currency) - 1.4 Add placeholder example
03/with an edge case (e.g., breakclause = "Y", or unusual counterparty name)
2. Instruction Template
- 2.1 Create
examples/extraction/instruction-template.txtwith the fixed extraction system prompt: task description, TradeItem schema definition (all 7 fields with types), mapping rules (date parsing, leg flattening, currency symbol → ISO code, breakclause default), and expected JSON output format
3. FewShotService
- 3.1 Create
FewShotService.csin the API project — constructor loads instruction template and all few-shot examples from disk, assembles a ChatHistory prefix (system message + alternating user/assistant turns) - 3.2 Add
CloneWithEmail(string emailHtml)method that clones the cached ChatHistory prefix and appends the email as a user message - 3.3 Add
CloneWithEmailAndMessages(string emailHtml, List<ChatMessage> messages)method for follow-up disambiguation requests — clones prefix, appends email, appends follow-up messages - 3.4 Register
FewShotServiceas singleton inProgram.cs - 3.5 Add
Examples:FewShotPathconfiguration inappsettings.jsonpointing to the examples folder
4. ExtractionRequest DTO
- 4.1 Create
ExtractionRequest.csin Shared/Models withEmailHtml(string, required) andMessages(List, optional)
5. Extraction Endpoint
- 5.1 Add
Extractaction toChatController(or newExtractionController) —POST /api/chat/extractacceptingExtractionRequest - 5.2 In the Extract action: get ChatHistory from
FewShotService.CloneWithEmail()orCloneWithEmailAndMessages()based on whether Messages are present - 5.3 Import extraction-specific plugins only (not general chat plugins)
- 5.4 Stream response via SSE using the same format as the existing chat endpoint
- 5.5 Update
ChatApiClienton the client side — addSendExtractionStreamingAsync(ExtractionRequest request)method mirroring the existing streaming pattern
6. Build and Verify
- 6.1 Build the solution (
dotnet build) and confirm no compilation errors - 6.2 Run all tests (
dotnet test) and confirm they pass - 6.3 Add unit test for
FewShotService— verify it loads examples and assembles correct ChatHistory structure (message count, roles, ordering)