Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
disler committed Jan 11, 2025
1 parent e128c21 commit b042c51
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
8 changes: 7 additions & 1 deletion main_typer_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def deep(
context_files: List[str] = typer.Option(
[], "--context", "-c", help="List of context files"
),
mode: str = typer.Option(
"default",
"--mode",
"-m",
help="Execution mode: default (no exec), execute (exec + scratch), execute-no-scratch (exec only)"
),
):
"""Run STT interface that processes speech into typer commands"""
assistant, typer_file, scratchpad = TyperAgent.build_agent(typer_file, [scratchpad] + context_files)
Expand Down Expand Up @@ -111,7 +117,7 @@ def process_text(text):
return

recorder.stop()
output = assistant.process_text(text, typer_file, scratchpad)
output = assistant.process_text(text, typer_file, scratchpad, context_files, mode)
print(f"🤖 Response:\n{output}")
recorder.start()
except Exception as e:
Expand Down
58 changes: 32 additions & 26 deletions modules/typer_agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List
import os
import logging
from datetime import datetime
from modules.assistant_config import get_config
from modules.utils import (
build_file_name_session,
Expand Down Expand Up @@ -100,21 +101,12 @@ def build_prompt(
self.logger.error(f"❌ Error building prompt: {str(e)}")
raise

def process_text(self, text: str, typer_file: str, scratchpad: str, context_files: List[str]) -> str:
"""Process text input and execute as typer command"""

# don't act on the assistants last input
if self.previous_responses and text in self.previous_responses[-1]:
self.logger.info(
f"🤖 Previous response found for '{text}'",
extra={"skip_stdout": True},
)
return

def process_text(self, text: str, typer_file: str, scratchpad: str, context_files: List[str], mode: str) -> str:
"""Process text input and handle based on execution mode"""
try:
# Build fresh prompt with current state
formatted_prompt = self.build_prompt(typer_file, scratchpad, context_files, text)

# Generate command using DeepSeek
self.logger.info("🤖 Processing text with DeepSeek...")
prefix = f"python {typer_file}"
Expand All @@ -125,20 +117,34 @@ def process_text(self, text: str, typer_file: str, scratchpad: str, context_file
self.speak("I couldn't find that command")
return "Command not found"

# Execute the generated command
self.logger.info(f"⚡ Executing command: `{command}`")
output = execute_uv_python(command, typer_file)

# Conversational response
self.think_speak(
f"You've successfully executed the command: `{command}` based on the request: `{text}`"
)

# Log results
self.logger.info("✅ Command execution completed successfully")
self.logger.info(f"📄 Output:\n{output}")

return output
# Handle different modes
assistant_name = get_config("typer_assistant.assistant_name")
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

if mode == "default":
result = f"---\n{command}\n---"
append_text = f"\n\n{timestamp} - {assistant_name} generated:\n{result}"
with open(scratchpad, "a") as f:
f.write(append_text)
return result

elif mode == "execute":
self.logger.info(f"⚡ Executing command: `{command}`")
output = execute_uv_python(command, typer_file)

result = f"---\n{command}\n{output}\n---"
append_text = f"\n\n{timestamp} - {assistant_name} executed and generated:\n{result}"
with open(scratchpad, "a") as f:
f.write(append_text)
return output

elif mode == "execute-no-scratch":
self.logger.info(f"⚡ Executing command: `{command}`")
output = execute_uv_python(command, typer_file)
return output

else:
raise ValueError(f"Invalid mode: {mode}")

except Exception as e:
self.logger.error(f"❌ Error occurred: {str(e)}")
Expand Down

0 comments on commit b042c51

Please sign in to comment.