llm-rsa 0.0.2__py3-none-any.whl → 0.0.3__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.
llm_rsa/core.py CHANGED
@@ -43,12 +43,14 @@ class RSA:
43
43
 
44
44
  # %% ../nbs/00_core.ipynb #3c39e9e6
45
45
  @patch
46
- def _call_llm(self:RSA, prompt):
46
+ def _call_llm(self:RSA, prompt, **kwargs):
47
47
  "Call the LLM with the given prompt and return the response content"
48
48
  response = completion(
49
49
  model=self.model,
50
50
  messages=[{"role": "user", "content": prompt}],
51
51
  temperature=self.temperature,
52
+ num_retries=3,
53
+ **kwargs
52
54
  )
53
55
  return response.choices[0].message.content
54
56
 
@@ -97,11 +99,13 @@ def run(self:RSA):
97
99
  self.history.extend(pool)
98
100
  return pool
99
101
 
100
- # %% ../nbs/00_core.ipynb #b4edf71c
102
+ # %% ../nbs/00_core.ipynb #72cb9b61
101
103
  @patch
102
- def aggregate(self:RSA):
103
- "Final aggregation one LLM call to aggregate all the final loop candidates"
104
+ def aggregate(self:RSA, agg_prompt=None, response_model=None):
105
+ "Final aggregation: one LLM call to aggregate all final loop candidates, with optional structured output"
106
+ agg_prompt = agg_prompt or self.agg_prompt
104
107
  candidates = self.history.filter(lambda x: x.loop_id==(self.loops-1))
105
108
  responses = '\n'.join(f"---- Candidate {i+1} ----\n{c.response}" for i, c in enumerate(candidates))
