r3trace 0.6.51__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. r3trace/__init__.py +115 -0
  2. r3trace/__main__.py +22 -0
  3. r3trace/app/__init__.py +8 -0
  4. r3trace/app/app.css +736 -0
  5. r3trace/app/app.js +8612 -0
  6. r3trace/app/index.html +155 -0
  7. r3trace/app/server.py +1526 -0
  8. r3trace/app/updates.py +69 -0
  9. r3trace/app/window.py +304 -0
  10. r3trace/cli.py +489 -0
  11. r3trace/config.py +390 -0
  12. r3trace/configs/default.yaml +42 -0
  13. r3trace/documents.py +727 -0
  14. r3trace/logging_setup.py +94 -0
  15. r3trace/masking.py +295 -0
  16. r3trace/parallel.py +40 -0
  17. r3trace/pipeline.py +2193 -0
  18. r3trace/prompts/claims/v1.yaml +46 -0
  19. r3trace/prompts/claims/v2.yaml +46 -0
  20. r3trace/prompts/claims/v3.yaml +46 -0
  21. r3trace/prompts/linking/v1.yaml +6 -0
  22. r3trace/prompts/reasoning/coding/v1.yaml +178 -0
  23. r3trace/prompts/reasoning/coding/v2.yaml +183 -0
  24. r3trace/prompts/reasoning/coding/v3.yaml +185 -0
  25. r3trace/prompts/reasoning/coding/v4.yaml +185 -0
  26. r3trace/prompts/reasoning/direct/v1.yaml +153 -0
  27. r3trace/prompts/reasoning/direct/v2.yaml +160 -0
  28. r3trace/prompts/reasoning/direct/v3.yaml +162 -0
  29. r3trace/prompts/reasoning/direct/v4.yaml +162 -0
  30. r3trace/prompts/reasoning/direct/v5.yaml +162 -0
  31. r3trace/prompts/reasoning/v1.yaml +176 -0
  32. r3trace/prompts/reasoning/v2.yaml +178 -0
  33. r3trace/prompts/relevance/first-round/v1.yaml +38 -0
  34. r3trace/prompts/relevance/first-round/v2.yaml +41 -0
  35. r3trace/prompts/relevance/first-round/v3.yaml +51 -0
  36. r3trace/prompts/relevance/later-rounds/v1.yaml +71 -0
  37. r3trace/prompts/relevance/later-rounds/v2.yaml +71 -0
  38. r3trace/prompts/relevance/later-rounds/v3.yaml +72 -0
  39. r3trace/prompts/relevance/later-rounds/v4.yaml +87 -0
  40. r3trace/prompts/relevance/v1.yaml +44 -0
  41. r3trace/prompts/structuring/parsing/v1.yaml +88 -0
  42. r3trace/prompts/structuring/parsing/v2.yaml +149 -0
  43. r3trace/prompts/structuring/parsing/v3.yaml +149 -0
  44. r3trace/prompts/structuring/parsing/v4.yaml +148 -0
  45. r3trace/prompts/structuring/schema/v1.yaml +121 -0
  46. r3trace/prompts/structuring/schema/v2.yaml +119 -0
  47. r3trace/prompts.py +130 -0
  48. r3trace/provenance.py +408 -0
  49. r3trace/py.typed +0 -0
  50. r3trace/quotes.py +258 -0
  51. r3trace/r3trace.py +495 -0
  52. r3trace/runs.py +824 -0
  53. r3trace/runtime/__init__.py +7 -0
  54. r3trace/runtime/codeact.py +605 -0
  55. r3trace/runtime/llm.py +935 -0
  56. r3trace/runtime/python_executor.py +1853 -0
  57. r3trace/settings.py +171 -0
  58. r3trace/splitting.py +522 -0
  59. r3trace/stages/__init__.py +12 -0
  60. r3trace/stages/citing.py +116 -0
  61. r3trace/stages/claims.py +329 -0
  62. r3trace/stages/reasoning.py +581 -0
  63. r3trace/stages/relevance.py +669 -0
  64. r3trace/stages/structuring/__init__.py +8 -0
  65. r3trace/stages/structuring/parsing.py +621 -0
  66. r3trace/stages/structuring/schema.py +250 -0
  67. r3trace-0.6.51.dist-info/METADATA +402 -0
  68. r3trace-0.6.51.dist-info/RECORD +72 -0
  69. r3trace-0.6.51.dist-info/WHEEL +4 -0
  70. r3trace-0.6.51.dist-info/entry_points.txt +3 -0
  71. r3trace-0.6.51.dist-info/licenses/LICENSE +22 -0
  72. r3trace-0.6.51.dist-info/licenses/THIRD-PARTY-NOTICES +222 -0
