Skip to content

Commit e28112e

Browse files
committed
fix ruff
1 parent 37b7368 commit e28112e

File tree

5 files changed

+95
-66
lines changed

5 files changed

+95
-66
lines changed

dspy_code/commands/interactive_command.py

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -539,38 +539,52 @@ def _show_welcome(self):
539539
rag_config = self.config_manager.config.codebase_rag
540540
rag_enabled = rag_config.enabled if rag_config else True
541541
fast_mode = rag_config.fast_mode if rag_config else False
542-
542+
543543
# RAG status
544544
if self.codebase_rag and self.codebase_rag.enabled:
545545
if self.codebase_rag.index:
546546
element_count = len(self.codebase_rag.index.elements)
547547
rag_status = f"[cyan]RAG Mode:[/cyan] [green]ON[/green] ({element_count} elements indexed)"
548548
else:
549-
rag_status = "[cyan]RAG Mode:[/cyan] [yellow]ON[/yellow] (no index - run /init to build)"
549+
rag_status = (
550+
"[cyan]RAG Mode:[/cyan] [yellow]ON[/yellow] (no index - run /init to build)"
551+
)
550552
else:
551553
rag_status = "[cyan]RAG Mode:[/cyan] [red]OFF[/red] (use /enable-rag to enable)"
552-
554+
553555
# Fast Mode status
554-
fast_status = f"[cyan]Fast Mode:[/cyan] [green]ON[/green]" if fast_mode else f"[cyan]Fast Mode:[/cyan] [yellow]OFF[/yellow]"
555-
556+
fast_status = (
557+
"[cyan]Fast Mode:[/cyan] [green]ON[/green]"
558+
if fast_mode
559+
else "[cyan]Fast Mode:[/cyan] [yellow]OFF[/yellow]"
560+
)
561+
556562
console.print()
557563
console.print("[bold]Performance Settings:[/bold]")
558564
console.print(f" {rag_status}")
559565
console.print(f" {fast_status}")
560-
566+
561567
# Add humorous message about quality vs speed
562568
if rag_enabled and not fast_mode:
563569
console.print()
564570
console.print("[dim]💡 Awesomeness takes time (but you can toggle anytime!)[/dim]")
565-
console.print("[dim] Use [cyan]/fast-mode on[/cyan] for faster responses or check [cyan]/status[/cyan] for details[/dim]")
571+
console.print(
572+
"[dim] Use [cyan]/fast-mode on[/cyan] for faster responses or check [cyan]/status[/cyan] for details[/dim]"
573+
)
566574
elif not rag_enabled:
567575
console.print()
568576
console.print("[dim]💡 RAG disabled - faster startup, lower code quality[/dim]")
569-
console.print("[dim] Use [cyan]/enable-rag[/cyan] to enable or check [cyan]/status[/cyan] for details[/dim]")
577+
console.print(
578+
"[dim] Use [cyan]/enable-rag[/cyan] to enable or check [cyan]/status[/cyan] for details[/dim]"
579+
)
570580
elif fast_mode:
571581
console.print()
572-
console.print("[dim]💡 Fast mode enabled - quick responses, slightly lower quality[/dim]")
573-
console.print("[dim] Use [cyan]/fast-mode off[/cyan] for better quality or check [cyan]/status[/cyan] for details[/dim]")
582+
console.print(
583+
"[dim]💡 Fast mode enabled - quick responses, slightly lower quality[/dim]"
584+
)
585+
console.print(
586+
"[dim] Use [cyan]/fast-mode off[/cyan] for better quality or check [cyan]/status[/cyan] for details[/dim]"
587+
)
574588
except Exception as e:
575589
logger.debug(f"Error showing performance status: {e}")
576590
console.print("[dim]Performance: Status unknown[/dim]")
@@ -1917,11 +1931,7 @@ def _build_context_with_rag(self, user_input: str, reference: str) -> dict[str,
19171931
}
19181932

19191933
# Check if RAG is enabled and not in fast mode
1920-
rag_enabled = (
1921-
self.codebase_rag
1922-
and self.codebase_rag.enabled
1923-
and not self._is_fast_mode()
1924-
)
1934+
rag_enabled = self.codebase_rag and self.codebase_rag.enabled and not self._is_fast_mode()
19251935