106
- prompt = f"{self.agg_prompt}\n{self.task_prompt}\n\nCANDIDATE ANSWERS:\n{responses}\n\nProvide the best aggregated answer:"
107
- return prompt, self._call_llm(prompt)
109
+ prompt = f"{agg_prompt}\n{self.task_prompt}\n\nCANDIDATE ANSWERS:\n{responses}\n\nProvide the best aggregated answer:"
110
+ result = self._call_llm(prompt, **({'response_format': response_model} if response_model else {}))
111
+ return prompt, result
@@ -0,0 +1,287 @@
1
+ Metadata-Version: 2.4
2
+ Name: llm_rsa
3
+ Version: 0.0.3
4
+ Summary: Recursive self aggregation
5
+ Home-page: https://github.com/risheekkumarb/llm_rsa
6
+ Author: Risheek kumar B
7
+ Author-email: b.risheekkumar@gmail.com
8
+ License: Apache-2.0
9
+ Keywords: nbdev jupyter notebook python
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: fastcore
22
+ Requires-Dist: litellm
23
+ Requires-Dist: fastprogress
24
+ Provides-Extra: dev
25
+ Dynamic: author
26
+ Dynamic: author-email
27
+ Dynamic: classifier
28
+ Dynamic: description
29
+ Dynamic: description-content-type
30
+ Dynamic: home-page
31
+ Dynamic: keywords
32
+ Dynamic: license
33
+ Dynamic: license-file
34
+ Dynamic: provides-extra
35
+ Dynamic: requires-dist
36
+ Dynamic: requires-python
37
+ Dynamic: summary
38
+
39
+ # RSA - Recursive Self-Aggregation
40
+
41
+
42
+ <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
43
+
44
+ RSA implements Recursive Self-Aggregation, a technique for improving LLM
45
+ responses by generating multiple candidate answers and iteratively
46
+ aggregating them. The algorithm samples k candidates from a pool of M
47
+ responses, asks the LLM to synthesize an improved answer, and repeats
48
+ this process across multiple loops to converge on higher-quality
49
+ outputs.
50
+
51
+ ## Developer Guide
52
+
53
+ If you are new to using `nbdev` here are some useful pointers to get you
54
+ started.
55
+
56
+ ### Install in Development mode
57
+
58
+ ``` sh
59
+ # make sure package is installed in development mode
60
+ $ pip install -e .
61
+
62
+ # make changes under nbs/ directory
63
+ # ...
64
+
65
+ # compile to have changes apply to
66
+ $ nbdev_prepare
67
+ ```
68
+
69
+ ## Usage
70
+
71
+ ### Installation
72
+
73
+ Install latest from the GitHub
74
+ [repository](https://github.com/risheekkumarb/llm_rsa):
75
+
76
+ ``` sh
77
+ $ pip install git+https://github.com//.git
78
+ ```
79
+
80
+ or from [conda](https://anaconda.org/risheekkumarb/llm_rsa)
81
+
82
+ ``` sh
83
+ $ conda install -c
84
+ ```
85
+
86
+ or from [pypi](https://pypi.org/project/llm_rsa)
87
+
88
+ ``` sh
89
+ $ pip install
90
+ ```
91
+
92
+ ### Documentation
93
+
94
+ Documentation can be found hosted on this GitHub
95
+ [repository](https://github.com/risheekkumarb/llm_rsa)’s
96
+ [pages](https://risheekkumarb.github.io/llm_rsa/). Additionally you can
97
+ find package manager specific guidelines on
98
+ [conda](https://anaconda.org/risheekkumarb/llm_rsa) and
99
+ [pypi](https://pypi.org/project/llm_rsa) respectively.
100
+
101
+ ## How to use
102
+
103
+ ### Basic Usage
104
+
105
+ Create an RSA instance with your task prompt and call it to run the
106
+ aggregation:
107
+
108
+ ``` python
109
+ task_prompt = '''Three people check into a hotel room that costs $30. They each contribute $10.
110
+ Later, the manager realizes the room only costs $25 and gives $5 to the bellboy to return.
111
+ The bellboy keeps $2 and gives $1 back to each person.
112
+ So each person paid $9 (total $27), plus the bellboy has $2, which equals $29.
113
+ Where did the extra dollar go?'''
114
+ ```
115
+
116
+ ``` python
117
+ agg_prompt = """Below is a reasoning problem followed by several candidate solutions.
118
+ Your job is to:
119
+ 1. Carefully analyze each candidate's reasoning step-by-step
120
+ 2. Identify which candidates make logical errors or arithmetic mistakes
121
+ 3. Note which approaches lead to correct reasoning
122
+ 4. Synthesize the best reasoning into a single, clear, correct solution
123
+
124
+ Show your work step-by-step, then state your final answer clearly."""
125
+ ```
126
+
127
+ ``` python
128
+ from llm_rsa.core import RSA
129
+
130
+ # Create RSA instance with a reasoning task
131
+ rsa = RSA(
132
+ task_prompt=task_prompt,
133
+ agg_prompt=agg_prompt,
134
+ N=4,
135
+ K=2,
136
+ loops=2
137
+ )
138
+
139
+ # Run the aggregation
140
+ results = rsa.run()
141
+ print(f"Generated {len(rsa.history)} total candidates across {rsa.loops} loops")
142
+ print('llm response: \n', results[-1].response)
143
+ ```
144
+
145
+ <style>
146
+ progress { appearance: none; border: none; border-radius: 4px; width: 300px;
147
+ height: 20px; vertical-align: middle; background: #e0e0e0; }
148
+ &#10; progress::-webkit-progress-bar { background: #e0e0e0; border-radius: 4px; }
149
+ progress::-webkit-progress-value { background: #2196F3; border-radius: 4px; }
150
+ progress::-moz-progress-bar { background: #2196F3; border-radius: 4px; }
151
+ &#10; progress:not([value]) {
152
+ background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px); }
153
+ &#10; progress.progress-bar-interrupted::-webkit-progress-value { background: #F44336; }
154
+ progress.progress-bar-interrupted::-moz-progress-value { background: #F44336; }
155
+ progress.progress-bar-interrupted::-webkit-progress-bar { background: #F44336; }
156
+ progress.progress-bar-interrupted::-moz-progress-bar { background: #F44336; }
157
+ progress.progress-bar-interrupted { background: #F44336; }
158
+ &#10; table.fastprogress { border-collapse: collapse; margin: 1em 0; font-size: 0.9em; }
159
+ table.fastprogress th, table.fastprogress td { padding: 8px 12px; border: 1px solid #ddd; text-align: left; }
160
+ table.fastprogress thead tr { background: #f8f9fa; font-weight: bold; }
161
+ table.fastprogress tbody tr:nth-of-type(even) { background: #f8f9fa; }
162
+ </style>
163
+
164
+ ``` html
165
+ <div>
166
+ <progress max="2" value="2"></progress> 100.00% [2/2 00:20&lt;00:00... Loop 2]</div>
167
+ ```
168
+
169
+ Generated 8 total candidates across 2 loops
170
+ llm response:
171
+ ### Analysis of Candidate Reasoning
172
+
173
+ Both **Candidate 1** and **Candidate 2** provide excellent, accurate explanations of the "missing dollar" riddle.
174
+
175
+ 1. **Candidate 1 Analysis:** This candidate correctly identifies the logical fallacy of adding the bellboy's kept money to the amount spent by the guests. They provide a clear "Follow the Money" breakdown showing that the $30 is distributed as $25 (hotel), $2 (bellboy), and $3 (guests). They correctly state that the $27 spent by the guests *already includes* the $2 held by the bellboy.
176
+ 2. **Candidate 2 Analysis:** This candidate identifies the "false premise" and "incorrect logic" of the riddle. Like Candidate 1, they break down the $30 correctly and explain that the riddle incorrectly adds a "cost" ($27) to a "profit" ($2) instead of adding the "cost" ($27) to the "refund" ($3).
177
+
178
+ Both candidates conclude that no money is actually missing and that the riddle is based on an arithmetic trick.
179
+
180
+ ---
181
+
182
+ ### Synthetic Correct Solution
183
+
184
+ The "missing dollar" is a result of a misleading calculation. To resolve the mystery, we must track the money accurately using two different perspectives: **where the money is now** and **the total amount spent vs. kept.**
185
+
186
+ #### 1. Where is the money now? (The $30 Breakdown)
187
+ The original $30 can be accounted for by looking at who currently holds the cash:
188
+ * **$25:** Held by the hotel (the actual cost of the room).
189
+ * **$2:** Held by the bellboy (the amount he kept).
190
+ * **$3:** Held by the three guests ($1 each in their pockets).
191
+ * **Total: $25 + $2 + $3 = $30.**
192
+ Nothing is missing.
193
+
194
+ #### 2. The Fallacy in the Riddle
195
+ The riddle states: *"Each person paid $9 (total $27), plus the bellboy has $2, which equals $29."*
196
+ This is logically incorrect because it **double-counts** the bellboy's money.
197
+
198
+ * **The Net Payment:** The guests spent a total of **$27**.
199
+ * **The Destination of that payment:** Of that $27, **$25** went to the hotel and **$2** went to the bellboy.
200
+ * **The Calculation:** Adding the $2 to the $27 is nonsensical because the $2 is *already part* of the $27.
201
+
202
+ To reach the original $30, you must add the money the guests **kept** to the money they **spent**:
203
+ **$27 (Spent) + $3 (Returned to them) = $30.**
204
+
205
+ ### Final Answer
206
+ The dollar did not go anywhere. The riddle creates an illusion by adding the bellboy's $2 to the $27 spent, when it should be subtracting the $2 from the $27 to find the hotel’s $25, or adding the $3 refund to the $27 to find the original $30.
207
+
208
+ ``` python
209
+ from pydantic import BaseModel
210
+ class Answer(BaseModel):
211
+ answer: str
212
+ confidence: float
213
+
214
+ prompt, response = rsa.aggregate(response_model=Answer)
215
+ print(response)
216
+ ```
217
+
218
+ {"answer":"The mystery of the missing dollar is caused by a logical fallacy known as misdirection. The riddle incorrectly adds the bellboy's $2 to the $27 paid by the guests, creating a mathematically irrelevant number ($29). To solve the puzzle, we simply need to track the original $30 using two balance methods:\n\n1. The Distribution Method (Where is the money now?):\n- $25 is in the hotel's register.\n- $2 is in the bellboy's pocket.\n- $3 is in the guests' pockets ($1 each).\n- Total: $25 + $2 + $3 = $30. \nEverything is accounted for.\n\n2. The Net Expenditure Method (What did the guests pay?):\nThe guests paid $30 and got $3 back, meaning they spent exactly $27. \n- $25 of that $27 went to the hotel room cost.\n- $2 of that $27 went to the bellboy as a tip.\n- Total: $25 + $2 = $27.\n\nThe error in the riddle is adding the $2 to the $27. Because the $2 is already part of the $27, adding them together double-counts the bellboy's tip. To get back to the original $30, you must add the $27 spent to the $3 refund ($27 + $3 = $30). There is no missing dollar.","confidence":1.0}
219
+
220
+ ``` python
221
+ from litellm import completion
222
+
223
+ # Single direct call (baseline)
224
+ response = completion(
225
+ model='openrouter/google/gemini-3-flash-preview',
226
+ messages=[{"role": "user", "content": task_prompt}],
227
+ temperature=1.0
228
+ )
229
+ baseline_answer = response.choices[0].message.content
230
+ print("=== BASELINE (single call) ===")
231
+ print(baseline_answer)
232
+ ```
233
+
234
+ === BASELINE (single call) ===
235
+ This is a classic riddle that relies on a **logical fallacy**—specifically, an error in how the numbers are added together at the end.
236
+
237
+ The "lost" dollar doesn't exist; it only appears to be missing because the math at the end of the story adds two numbers that should actually be **subtracted**.
238
+
239
+ Here is the correct breakdown of the money:
240
+
241
+ ### 1. Follow the Money
242
+ Instead of adding the bellboy's tip to the guests' payment, look at where the original $30 is at the very end:
243
+ * **$25** is in the hotel cash register.
244
+ * **$2** is in the bellboy's pocket.
245
+ * **$3** was returned to the guests ($1 each).
246
+ * **Total: $25 + $2 + $3 = $30.** (The math is perfect).
247
+
248
+ ### 2. The Flaw in the Riddle
249
+ The riddle says: *"Each person paid $9 (total $27), plus the bellboy has $2, which equals $29."*
250
+
251
+ **The error is adding the $2 to the $27.**
252
+ The $27 that the guests spent **already includes** the $2 that the bellboy took.
253
+
254
+ Think of it this way:
255
+ * The guests paid **$27**.
256
+ * Where did that $27 go? **$25** went to the hotel and **$2** went to the bellboy.
257
+ * To reach the original $30, you should add the **$3** they got back, not the $2 the bellboy kept.
258
+
259
+ **The correct equation is:**
260
+ $27 (Paid) + $3 (Refund) = $30.
261
+ *OR*
262
+ $27 (Paid) - $2 (Bellboy's Tip) = $25 (Room Cost).
263
+
264
+ ### Configuration Options
265
+
266
+ | Parameter | Default | Description |
267
+ |----|----|----|
268
+ | `task_prompt` | (required) | The main task/question to solve |
269
+ | `model` | `'openrouter/google/gemini-3-flash-preview'` | LLM model to use (any litellm-compatible model) |
270
+ | `N` | 4 | Population size (candidates per loop) |
271
+ | `K` | 3 | Number of candidates to aggregate |
272
+ | `loops` | 2 | Number of aggregation iterations |
273
+ | `temperature` | 1.0 | LLM sampling temperature |
274
+ | `n_workers` | 4 | Parallel workers for LLM calls |
275
+ | `agg_prompt` | (auto) | Custom aggregation prompt (optional) |
276
+
277
+ ### How RSA Works
278
+
279
+ 1. **Loop 0**: Generate N independent responses to the task prompt
280
+ 2. **Loop 1+**: For each of N new candidates, randomly sample K
281
+ previous candidates and ask the LLM to aggregate them into an
282
+ improved answer
283
+ 3. **Repeat** for the specified number of loops
284
+ 4. **Return** the final pool of aggregated candidates
285
+
286
+ The `history` attribute stores all candidates across all loops, allowing
287
+ you to trace the aggregation process.
@@ -0,0 +1,9 @@
1
+ llm_rsa/__init__.py,sha256=QvlVh4JTl3JL7jQAja76yKtT-IvF4631ASjWY1wS6AQ,22
2
+ llm_rsa/_modidx.py,sha256=ogPe8zhCHsthGKU9Xg2XJUrE0h6S6T87oFcbjPsRIrc,1581
3
+ llm_rsa/core.py,sha256=a8Dx7MpVsVRbfjKOH0MHTPH3I3e4URnlS-GMv8V0UlU,5329
4
+ llm_rsa-0.0.3.dist-info/licenses/LICENSE,sha256=xV8xoN4VOL0uw9X8RSs2IMuD_Ss_a9yAbtGNeBWZwnw,11337
5
+ llm_rsa-0.0.3.dist-info/METADATA,sha256=sbgGuyIo6Qmp_iQhmHlzNAcRKjDMYQPcCa6CvTcN_B4,12032
6
+ llm_rsa-0.0.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
7
+ llm_rsa-0.0.3.dist-info/entry_points.txt,sha256=pnciZLW9vjkfP635726PVzPYrDvpPRb1SrHrtZsQbgw,36
8
+ llm_rsa-0.0.3.dist-info/top_level.txt,sha256=p3SxxJAnEYU4XsL4IJt9PSglY7nE4zlWf9IWo9Yu6_E,8
9
+ llm_rsa-0.0.3.dist-info/RECORD,,
@@ -1,251 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: llm_rsa
3
- Version: 0.0.2
4
- Summary: Recursive self aggregation
5
- Home-page: https://github.com/risheekkumarb/llm_rsa
6
- Author: Risheek kumar B
7
- Author-email: b.risheekkumar@gmail.com
8
- License: Apache-2.0
9
- Keywords: nbdev jupyter notebook python
10
- Classifier: Development Status :: 4 - Beta
11
- Classifier: Intended Audience :: Developers
12
- Classifier: Natural Language :: English
13
- Classifier: Programming Language :: Python :: 3.9
14
- Classifier: Programming Language :: Python :: 3.10
15
- Classifier: Programming Language :: Python :: 3.11
16
- Classifier: Programming Language :: Python :: 3.12
17
- Classifier: Programming Language :: Python :: 3.13
18
- Requires-Python: >=3.9
19
- Description-Content-Type: text/markdown
20
- License-File: LICENSE
21
- Requires-Dist: fastcore
22
- Requires-Dist: litellm
23
- Requires-Dist: fastprogress
24
- Provides-Extra: dev
25
- Dynamic: author
26
- Dynamic: author-email
27
- Dynamic: classifier
28
- Dynamic: description
29
- Dynamic: description-content-type
30
- Dynamic: home-page
31
- Dynamic: keywords
32
- Dynamic: license
33
- Dynamic: license-file
34
- Dynamic: provides-extra
35
- Dynamic: requires-dist
36
- Dynamic: requires-python
37
- Dynamic: summary
38
-
39
- # RSA - Recursive Self-Aggregation
40
-
41
-
42
- <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
43
-
44
- RSA implements Recursive Self-Aggregation, a technique for improving LLM
45
- responses by generating multiple candidate answers and iteratively
46
- aggregating them. The algorithm samples k candidates from a pool of M
47
- responses, asks the LLM to synthesize an improved answer, and repeats
48
- this process across multiple loops to converge on higher-quality
49
- outputs.
50
-
51
- ## Developer Guide
52
-
53
- If you are new to using `nbdev` here are some useful pointers to get you
54
- started.
55
-
56
- ### Install in Development mode
57
-
58
- ``` sh
59
- # make sure package is installed in development mode
60
- $ pip install -e .
61
-
62
- # make changes under nbs/ directory
63
- # ...
64
-
65
- # compile to have changes apply to
66
- $ nbdev_prepare
67
- ```
68
-
69
- ## Usage
70
-
71
- ### Installation
72
-
73
- Install latest from the GitHub
74
- [repository](https://github.com/risheekkumarb/llm_rsa):
75
-
76
- ``` sh
77
- $ pip install git+https://github.com//.git
78
- ```
79
-
80
- or from [conda](https://anaconda.org/risheekkumarb/llm_rsa)
81
-
82
- ``` sh
83
- $ conda install -c
84
- ```
85
-
86
- or from [pypi](https://pypi.org/project/llm_rsa)
87
-
88
- ``` sh
89
- $ pip install
90
- ```
91
-
92
- ### Documentation
93
-
94
- Documentation can be found hosted on this GitHub
95
- [repository](https://github.com/risheekkumarb/llm_rsa)’s
96
- [pages](https://risheekkumarb.github.io/llm_rsa/). Additionally you can
97
- find package manager specific guidelines on
98
- [conda](https://anaconda.org/risheekkumarb/llm_rsa) and
99
- [pypi](https://pypi.org/project/llm_rsa) respectively.
100
-
101
- ## How to use
102
-
103
- ### Basic Usage
104
-
105
- Create an RSA instance with your task prompt and call it to run the
106
- aggregation:
107
-
108
- ``` python
109
- task_prompt = '''Three people check into a hotel room that costs $30. They each contribute $10.
110
- Later, the manager realizes the room only costs $25 and gives $5 to the bellboy to return.
111
- The bellboy keeps $2 and gives $1 back to each person.
112
- So each person paid $9 (total $27), plus the bellboy has $2, which equals $29.
113
- Where did the extra dollar go?'''
114
- ```
115
-
116
- ``` python
117
- agg_prompt = """Below is a reasoning problem followed by several candidate solutions.
118
- Your job is to:
119
- 1. Carefully analyze each candidate's reasoning step-by-step
120
- 2. Identify which candidates make logical errors or arithmetic mistakes
121
- 3. Note which approaches lead to correct reasoning
122
- 4. Synthesize the best reasoning into a single, clear, correct solution
123
-
124
- Show your work step-by-step, then state your final answer clearly."""
125
- ```
126
-
127
- ``` python
128
- from llm_rsa.core import RSA
129
-
130
- # Create RSA instance with a reasoning task
131
- rsa = RSA(
132
- task_prompt=task_prompt,
133
- agg_prompt=agg_prompt,
134
- M=4,
135
- k=2,
136
- loops=3
137
- )
138
-
139
- # Run the aggregation
140
- results = rsa.run()
141
- print(f"Generated {len(rsa.history)} total candidates across {rsa.loops} loops")
142
- print('llm response: \n', results[-1].response)
143
- ```
144
-
145
- Generated 12 total candidates across 3 loops
146
- llm response:
147
- ### Analysis of Candidate Reasoning
148
-
149
- Both **Candidate 1** and **Candidate 2** provide identical logical conclusions and correctly identify the fallacy.
150
- * They both recognize that $27 is the total amount the guests spent ($30 - $3 refund).
151
- * They both correctly point out that the $2 held by the bellboy is a *subset* of that $27, not an additional amount to be added to it.
152
- * They both demonstrate that the correct way to reach the original $30 is to add the $3 refund to the $27 spent, rather than adding the $2 tip to the $27 spent.
153
-
154
- The candidates effectively "debunked" the riddle's misdirection, which relies on the psychological trick of adding two numbers that do not belong together in a balance sheet.
155
-
156
- ---
157
-
158
- ### Step-by-Step Reasoning and Solution
159
-
160
- To solve the mystery of the "missing dollar," we must track the $30 carefully and distinguish between **Assets** (money held) and **Expenses** (money spent).
161
-
162
- **1. Track the $30 Total**
163
- At the end of the transaction, the $30 is distributed as follows:
164
- * **$25** is in the hotel's register (the actual price of the room).
165
- * **$2** is in the bellboy's pocket (the stolen tip).
166
- * **$3** is in the guests' pockets ($1 each).
167
- * **Total: $25 + $2 + $3 = $30.**
168
- Nothing is missing.
169
-
170
- **2. Analyze the Guest Perspective (The $27)**
171
- The riddle says: "Each person paid $9, total $27." This is correct. Let's look at what happened to that $27:
172
- * **$25** went to the hotel for the room.
173
- * **$2** went to the bellboy as a tip.
174
- * **Total: $25 + $2 = $27.**
175
- The $2 is already *inside* the $27.
176
-
177
- **3. Identify the Logical Fallacy**
178
- The riddle's error is the statement: *"Each person paid $9 (total $27), plus the bellboy has $2, which equals $29."*
179
- This is an accounting error. You cannot add the bellboy's $2 to the $27 because the bellboy's $2 is **part of** the $27.
180
-
181
- To reconcile the total to $30, you must add the money the guests **kept** (the $3 refund) to the money they **spent** ($27):
182
- * **$27 (Spent) + $3 (Refunded) = $30.**
183
-
184
- **Conclusion:**
185
- The "extra dollar" does not exist. The riddle creates an illusion by adding a component of an expense ($2) to the total expense ($27), rather than adding the remaining cash on hand ($3) to the total expense.
186
-
187
- ### Final Answer
188
- The dollar is not missing. The mistake is in the calculation: it adds the bellboy's $2 to the $27 spent, even though the $2 is already included in the $27. The correct calculation is $27 (spent) + $3 (returned to guests) = $30.
189
-
190
- ``` python
191
- from litellm import completion
192
-
193
- # Single direct call (baseline)
194
- response = completion(
195
- model='openrouter/google/gemini-3-flash-preview',
196
- messages=[{"role": "user", "content": task_prompt}],
197
- temperature=1.0
198
- )
199
- baseline_answer = response.choices[0].message.content
200
- print("=== BASELINE (single call) ===")
201
- print(baseline_answer)
202
- ```
203
-
204
- === BASELINE (single call) ===
205
- The extra dollar didn't go anywhere; the confusion comes from **adding** the bellboy's tip to the guests' expenses instead of **subtracting** it.
206
-
207
- Here is the correct breakdown of the math:
208
-
209
- ### 1. The Total Spent
210
- Each person paid $9, for a total of **$27**.
211
-
212
- ### 2. Where that $27 is currently located
213
- Of that $27:
214
- * **$25** is in the cash register (the actual price of the room).
215
- * **$2** is in the bellboy’s pocket.
216
- * **Total: $27.**
217
-
218
- ### 3. The Logical Fallacy
219
- The riddle tricks you by saying: *"$27 (paid) + $2 (bellboy) = $29."*
220
-
221
- This is an error in logic because the **$2 is already included in the $27**. You are essentially adding the bellboy's tip twice.
222
-
223
- **The correct math should be:**
224
- * **Total Spent ($27) + Total Refunded ($3) = $30**
225
- * OR
226
- * **Total Spent ($27) - Bellboy's Tip ($2) = Room Price ($25)**
227
-
228
- ### Configuration Options
229
-
230
- | Parameter | Default | Description |
231
- |----|----|----|
232
- | `task_prompt` | (required) | The main task/question to solve |
233
- | `model` | `'openrouter/google/gemini-3-flash-preview'` | LLM model to use (any litellm-compatible model) |
234
- | `M` | 8 | Number of candidates generated per loop |
235
- | `k` | 4 | Number of candidates sampled for each aggregation |
236
- | `loops` | 3 | Number of aggregation iterations |
237
- | `temperature` | 1.0 | LLM sampling temperature |
238
- | `n_workers` | 4 | Parallel workers for LLM calls |
239
- | `agg_prompt` | (auto) | Custom aggregation prompt (optional) |
240
-
241
- ### How RSA Works
242
-
243
- 1. **Loop 0**: Generate M independent responses to the task prompt
244
- 2. **Loop 1+**: For each of M new candidates, randomly sample k
245
- previous candidates and ask the LLM to aggregate them into an
246
- improved answer
247
- 3. **Repeat** for the specified number of loops
248
- 4. **Return** the final pool of aggregated candidates
249
-
250
- The `history` attribute stores all candidates across all loops, allowing
251
- you to trace the aggregation process.
@@ -1,9 +0,0 @@
1
- llm_rsa/__init__.py,sha256=QvlVh4JTl3JL7jQAja76yKtT-IvF4631ASjWY1wS6AQ,22
2
- llm_rsa/_modidx.py,sha256=ogPe8zhCHsthGKU9Xg2XJUrE0h6S6T87oFcbjPsRIrc,1581
3
- llm_rsa/core.py,sha256=V5jTmC0OxRZRKd3Y3Zf3E_zCDWbDRkwNok16NaS2GB8,5082
4
- llm_rsa-0.0.2.dist-info/licenses/LICENSE,sha256=xV8xoN4VOL0uw9X8RSs2IMuD_Ss_a9yAbtGNeBWZwnw,11337
5
- llm_rsa-0.0.2.dist-info/METADATA,sha256=JuVSzg2_azwzx78B2dKXFeLzXkQFh10PR7LcWAqMqlg,8871
6
- llm_rsa-0.0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
7
- llm_rsa-0.0.2.dist-info/entry_points.txt,sha256=pnciZLW9vjkfP635726PVzPYrDvpPRb1SrHrtZsQbgw,36
8
- llm_rsa-0.0.2.dist-info/top_level.txt,sha256=p3SxxJAnEYU4XsL4IJt9PSglY7nE4zlWf9IWo9Yu6_E,8
9
- llm_rsa-0.0.2.dist-info/RECORD,,