Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
samholt committed Apr 16, 2024
1 parent ed25d03 commit 52f7bf2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
23 changes: 23 additions & 0 deletions l2mac/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ def load_config() -> L2MACConfig:
print("Invalid configuration:", e)
raise e

DEFAULT_CONFIG = """# Full Example: https://github.com/geekan/MetaGPT/blob/main/config/config2.example.yaml
# Reflected Code: https://github.com/geekan/MetaGPT/blob/main/metagpt/config2.py
llm:
api_type: "openai" # or azure etc. Check LLMType for more options
model: "gpt-4-1106-preview" # or gpt-3.5-turbo-1106 / gpt-4-1106-preview
base_url: "https://api.openai.com/v1" # or forward url / other llm url
api_key: "YOUR_API_KEY"
"""


def copy_config_to_home(home_config=Path.home() / '.l2mac' / 'config.yaml'):
"""Initialize the configuration file for L2MAC."""

home_config.parent.mkdir(parents=True, exist_ok=True)

if home_config.exists():
backup_path = home_config.with_suffix(".bak")
home_config.rename(backup_path)
print(f"Existing configuration file backed up at {backup_path}")

home_config.write_text(DEFAULT_CONFIG, encoding="utf-8")
print(f"Configuration file initialized at {home_config}")

if __name__ == "__main__":
try:
config = load_config()
Expand Down
37 changes: 22 additions & 15 deletions l2mac/main.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
from typing import Optional
from typing_extensions import Annotated
import typer
from enum import Enum
from config_loader import copy_config_to_home, load_config

class Domain(str, Enum):
codebase = "codebase"
book = "book"

class DebuggingLevel(str, Enum):
debug = "debug"
info = "info"
warn = "warn"
error = "error"

app = typer.Typer(help="Generate based on the prompt with LLM-automatic Computer")

@app.command()
def run_l2mac(prompt_task: Annotated[str, typer.Argument(help="Your input prompt to generate for such as 'Create a playable snake game in PyGame'")],
domain: Annotated[str, typer.Option(help="Domain to generate, existing options are 'codebase', 'book'.")] = "codebase",
domain: Annotated[Domain, typer.Option(help="Domain to generate, existing options are 'codebase', 'book'.")] = Domain.codebase,
run_tests: Annotated[bool, typer.Option(help="Whether to run self-generated unit-tests when generating code.")] = False,
project_name: Annotated[Optional[str], typer.Option(help="Unique project name, such as 'snakegame'.")] = None,
steps: Annotated[int, typer.Option(help="Number of internal steps to use when creating the prompt program internally.")] = 10,
prompt_program: Annotated[Optional[str], typer.Option(help="Path to the prompt program to use, or the prompt program as a string in a list format.")] = None,
prompts_file_path: Annotated[Optional[str], typer.Option(help="Overrides the existing prompts to be used. Useful when creating a new prompt set for a new task.")] = None,
tools_enabled: Annotated[Optional[str], typer.Option(help="List of functions that the agents can use.")] = None,
debugging_level: Annotated[str, typer.Option(help="Whether to print full context-windows out.")] = "Medium",
debugging_level: Annotated[DebuggingLevel, typer.Option(help="Whether to print full context-windows out.")] = DebuggingLevel.info,
init_config: Annotated[bool, typer.Option(help="Initialize the configuration file for L2MAC.")] = False):
"""
Generate based on the prompt with LLM-automatic Computer
"""
# Implementation of functionality goes here.
# For now, just printing received options for demonstration.
print(f"Prompt Task: {prompt_task}")
print(f"Domain: {domain}")
print(f"Run Tests: {run_tests}")
print(f"Project Name: {project_name}")
print(f"Steps: {steps}")
print(f"Prompt Program: {prompt_program}")
print(f"Prompts File Path: {prompts_file_path}")
print(f"Tools Enabled: {tools_enabled}")
print(f"Debugging Level: {debugging_level}")
print(f"Init Config: {init_config}")
return None
if init_config:
print("Initializing configuration file...")
copy_config_to_home()
return None
config = load_config()





if __name__ == '__main__':
Expand Down

0 comments on commit 52f7bf2

Please sign in to comment.