Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create Command #254

Merged
merged 10 commits into from
Jan 17, 2025
4 changes: 2 additions & 2 deletions src/codegen/cli/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ def ask_expert(self, query: str) -> AskExpertResponse:
AskExpertResponse,
)

def create(self, query: str) -> CreateResponse:
def create(self, name: str, query: str) -> CreateResponse:
"""Get AI-generated starter code for a codemod."""
session = CodegenSession()
return self._make_request(
"GET",
CREATE_ENDPOINT,
CreateInput(input=CreateInput.BaseCreateInput(query=query, repo_full_name=session.repo_name)),
CreateInput(input=CreateInput.BaseCreateInput(name=name, query=query, repo_full_name=session.repo_name)),
CreateResponse,
)

Expand Down
1 change: 1 addition & 0 deletions src/codegen/cli/api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class DocsResponse(SafeBaseModel):

class CreateInput(SafeBaseModel):
class BaseCreateInput(SafeBaseModel):
name: str
query: str | None = None
repo_full_name: str | None = None

Expand Down
6 changes: 3 additions & 3 deletions src/codegen/cli/commands/create/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def create_command(session: CodegenSession, name: str, path: Path, description:
# Check if file exists
if target_path.exists() and not overwrite:
rel_path = make_relative(target_path)
pretty_print_error(f"File already exists at {format_path(rel_path)}\n\n" "To overwrite the file:\n" f"{format_command(f'codegen create {name} {rel_path} --overwrite')}")
pretty_print_error(f"File already exists at {format_path(rel_path)}\n\nTo overwrite the file:\n{format_command(f'codegen create {name} {rel_path} --overwrite')}")
return

if description:
Expand All @@ -91,7 +91,7 @@ def create_command(session: CodegenSession, name: str, path: Path, description:
with create_spinner(status_message) as status:
try:
# Get code from API
response = RestAPI(session.token).create(description if description else None)
response = RestAPI(session.token).create(name=name, query=description if description else None)

# Convert the code to include the decorator
code = convert_to_cli(response.code, session.config.programming_language or ProgrammingLanguage.PYTHON, name)
Expand Down Expand Up @@ -120,7 +120,7 @@ def create_command(session: CodegenSession, name: str, path: Path, description:
rich.print("📁 Files Created:")
rich.print(f" [dim]Function:[/dim] {make_relative(target_path)}")
if response.context:
rich.print(f" [dim]Prompt:[/dim] {make_relative(get_prompts_dir() / f'{name.lower().replace(' ', '-')}-system-prompt.md')}")
rich.print(f" [dim]Prompt:[/dim] {make_relative(get_prompts_dir() / f'{name.lower().replace(" ", "-")}-system-prompt.md')}")

# Next steps
rich.print("\n[bold]What's next?[/bold]\n")
Expand Down
Loading