Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,7 @@ Thank you for considering contributing! Please follow these steps:
`LinkedIn` - [Visit](https://linkedin.com/in/anshsoni) </br>
`Follow Us` - [Visit](https://linkedin.com/company/py-shell)

### Recent updates check:
updates_to_read.md

## Thankyou 😀<br/>
4 changes: 4 additions & 0 deletions ai_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"api_key": "123",
"smart_suggestions": true
}
99 changes: 99 additions & 0 deletions ai_panel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import json
import os
from prompt_toolkit.shortcuts import checkboxlist_dialog, radiolist_dialog
from rich.console import Console

console = Console()
AI_CONFIG_FILE = "ai_config.json"

def load_ai_config():
"""Loads the AI feature configuration from a JSON file."""
if os.path.exists(AI_CONFIG_FILE):
try:
with open(AI_CONFIG_FILE, 'r') as f:
return json.load(f)
except (json.JSONDecodeError, IOError):
pass
return {"smart_suggestions": False}

def save_ai_config(config):
"""Saves the AI feature configuration to a JSON file."""
with open(AI_CONFIG_FILE, 'w') as f:
json.dump(config, f, indent=4)

def show_config_panel():
"""Shows a checklist to toggle AI features ON or OFF."""
config = load_ai_config()
default_values = [key for key, value in config.items() if value]

results = checkboxlist_dialog(
title="⚙️ AI Configuration",
text="Use SPACE to toggle features ON/OFF. Press ENTER to save.",
values=[
("smart_suggestions", "💡 Live Smart Suggestions"),
],
default_values=default_values
).run()

if results is not None:
config["smart_suggestions"] = "smart_suggestions" in results
save_ai_config(config)
status = "ON" if config["smart_suggestions"] else "OFF"
console.print(f"\n[bold green]Live Smart Suggestions are now {status}[/bold green]")

def show_ai_features():
"""Shows the AI features menu."""
from features import nl_to_code, error_explainer, snippet_search, code_refactor

AI_FEATURES = [
("nl", "🧠 NL to Code", nl_to_code.run),
("explain", "❌ Error Explainer", error_explainer.run),
("snippet", "📚 Snippet Search", snippet_search.run),
("refactor", "🧹 Code Refactor", code_refactor.run),
("back", "↩️ Back to Main Menu", None)
]

while True:
choice = radiolist_dialog(
title="🤖 AI Features",
text="Select an AI feature to run:",
values=[(key, label) for key, label, _ in AI_FEATURES],
).run()

if choice is None or choice == "back":
break

# Find and run the selected feature
for key, label, func in AI_FEATURES:
if key == choice and func:
try:
func()
except Exception as e:
print(f"[Error in {label}]: {e}")
input("\nPress Enter to return to the AI features menu...")
break

def show_ai_panel():
"""Main AI panel with options to configure or run features."""
while True:
choice = radiolist_dialog(
title="🤖 PyShell AI Panel",
text="Choose an option:",
values=[
("features", "🚀 Run AI Features"),
("config", "⚙️ Configure AI Settings"),
("exit", "↩️ Return to Shell")
],
).run()

if choice == "features":
show_ai_features()
elif choice == "config":
show_config_panel()
elif choice == "exit" or choice is None:
break

def is_feature_enabled(feature_name):
"""Checks if a specific AI feature is enabled in the config."""
config = load_ai_config()
return config.get(feature_name, False)
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
current_terminal_layout = 8
current_terminal_layout = 2
154 changes: 153 additions & 1 deletion equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
from sympy.parsing.sympy_parser import parse_expr
import re
from sympy.abc import x
import time
import msvcrt
from rich.table import Table
from menu_base import MojiSwitchMenu
from statistics_menu import show_statistics_menu

console = Console()

Expand Down Expand Up @@ -119,4 +124,151 @@ def solve_differential(self, args):
f"[red]❌ Error:[/red] {str(e)}\n"
"Please ensure your equation is in the correct format.",
title="⚠️ Invalid Input", border_style="red"
))
))

def show_equations_menu():
# Define options for equation operations
options = [
("➕ Basic Math", "basic"),
("📐 Algebra", "algebra"),
("📊 Calculus", "calculus"),
("📈 Statistics", "stats"),
("🔢 Matrix", "matrix")
]

def on_execute(state):
# Get list of enabled operations
enabled_ops = [name for name, value in options if state[value]]
if not enabled_ops:
console.print("[bold red]No operations selected![/bold red]")
return

# Animate calculation
animate_calculation()

