44
55from config import MAX_DISPLAY_SIZE , EXAMPLE_REPOS
66from gitingest import ingest_from_query , clone_repo , parse_query
7- from server_utils import logSliderToSize
7+ from server_utils import logSliderToSize , Colors
88
99templates = Jinja2Templates (directory = "templates" )
1010
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+
1134async def process_query (request : Request , input_text : str , slider_position : int , pattern_type : str = "exclude" , pattern : str = "" , is_index : bool = False ) -> str :
1235 template = "index.jinja" if is_index else "github.jinja"
1336 max_file_size = logSliderToSize (slider_position )
@@ -23,11 +46,14 @@ async def process_query(request: Request, input_text: str, slider_position: int,
2346 summary , tree , content = ingest_from_query (query )
2447 with open (f"{ query ['local_path' ]} .txt" , "w" ) as f :
2548 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+
3052 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 } " )
3157 return templates .TemplateResponse (
3258 template ,
3359 {
@@ -43,7 +69,7 @@ async def process_query(request: Request, input_text: str, slider_position: int,
4369
4470 if len (content ) > MAX_DISPLAY_SIZE :
4571 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 )
4773 return templates .TemplateResponse (
4874 template ,
4975 {
0 commit comments