Skip to content

feat: source-backed capital-history report generation (/report) - #1

Merged
Utkal059 merged 1 commit into
mainfrom
feat/report-generation
Jun 13, 2026
Merged

feat: source-backed capital-history report generation (/report)#1
Utkal059 merged 1 commit into
mainfrom
feat/report-generation

Conversation

@Utkal059

Copy link
Copy Markdown
Owner

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 report
  • api.py — new /report endpoint exposing report generation over HTTP
  • tests/test_report.py — unit coverage for report rendering and citation handling
  • tests/test_api.py — coverage for the /report endpoint
  • requirements-api.txt — added report-generation dependencies
  • README.md / CHANGES.md — documented the new feature

Testing

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.

Copilot AI review requested due to automatic review settings June 13, 2026 20:56
@Utkal059
Utkal059 merged commit 192b9bb into main Jun 13, 2026
5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py with deterministic rollups, timeline rendering, embedded verification output, and optional LLM-written executive summary.
  • Adds POST /report in api.py plus 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 thread report.py
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 thread report.py
Comment on lines +205 to +207
if report.narrative:
lines = [f"# {report.title}", "", "## Executive summary", "",
report.narrative, ""] + lines[3:]
Comment thread report.py
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 thread requirements-api.txt
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants