feat: source-backed capital-history report generation (/report) - #1
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a report-generation stage to CapScribe that converts the verified, citation-backed capital event set into a structured CapitalReport and rendered Markdown brief, exposed via a new POST /report API route.
Changes:
- Introduces
report.pywith deterministic rollups, timeline rendering, embedded verification output, and optional LLM-written executive summary. - Adds
POST /reportinapi.pyplus API/tests coverage for success, bad mode, and custom title. - Updates API requirements and documentation (
requirements-api.txt,README.md,CHANGES.md) to reflect the new feature and endpoints.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
report.py |
New report-generation module producing structured fields + rendered Markdown with page citations and optional LLM narrative. |
api.py |
Adds POST /report endpoint wiring the indexed event corpus into generate_report(). |
tests/test_report.py |
New unit tests covering rollups, timeline order, citation rules, verification embedding, markdown rendering, custom title, empty input. |
tests/test_api.py |
Adds /report endpoint tests (happy path, bad mode, custom title). |
requirements-api.txt |
Adds Anthropics SDK dependency for mode="llm" report generation. |
README.md |
Documents report stage and /report endpoint in the API table and quickstart/testing notes. |
CHANGES.md |
Changelog entry documenting the report-generation feature and related modifications. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+89
to
+93
| who = ev.get("allottee_category") | ||
| bit = f" to {who}" if who else "" | ||
| price = ev.get("issue_price") | ||
| at = f" at Rs. {price}" if price else "" | ||
| return f"Allotted {ev.get('shares', '?'):,} shares{bit}{at}".replace("?,", "?") |
Comment on lines
+205
to
+207
| if report.narrative: | ||
| lines = [f"# {report.title}", "", "## Executive summary", "", | ||
| report.narrative, ""] + lines[3:] |
Comment on lines
+217
to
+235
| from anthropic import Anthropic | ||
|
|
||
| facts = { | ||
| "metrics": report.metrics, | ||
| "timeline": [t.model_dump() for t in report.timeline], | ||
| "verification": report.verification, | ||
| } | ||
| client = Anthropic(api_key=settings.anthropic_api_key or None) | ||
| msg = client.messages.create( | ||
| model=settings.answer_model, | ||
| max_tokens=350, | ||
| system=( | ||
| "You are a capital-markets analyst. Write a 3-4 sentence executive " | ||
| "summary of a company's capital history using ONLY the JSON facts " | ||
| "provided. Never introduce a figure that is not in the facts. Be " | ||
| "precise and neutral; reference dates where relevant." | ||
| ), | ||
| messages=[{"role": "user", "content": str(facts)}], | ||
| ) |
Comment on lines
+20
to
+22
| # Claude SDK — only used by POST /ask?mode=llm and POST /report?mode=llm. | ||
| # The server boots and serves extractive search/ask/report without a key. | ||
| anthropic>=0.40.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
Adds source-backed capital-history report generation — the final stage of the agentic pipeline (
retrieval → reasoning → verification → report). Turns the verified, cited event set into an analyst-ready brief.Changes
report.py— new module that renders verified capital events into a structured, source-cited reportapi.py— new/reportendpoint exposing report generation over HTTPtests/test_report.py— unit coverage for report rendering and citation handlingtests/test_api.py— coverage for the/reportendpointrequirements-api.txt— added report-generation dependenciesREADME.md/CHANGES.md— documented the new featureTesting
All tests pass locally:
Notes
Every figure in the generated report traces back to a cited source event, consistent with the verification stage — no unsourced claims.