4
4
5
5
from config import MAX_DISPLAY_SIZE , EXAMPLE_REPOS
6
6
from gitingest import ingest_from_query , clone_repo , parse_query
7
- from server_utils import logSliderToSize
7
+ from server_utils import logSliderToSize , Colors
8
8
9
9
templates = Jinja2Templates (directory = "templates" )
10
10
11
+ def print_query (query , request , max_file_size , pattern_type , pattern ):
12
+ print (f"{ Colors .WHITE } { query ['url' ]:<20} { Colors .END } " , end = "" )
13
+ if int (max_file_size / 1024 ) != 50 :
14
+ print (f" | { Colors .PURPLE } Size: { int (max_file_size / 1024 )} kb{ Colors .END } " , end = "" )
15
+ if pattern_type == "include" and pattern != "" :
16
+ print (f" | { Colors .BLUE } Include { pattern } { Colors .END } " , end = "" )
17
+ elif pattern_type == "exclude" and pattern != "" :
18
+ print (f" | { Colors .YELLOW } Exclude { pattern } { Colors .END } " , end = "" )
19
+
20
+
21
+ def print_error (query , request , e , max_file_size , pattern_type , pattern ):
22
+ print (f"{ Colors .BROWN } WARNING{ Colors .END } : { Colors .RED } <- { Colors .END } " , end = "" )
23
+ print_query (query , request , max_file_size , pattern_type , pattern )
24
+ print (f" | { Colors .RED } { e } { Colors .END } " )
25
+
26
+ def print_success (query , request , max_file_size , pattern_type , pattern , summary ):
27
+ estimated_tokens = summary [summary .index ("Estimated tokens:" ) + len ("Estimated " ) :]
28
+ print (f"{ Colors .GREEN } INFO{ Colors .END } : { Colors .GREEN } <- { Colors .END } " , end = "" )
29
+ print_query (query , request , max_file_size , pattern_type , pattern )
30
+ print (f" | { Colors .PURPLE } { estimated_tokens } { Colors .END } " )
31
+
32
+
33
+
11
34
async def process_query (request : Request , input_text : str , slider_position : int , pattern_type : str = "exclude" , pattern : str = "" , is_index : bool = False ) -> str :
12
35
template = "index.jinja" if is_index else "github.jinja"
13
36
max_file_size = logSliderToSize (slider_position )
@@ -23,11 +46,14 @@ async def process_query(request: Request, input_text: str, slider_position: int,
23
46
summary , tree , content = ingest_from_query (query )
24
47
with open (f"{ query ['local_path' ]} .txt" , "w" ) as f :
25
48
f .write (tree + "\n " + content )
26
- print (f"{ query ['slug' ]:<20} " , end = "" )
27
- if pattern and pattern != "" :
28
- print (f"{ pattern_type } [{ pattern } ]" , end = "" )
29
- print (f"\n { query ['url' ]} " )
49
+
50
+
51
+
30
52
except Exception as e :
53
+ if 'query' in locals () and query is not None and isinstance (query , dict ):
54
+ print_error (query , request , e , max_file_size , pattern_type , pattern )
55
+ else :
56
+ print (f"{ Colors .RED } Error: { e } { Colors .END } " )
31
57
return templates .TemplateResponse (
32
58
template ,
33
59
{
@@ -43,7 +69,7 @@ async def process_query(request: Request, input_text: str, slider_position: int,
43
69
44
70
if len (content ) > MAX_DISPLAY_SIZE :
45
71
content = f"(Files content cropped to { int (MAX_DISPLAY_SIZE / 1000 )} k characters, download full ingest to see more)\n " + content [:MAX_DISPLAY_SIZE ]
46
-
72
+ print_success ( query , request , max_file_size , pattern_type , pattern , summary )
47
73
return templates .TemplateResponse (
48
74
template ,
49
75
{
0 commit comments