Skip to content

Bug fix: Create command response access #191

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

Merged
merged 1 commit into from
Jan 29, 2025
Merged
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
17 changes: 9 additions & 8 deletions src/codegen/cli/commands/create/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,24 @@ def create_command(session: CodegenSession, name: str, path: Path, description:
return

rich.print("") # Add a newline before output

response = None
try:
if description:
# Use API to generate implementation
with create_spinner("Generating function (using LLM, this will take ~10s)") as status:
response = RestAPI(session.token).create(name=name, query=description)
code = convert_to_cli(response.code, session.language, name)
prompt_path.write_text(response.context)
else:
# Use default implementation
code = DEFAULT_CODEMOD.format(name=name)

# Create the target directory if needed
codemod_path.parent.mkdir(parents=True, exist_ok=True)
# Create the target directory if needed
codemod_path.parent.mkdir(parents=True, exist_ok=True)

# Write the function code
codemod_path.write_text(code)
prompt_path.write_text(response.context)
# Write the function code
codemod_path.write_text(code)


except (ServerError, ValueError) as e:
raise click.ClickException(str(e))
Expand All @@ -112,8 +113,8 @@ def create_command(session: CodegenSession, name: str, path: Path, description:
rich.print("")
rich.print("📁 Files Created:")
rich.print(f" [dim]Function:[/dim] {make_relative(codemod_path)}")
if description and response.context:
rich.print(f" [dim]Prompt:[/dim] {make_relative(prompt_path)}")
if description and response and response.context:
rich.print(f" [dim]Prompt:[/dim] {description}")

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