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

fix: Workaround for relace not adding newlines #907

Merged
merged 3 commits into from
Mar 19, 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
12 changes: 7 additions & 5 deletions src/codegen/extensions/tools/relace_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import difflib
import os
from typing import TYPE_CHECKING, ClassVar, Optional
from typing import TYPE_CHECKING, ClassVar

import requests
from langchain_core.messages import ToolMessage
Expand All @@ -23,15 +23,15 @@ class RelaceEditObservation(Observation):
filepath: str = Field(
description="Path to the edited file",
)
diff: Optional[str] = Field(
diff: str | None = Field(
default=None,
description="Unified diff showing the changes made",
)
new_content: Optional[str] = Field(
new_content: str | None = Field(
default=None,
description="New content with line numbers",
)
line_count: Optional[int] = Field(
line_count: int | None = Field(
default=None,
description="Total number of lines in file",
)
Expand Down Expand Up @@ -135,7 +135,7 @@ def apply_relace_edit(api_key: str, initial_code: str, edit_snippet: str, stream
raise Exception(msg)


def relace_edit(codebase: Codebase, filepath: str, edit_snippet: str, api_key: Optional[str] = None) -> RelaceEditObservation:
def relace_edit(codebase: Codebase, filepath: str, edit_snippet: str, api_key: str | None = None) -> RelaceEditObservation:
"""Edit a file using the Relace Instant Apply API.

Args:
Expand Down Expand Up @@ -176,6 +176,8 @@ def relace_edit(codebase: Codebase, filepath: str, edit_snippet: str, api_key: O
# Apply the edit using Relace API
try:
merged_code = apply_relace_edit(api_key, original_content, edit_snippet)
if original_content.endswith("\n") and not merged_code.endswith("\n"):
merged_code += "\n"
except Exception as e:
return RelaceEditObservation(
status="error",
Expand Down
Loading