Skip to content

Commit

Permalink
refactor: instantiate DirectoryManager and ConversationManager in com…
Browse files Browse the repository at this point in the history
…mand functions to improve performance
  • Loading branch information
shxntanu committed Jan 5, 2025
1 parent 8819fc6 commit 1421ffc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lesa/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
from lesa.core.conversations import ConversationManager
from lesa.core.directory_manager import DirectoryManager

dm = DirectoryManager()
cm = ConversationManager(directory_manager_instance=dm)

console = Console()
app = typer.Typer()

Expand All @@ -41,11 +38,13 @@ def start():
"""
Starts ollama server and ensures the default LLM model is available.
Returns:
Optional[subprocess.Popen]: Process object if server starts successfully, None otherwise
"""

dm = DirectoryManager()
cm = ConversationManager(directory_manager_instance=dm)

console.print(
Panel(
Text(
Expand Down Expand Up @@ -113,6 +112,8 @@ def embed():
Looks for embeddable files in the current working directory and creates vector embeddings of the same.
"""

dm = DirectoryManager()

console.print(
Panel(
Text(
Expand Down Expand Up @@ -192,6 +193,9 @@ def read(
Reads and starts a chat using the given document from the current working directory.
"""

dm = DirectoryManager()
cm = ConversationManager(directory_manager_instance=dm)

if not OllamaManager.is_server_running():
console.print(f"[red]Error: Ollama server is not running![/red]")
console.print(
Expand All @@ -211,6 +215,9 @@ def chat():
Starts a chat with the embedded documents.
"""

dm = DirectoryManager()
cm = ConversationManager(directory_manager_instance=dm)

if not OllamaManager.is_server_running():
console.print(f"[red]Error: Ollama server is not running![/red]")
console.print(
Expand Down

0 comments on commit 1421ffc

Please sign in to comment.