19261936
# Add comprehensive RAG context from DSPy and GEPA source code
19271937
if rag_enabled:
@@ -1954,17 +1964,23 @@ def _build_context_with_rag(self, user_input: str, reference: str) -> dict[str,
19541964
if any(word in user_lower for word in ["react", "agent", "tool", "action"]):
19551965
specific_queries.append("dspy.ReAct agent tools")
19561966
if any(
1957-
word in user_lower for word in ["gepa", "optimize", "optimization", "genetic"]
1967+
word in user_lower
1968+
for word in ["gepa", "optimize", "optimization", "genetic"]
19581969
):
19591970
specific_queries.append("GEPA Genetic Pareto optimization")
19601971
if any(word in user_lower for word in ["chain", "thought", "reasoning", "cot"]):
19611972
specific_queries.append("dspy.ChainOfThought reasoning")
1962-
if any(word in user_lower for word in ["signature", "input", "output", "field"]):
1973+
if any(
1974+
word in user_lower for word in ["signature", "input", "output", "field"]
1975+
):
19631976
specific_queries.append("dspy.Signature InputField OutputField")
1964-
if any(word in user_lower for word in ["mcp", "model context protocol", "server"]):
1977+
if any(
1978+
word in user_lower for word in ["mcp", "model context protocol", "server"]
1979+
):
19651980
specific_queries.append("MCP Model Context Protocol client")
19661981
if any(
1967-
word in user_lower for word in ["async", "streaming", "streamify", "asyncify"]
1982+
word in user_lower
1983+
for word in ["async", "streaming", "streamify", "asyncify"]
19681984
):
19691985
specific_queries.append("dspy async streaming asyncify streamify")
19701986
if any(word in user_lower for word in ["adapter", "json", "xml", "chat"]):
@@ -1985,7 +2001,9 @@ def _build_context_with_rag(self, user_input: str, reference: str) -> dict[str,
19852001
context["additional_examples"] = "\n".join(additional_context)
19862002
logger.debug(f"Added {len(additional_context)} additional context sections")
19872003
else:
1988-
logger.debug("Skipping pattern-specific searches (skip_pattern_searches enabled)")
2004+
logger.debug(
2005+
"Skipping pattern-specific searches (skip_pattern_searches enabled)"
2006+
)
19892007

19902008
except Exception as e:
19912009
logger.warning(f"Failed to get RAG context: {e}")
@@ -2026,16 +2044,16 @@ def _is_fast_mode(self) -> bool:
20262044
def _show_performance_tip_if_needed(self, generation_time: float):
20272045
"""Show performance tip after slow response."""
20282046
# Only show once per session
2029-
if hasattr(self, '_performance_tip_shown'):
2047+
if hasattr(self, "_performance_tip_shown"):
20302048
return
2031-
2049+
20322050
# Only show if RAG enabled and fast mode disabled
20332051
if not (self.codebase_rag and self.codebase_rag.enabled):
20342052
return
2035-
2053+
20362054
if self._is_fast_mode():
20372055
return
2038-
2056+
20392057
console.print()
20402058
console.print(
20412059
f"[dim]⏱️ That took {generation_time:.1f}s. "
@@ -2044,7 +2062,7 @@ def _show_performance_tip_if_needed(self, generation_time: float):
20442062
)
20452063
console.print("[dim] Or check [cyan]/status[/cyan] for all performance settings[/dim]")
20462064
console.print()
2047-
2065+
20482066
self._performance_tip_shown = True
20492067

20502068
def _build_template_context(self, user_input: str) -> str:
@@ -2288,14 +2306,15 @@ def _generate_signature_with_llm(self, user_input: str) -> str:
22882306

22892307
# Generate with LLM (track time for performance tips)
22902308
import time
2309+
22912310
start_time = time.time()
2292-
2311+
22932312
response = self.llm_connector.generate_response(
22942313
prompt=enhanced_prompt, system_prompt=system_prompt, context=context
22952314
)
2296-
2315+
22972316
generation_time = time.time() - start_time
2298-
2317+
22992318
# Show performance tip if slow
23002319
if generation_time > 3.0:
23012320
self._show_performance_tip_if_needed(generation_time)
@@ -2513,14 +2532,15 @@ def forward(self, input_text):
25132532

25142533
# Generate with LLM (track time for performance tips)
25152534
import time
2535+
25162536
start_time = time.time()
2517-
2537+
25182538
response = self.llm_connector.generate_response(
25192539
prompt=enhanced_prompt, system_prompt=system_prompt, context=context
25202540
)
2521-
2541+
25222542
generation_time = time.time() - start_time
2523-
2543+
25242544
# Show performance tip if slow
25252545
if generation_time > 3.0:
25262546
self._show_performance_tip_if_needed(generation_time)

dspy_code/commands/slash_commands.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,9 @@ def cmd_status(self, args: list):
676676
rag_config = self.config_manager.config.codebase_rag
677677
rag_enabled = rag_config.enabled if rag_config else True
678678
fast_mode = rag_config.fast_mode if rag_config else False
679-
679+
680680
console.print("[bold]⚡ Performance Settings:[/bold]")
681-
681+
682682
# RAG status
683683
if rag_enabled:
684684
rag_status = "[green]ON[/green]"
@@ -690,27 +690,31 @@ def cmd_status(self, args: list):
690690
rag_status += " (no index - run /init)"
691691
else:
692692
rag_status = "[red]OFF[/red]"
693-
693+
694694
console.print(f" [cyan]RAG Mode:[/cyan] {rag_status}")
695-
695+
696696
# Fast Mode status
697697
fast_status = "[green]ON[/green]" if fast_mode else "[yellow]OFF[/yellow]"
698698
console.print(f" [cyan]Fast Mode:[/cyan] {fast_status}")
699-
699+
700700
# Show tips based on current settings
701701
if rag_enabled and not fast_mode:
702702
console.print()
703703
console.print("[dim]💡 Awesomeness takes time (but you can toggle anytime!)[/dim]")
704-
console.print("[dim] Use [cyan]/fast-mode on[/cyan] for faster responses (0.5-1s)[/dim]")
704+
console.print(
705+
"[dim] Use [cyan]/fast-mode on[/cyan] for faster responses (0.5-1s)[/dim]"
706+
)
705707
elif not rag_enabled:
706708
console.print()
707709
console.print("[dim]💡 RAG disabled - faster startup, lower code quality[/dim]")
708710
console.print("[dim] Use [cyan]/enable-rag[/cyan] for better code quality[/dim]")
709711
elif fast_mode:
710712
console.print()
711-
console.print("[dim]💡 Fast mode enabled - quick responses, slightly lower quality[/dim]")
713+
console.print(
714+
"[dim]💡 Fast mode enabled - quick responses, slightly lower quality[/dim]"
715+
)
712716
console.print("[dim] Use [cyan]/fast-mode off[/cyan] for better quality[/dim]")
713-
717+
714718
except Exception as e:
715719
logger.debug(f"Error showing performance settings: {e}")
716720

@@ -2998,10 +3002,14 @@ def cmd_fast_mode(self, args: list):
29983002
console.print()
29993003
console.print(f"[cyan]Fast mode:[/cyan] {status}")
30003004
if is_fast:
3001-
console.print("[dim]RAG context building is disabled for faster responses[/dim]")
3005+
console.print(
3006+
"[dim]RAG context building is disabled for faster responses[/dim]"
3007+
)
30023008
console.print("[yellow]Note: Code generation quality may be reduced[/yellow]")
30033009
else:
3004-
console.print("[dim]RAG context building is enabled for better code quality[/dim]")
3010+
console.print(
3011+
"[dim]RAG context building is enabled for better code quality[/dim]"
3012+
)
30053013
console.print()
30063014
return
30073015
except Exception as e:
@@ -3044,7 +3052,9 @@ def cmd_disable_rag(self, args: list):
30443052
console.print()
30453053
show_success_message("RAG disabled")
30463054
console.print("[dim]RAG indexing disabled - faster startup and responses[/dim]")
3047-
console.print("[yellow]Note: Code generation quality may be significantly reduced[/yellow]")
3055+
console.print(
3056+
"[yellow]Note: Code generation quality may be significantly reduced[/yellow]"
3057+
)
30483058
console.print()
30493059
except Exception as e:
30503060
show_error_message(f"Error disabling RAG: {e}")

0 commit comments

Comments
 (0)