# Process each enabled operation
results = {}
for op in enabled_ops:
# Simulate calculation
time.sleep(0.5)
results[op] = f"Result for {op}"

# Display results
animate_results_display(results)

# Create and run menu
menu = MojiSwitchMenu(
title="🧮 Equation Operations",
options=options,
on_execute=on_execute
)
menu.run()

def display_equation_table(equations):
"""Display equations in a modern table format"""
table = Table(
show_header=True,
header_style="bold cyan",
box=None,
padding=(0, 1)
)

# Add columns
table.add_column("No.", style="dim", width=4)
table.add_column("Type", style="bold")
table.add_column("Description", style="italic")
table.add_column("Status", justify="center", width=4)

# Add rows with equation types
features = [
("1", "Basic Math", "Arithmetic and algebraic operations", "basic"),
("2", "Algebra", "Solve linear and quadratic equations", "algebra"),
("3", "Calculus", "Derivatives and integrals", "calculus"),
("4", "Statistics", "Statistical formulas and calculations", "stats"),
("5", "Matrix", "Matrix operations and determinants", "matrix")
]

for no, name, desc, key in features:
status = "✅" if equations.get(key, False) else "❌"
table.add_row(no, name, desc, status)

# Create panel with table
panel = Panel(
table,
title="🧮 Equation Types",
border_style="cyan",
padding=(1, 2)
)

console.print(panel)

def animate_calculation():
"""Animate calculation with a spinning effect"""
spinner = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
console.print("\n")
for _ in range(20): # 2 seconds of animation
for char in spinner:
console.print(f"\033[A\033[K[bold blue]{char} Calculating...[/bold blue]")
time.sleep(0.1)
console.print("\n")

def animate_results_display(results):
"""Animate results display with a fade-in effect"""
console.print("\n")
for i in range(3):
console.print("\033[A\033[K", end="")
if i == 0:
for key, value in results.items():
console.print(f"[grey50]{key}: {value}[/grey50]")
elif i == 1:
for key, value in results.items():
console.print(f"[bold blue]{key}: {value}[/bold blue]")
else:
for key, value in results.items():
console.print(f"[bold green]{key}: {value}[/bold green]")
time.sleep(0.2)
console.print("\n")

def animate_equation_solving(equation):
"""Animate equation solving with a step-by-step effect"""
console.print("\n")
steps = [
f"Original equation: {equation}",
"Simplifying...",
"Solving for x...",
"Checking solution..."
]

for step in steps:
console.print(f"\033[A\033[K[bold blue]{step}[/bold blue]")
time.sleep(0.5)
console.print("\n")

def animate_matrix_operation():
"""Animate matrix operation with a progress bar effect"""
console.print("\n")
for i in range(10):
progress = "█" * i + "░" * (10 - i)
console.print(f"\033[A\033[K[bold blue]Performing matrix operation: [{progress}] {i*10}%[/bold blue]")
time.sleep(0.2)
console.print("\n")

def solve_equation(equation_str):
try:
# Split equation into left and right sides
left, right = equation_str.split('=')

# Convert strings to sympy expressions
left_expr = parse_expr(left.strip())
right_expr = parse_expr(right.strip())

# Create equation
equation = Eq(left_expr, right_expr)

# Solve equation
solution = solve(equation, x)

return solution
except Exception as e:
console.print(f"Error solving equation: {e}", style="bold red")
return None
10 changes: 10 additions & 0 deletions features/code_refactor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from local_llm_client import run_llama_prompt
import sys

def run():
print("\n🧹 Paste your code below (CTRL+D to end):")
code = sys.stdin.read()
prompt = f"Refactor this code for better readability and performance:\n{code}"
result = run_llama_prompt(prompt)
print("\n🔧 Refactored Code:\n")
print(result)
7 changes: 7 additions & 0 deletions features/error_explainer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from local_llm_client import run_llama_prompt

def run():
error = input("\n❌ Paste the error message: ")
prompt = f"Explain and fix this error:\n{error}"
explanation = run_llama_prompt(prompt)
print(f"\n🛠️ Explanation:\n{explanation}")
13 changes: 13 additions & 0 deletions features/nl_to_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from local_llm_client import run_llama_prompt
import os

def run():
instruction = input("\n💬 Describe your task: ")
prompt = f"Convert this to a shell command:\nInstruction: {instruction}\nCommand:"
command = run_llama_prompt(prompt)
if command:
print(f"\n🧠 Suggested Command: {command}")
if input("Run it? (y/n): ").lower().startswith("y"):
os.system(command)
else:
print("\nCould not generate a command.")
Loading