Skip to content

Commit 6bb271f

Browse files
committed
feat/max_file_size: Added ability to manually input the max file size instead of using the slider
- Added two (2) new arguments to the POST route in 'index.py' called 'max_file_size_manual' and 'use_manual_input' - The query_processor now directly uses the max file size value instead of using the log_slider_to_size function if the value provided is from the manual file size input
1 parent 3cee672 commit 6bb271f

File tree

3 files changed

+109
-17
lines changed

3 files changed

+109
-17
lines changed

src/server/query_processor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Process a query by parsing input, cloning a repository, and generating a summary. """
1+
"""Process a query by parsing input, cloning a repository, and generating a summary."""
22

33
from functools import partial
44

@@ -19,6 +19,7 @@ async def process_query(
1919
pattern_type: str = "exclude",
2020
pattern: str = "",
2121
is_index: bool = False,
22+
is_file_size_manual: bool = False,
2223
) -> _TemplateResponse:
2324
"""
2425
Process a query by parsing input, cloning a repository, and generating a summary.
@@ -40,6 +41,8 @@ async def process_query(
4041
Pattern to include or exclude in the query, depending on the pattern type.
4142
is_index : bool
4243
Flag indicating whether the request is for the index page (default is False).
44+
is_file_size_manual: bool
45+
Flag indicating if the file size provided is via the manual input (default to False).
4346
4447
Returns
4548
-------
@@ -62,7 +65,7 @@ async def process_query(
6265

6366
template = "index.jinja" if is_index else "git.jinja"
6467
template_response = partial(templates.TemplateResponse, name=template)
65-
max_file_size = log_slider_to_size(slider_position)
68+
max_file_size = slider_position if is_file_size_manual else log_slider_to_size(slider_position)
6669

6770
context = {
6871
"request": request,

src/server/routers/index.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
""" This module defines the FastAPI router for the home page of the application. """
1+
"""This module defines the FastAPI router for the home page of the application."""
2+
3+
from typing import Optional
24

35
from fastapi import APIRouter, Form, Request
46
from fastapi.responses import HTMLResponse
@@ -45,6 +47,8 @@ async def index_post(
4547
request: Request,
4648
input_text: str = Form(...),
4749
max_file_size: int = Form(...),
50+
max_file_size_manual: Optional[str] = Form(None),
51+
use_manual_input: bool = Form(...),
4852
pattern_type: str = Form(...),
4953
pattern: str = Form(...),
5054
) -> HTMLResponse:
@@ -67,18 +71,28 @@ async def index_post(
6771
The type of pattern used for the query, specified by the user.
6872
pattern : str
6973
The pattern string used in the query, specified by the user.
74+
use_manual_input : bool
75+
Whether to use the manual input instead of the slider, by default False.
76+
max_file_size_manual : Optional[str], optional
77+
The manually entered file size in KB, by default None.
7078
7179
Returns
7280
-------
7381
HTMLResponse
7482
An HTML response containing the results of processing the form input and query logic,
7583
which will be rendered and returned to the user.
7684
"""
85+
# Determine the file size based on the input method
86+
max_file_size = int(max_file_size_manual) * 1024 if use_manual_input else max_file_size
87+
# Print debug information
88+
print(f"Received value: {max_file_size_manual}")
89+
print(f"Manual: {use_manual_input}")
7790
return await process_query(
7891
request,
7992
input_text,
8093
max_file_size,
8194
pattern_type,
8295
pattern,
8396
is_index=True,
97+
is_file_size_manual=use_manual_input,
8498
)

src/server/templates/components/git_form.jinja

Lines changed: 89 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
<script>
2+
document.addEventListener('DOMContentLoaded', function() {
3+
const checkbox = document.getElementById('use_manual_input');
4+
const hiddenInput = document.getElementById('file_size_manual');
5+
6+
if (hiddenInput.value === "true") {
7+
checkbox.checked = true;
8+
toggleSizeInputType(checkbox);
9+
}
10+
});
11+
212
function changePattern(element) {
313
console.log("Pattern changed", element.value);
414
let patternType = element.value;
@@ -8,7 +18,6 @@
818
if (element.textContent.includes("Directory structure:")) {
919
return;
1020
}
11-
1221
element.classList.toggle('line-through');
1322
element.classList.toggle('text-gray-500');
1423
element.classList.toggle('hover:text-inherit');
@@ -17,6 +26,41 @@
1726
element.classList.toggle('hover:text-gray-500');
1827
});
1928
}
29+
30+
function toggleSizeInputType(element) {
31+
const hiddenInput = document.getElementById('file_size_manual');
32+
const sliderContainer = document.getElementById('slider_container');
33+
const manualSizeInput = document.getElementById('manual_size_input_container');
34+
const manualSizeValueInput = document.getElementById('max_file_size_manual_input');
35+
const hiddenSizeInput = document.getElementById('max_file_size_manual');
36+
hiddenSizeInput.value = manualSizeValueInput.value;
37+
hiddenInput.value = element.checked ? "true" : "false";
38+
39+
if (element.checked) {
40+
sliderContainer.classList.add('hidden');
41+
manualSizeInput.classList.remove('hidden');
42+
43+
if (!manualSizeValueInput.value || manualSizeValueInput.value.trim() === '') {
44+
manualSizeValueInput.value = "1024";
45+
}
46+
hiddenSizeInput.value = manualSizeValueInput.value || "1024";
47+
} else {
48+
sliderContainer.classList.remove('hidden');
49+
manualSizeInput.classList.add('hidden');
50+
51+
const sliderValue = document.getElementById('file_size').value;
52+
hiddenSizeInput.value = sliderValue;
53+
}
54+
55+
console.log("Use manual input: " + hiddenInput.value);
56+
console.log("Manual size value: " + hiddenSizeInput.value);
57+
}
58+
59+
function updateManualSizeValue(element) {
60+
const hiddenSizeInput = document.getElementById('max_file_size_manual');
61+
hiddenSizeInput.value = element.value || "1024";
62+
console.log("Manual size updated to: " + hiddenSizeInput.value + "KB");
63+
}
2064
</script>
2165
<div class="relative">
2266
<div class="w-full h-full absolute inset-0 bg-gray-900 rounded-xl translate-y-2 translate-x-2"></div>
@@ -43,10 +87,18 @@
4387
Ingest
4488
</button>
4589
</div>
90+
<input type="hidden"
91+
id="file_size_manual"
92+
name="use_manual_input"
93+
value="{{ use_manual_input }}">
94+
<input type="hidden"
95+
id="max_file_size_manual"
96+
name="max_file_size_manual"
97+
value="{{ max_file_size_manual }}">
4698
<input type="hidden" name="pattern_type" value="exclude">
4799
<input type="hidden" name="pattern" value="">
48100
</form>
49-
<div class="mt-4 relative z-20 flex flex-wrap gap-4 items-start">
101+
<div class="mt-4 relative z-20 flex flex-wrap gap-4 items-center">
50102
<!-- Pattern selector -->
51103
<div class="w-[200px] sm:w-[250px] mr-9 mt-4">
52104
<div class="relative">
@@ -83,18 +135,41 @@
83135
</div>
84136
</div>
85137
</div>
86-
<div class="w-[200px] sm:w-[200px] mt-3">
87-
<label for="file_size" class="block text-gray-700 mb-1">
88-
Include files under: <span id="size_value" class="font-bold">50kb</span>
89-
</label>
90-
<input type="range"
91-
id="file_size"
92-
name="max_file_size"
93-
min="0"
94-
max="500"
95-
required
96-
value="{{ default_file_size }}"
97-
class="w-full h-3 bg-[#FAFAFA] bg-no-repeat bg-[length:50%_100%] bg-[#ebdbb7] appearance-none border-[3px] border-gray-900 rounded-sm focus:outline-none bg-gradient-to-r from-[#FE4A60] to-[#FE4A60] [&::-webkit-slider-thumb]:w-5 [&::-webkit-slider-thumb]:h-7 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:bg-white [&::-webkit-slider-thumb]:rounded-sm [&::-webkit-slider-thumb]:cursor-pointer [&::-webkit-slider-thumb]:border-solid [&::-webkit-slider-thumb]:border-[3px] [&::-webkit-slider-thumb]:border-gray-900 [&::-webkit-slider-thumb]:shadow-[3px_3px_0_#000] ">
138+
<div class="flex items-center gap-4 h-[50px]">
139+
<div class="mt-4">
140+
<label class="flex flex-col items-center cursor-pointer">
141+
<input type="checkbox" id="use_manual_input" name="use_manual_input" value="false" checked={false} class="sr-only peer w-12" onchange="toggleSizeInputType(this)">
142+
<div class="relative w-12 h-6 bg-[#ebdbb7] peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-[#FE4A60]/30 rounded-full peer border-[2px] border-gray-900 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-5 after:transition-all peer-checked:bg-[#FE4A60]">
143+
</div>
144+
<p class="ms-1 text-sm font-medium text-gray-900">Manual</p>
145+
</label>
146+
</div>
147+
<div id="slider_container" class="w-[200px] sm:w-[200px] mt-3">
148+
<label for="file_size" class="block text-gray-700 mb-1">
149+
Include files under: <span id="size_value" class="font-bold">50kb</span>
150+
</label>
151+
<input type="range"
152+
id="file_size"
153+
name="max_file_size"
154+
min="0"
155+
max="500"
156+
required
157+
value="{{ default_file_size }}"
158+
class="w-full h-3 bg-[#FAFAFA] bg-no-repeat bg-[length:50%_100%] bg-[#ebdbb7] appearance-none border-[3px] border-gray-900 rounded-sm focus:outline-none bg-gradient-to-r from-[#FE4A60] to-[#FE4A60] [&::-webkit-slider-thumb]:w-5 [&::-webkit-slider-thumb]:h-7 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:bg-white [&::-webkit-slider-thumb]:rounded-sm [&::-webkit-slider-thumb]:cursor-pointer [&::-webkit-slider-thumb]:border-solid [&::-webkit-slider-thumb]:border-[3px] [&::-webkit-slider-thumb]:border-gray-900 [&::-webkit-slider-thumb]:shadow-[3px_3px_0_#000]">
159+
</div>
160+
<div id="manual_size_input_container" class="hidden mt-3">
161+
<label for="max_file_size_manual_input" class="block text-gray-700 mb-1">Manual size (kb):</label>
162+
<input type="number"
163+
id="max_file_size_manual_input"
164+
name="max_file_size_manual"
165+
min="1"
166+
max="102400"
167+
value="1024"
168+
class="lg:w-[150px] sm:w-[100px] border-[3px] border-gray-900 rounded-sm focus:outline-none bg-[#ebdbb7] appearance-none indent-2"
169+
style="-webkit-appearance: none;
170+
color: #333"
171+
onchange="updateManualSizeValue(this)">
172+
</div>
98173
</div>
99174
</div>
100175
{% if show_examples %}

0 commit comments

Comments
 (0)