r3trace/__init__.py ADDED
@@ -0,0 +1,115 @@
1
+ """r3trace — just-in-time reasoning over a collection of documents.
2
+
3
+ Ask a question whose evidence is spread across many documents; the apparatus for
4
+ answering it is built *per question*, at the moment you ask:
5
+
6
+ >>> from r3trace import r3trace
7
+ >>> result = r3trace.run("Which supplier missed the most delivery windows?", docs)
8
+ >>> print(result) # the answer
9
+ >>> result.provenance # its relevant trail, claims and evidence trail
10
+ >>> result.relevant_context # what each document contributed
11
+ >>> result.structured_context # the structured parse behind it
12
+
13
+ Three moves, in order:
14
+
15
+ 1. **surfacing relevance** — every document is read against the question and written up
16
+ as a **relevance summary**; then re-read in light of the *other* documents'
17
+ summaries, until it is pruned for saying nothing. Together they are the **relevant context**.
18
+ Relevance is not a property a document has; it is a relation between the document,
19
+ the question, and the rest of the collection, so it cannot be settled from a
20
+ document in isolation.
21
+ 2. **structuring** — a Pydantic schema is proposed for exactly what this question needs,
22
+ then every document not pruned is parsed into instances of it.
23
+ 3. **reasoning** — one call answers over the structured records and the relevance
24
+ summaries together; or, when the run asks for it or that prompt does not fit the
25
+ model's window, the merged parse is loaded into a sandboxed Python runtime and an
26
+ agent reasons there with code. Either way the answer cites the documents it used.
27
+
28
+ The whole collection is never placed in a single prompt: each document is read on its
29
+ own, in parts when it is too long for the model's window, and information crosses
30
+ document boundaries through the relevance summaries.
31
+ """
32
+
33
+ from importlib import metadata as _metadata
34
+
35
+ from r3trace import provenance, r3trace, settings
36
+ from r3trace.config import RunConfig, load_config
37
+ from r3trace.documents import read_documents
38
+ from r3trace.pipeline import Answer, Skip, run_pipeline
39
+ from r3trace.prompts import load_prompt
40
+ from r3trace.r3trace import ask, resume, run, trace
41
+ from r3trace.runs import StageRun, TaskLogger
42
+ from r3trace.runtime.codeact import CodeActResult, CodeActTurn
43
+ from r3trace.runtime.llm import (
44
+ Cancelled,
45
+ EmptyReply,
46
+ UnfitReply,
47
+ UnusableReply,
48
+ litellm_chat_completion,
49
+ litellm_chat_completion_full,
50
+ )
51
+ from r3trace.stages.reasoning import ReasoningResult, reason
52
+ from r3trace.stages.relevance import (
53
+ RelevantContext,
54
+ relevance_snippet,
55
+ render_relevance,
56
+ surface_relevance,
57
+ )
58
+ from r3trace.stages.structuring.parsing import (
59
+ ParseResult,
60
+ SchemaError,
61
+ check_schema,
62
+ parse_documents,
63
+ parse_one_document,
64
+ )
65
+ from r3trace.stages.structuring.schema import (
66
+ ProposalAttempt,
67
+ ProposalResult,
68
+ propose_schema,
69
+ )
70
+
71
+ try:
72
+ __version__ = _metadata.version("r3trace")
73
+ except _metadata.PackageNotFoundError: # a source tree that was never installed
74
+ __version__ = "0+unknown"
75
+
76
+ __all__ = [
77
+ "Answer",
78
+ "Cancelled",
79
+ "CodeActResult",
80
+ "CodeActTurn",
81
+ "EmptyReply",
82
+ "ParseResult",
83
+ "ProposalAttempt",
84
+ "ProposalResult",
85
+ "ReasoningResult",
86
+ "RelevantContext",
87
+ "RunConfig",
88
+ "SchemaError",
89
+ "Skip",
90
+ "StageRun",
91
+ "TaskLogger",
92
+ "UnfitReply",
93
+ "UnusableReply",
94
+ "ask",
95
+ "check_schema",
96
+ "litellm_chat_completion",
97
+ "litellm_chat_completion_full",
98
+ "load_config",
99
+ "load_prompt",
100
+ "parse_documents",
101
+ "parse_one_document",
102
+ "propose_schema",
103
+ "provenance",
104
+ "r3trace",
105
+ "read_documents",
106
+ "reason",
107
+ "relevance_snippet",
108
+ "render_relevance",
109
+ "resume",
110
+ "run",
111
+ "run_pipeline",
112
+ "settings",
113
+ "surface_relevance",
114
+ "trace",
115
+ ]
r3trace/__main__.py ADDED
@@ -0,0 +1,22 @@
1
+ """``python -m r3trace``: the command line, as ``r3trace`` is, except in the Mac app, which
2
+ Briefcase starts this way: there it opens the app's window (:mod:`r3trace.app.window`)."""
3
+
4
+ from importlib import metadata
5
+
6
+ # Briefcase writes an "r3trace" distribution of its own into the Mac app, as its
7
+ # INSTALLER says; pip and uv install one of that name too.
8
+ MAC_APP_INSTALLER = "briefcase"
9
+
10
+ if __name__ == "__main__":
11
+ installers = {
12
+ (found.read_text("INSTALLER") or "").strip()
13
+ for found in metadata.distributions(name="r3trace")
14
+ }
15
+ if MAC_APP_INSTALLER in installers:
16
+ from r3trace.app import window
17
+
18
+ window.main()
19
+ else:
20
+ from r3trace import cli
21
+
22
+ raise SystemExit(cli.main())
@@ -0,0 +1,8 @@
1
+ """r3trace's app: a page that runs r3trace, and the local server behind it (``r3trace app``).
2
+
3
+ It needs the ``app`` extra.
4
+ """
5
+
6
+ from r3trace.app.server import create_app, serve
7
+
8
+ __all__ = ["create_app", "serve"]