Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export GOOSE_EDITOR_MODEL="claude-3-5-sonnet-20241022"
```bash
export GOOSE_EDITOR_API_KEY="sk-..."
export GOOSE_EDITOR_HOST="https://api.morphllm.com/v1"
export GOOSE_EDITOR_MODEL="morph-v0"
export GOOSE_EDITOR_MODEL="morph-v3-large"
```

**Relace**
Expand Down
18 changes: 15 additions & 3 deletions crates/goose-mcp/src/developer/editor_models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ impl EditorModel {
original_code: &str,
old_str: &str,
update_snippet: &str,
instruction: &str,
) -> Result<String, String> {
match self {
EditorModel::MorphLLM(editor) => {
// Only MorphLLM uses the instruction parameter
editor
.edit_code(original_code, old_str, update_snippet)
.edit_code(original_code, old_str, update_snippet, instruction)
.await
}
EditorModel::OpenAICompatible(editor) => {
editor
.edit_code(original_code, old_str, update_snippet)
.edit_code(original_code, old_str, update_snippet, instruction)
.await
}
EditorModel::Relace(editor) => {
editor
.edit_code(original_code, old_str, update_snippet)
.edit_code(original_code, old_str, update_snippet, instruction)
.await
}
}
Expand All @@ -51,6 +53,15 @@ impl EditorModel {
EditorModel::Relace(editor) => editor.get_str_replace_description(),
}
}

/// Check if this editor supports/requires the instruction parameter
pub fn supports_instruction_parameter(&self) -> bool {
match self {
EditorModel::MorphLLM(_) => true,
EditorModel::OpenAICompatible(_) => false,
EditorModel::Relace(_) => false,
}
}
}

/// Trait for individual editor implementations
Expand All @@ -61,6 +72,7 @@ pub trait EditorModelImpl {
original_code: &str,
old_str: &str,
update_snippet: &str,
instruction: &str,
) -> Result<String, String>;

/// Get the description for the str_replace command when this editor is active
Expand Down
15 changes: 12 additions & 3 deletions crates/goose-mcp/src/developer/editor_models/morphllm_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl EditorModelImpl for MorphLLMEditor {
original_code: &str,
_old_str: &str,
update_snippet: &str,
instruction: &str,
) -> Result<String, String> {
eprintln!("Calling MorphLLM Editor API");

Expand All @@ -42,10 +43,10 @@ impl EditorModelImpl for MorphLLMEditor {
// Create the client
let client = Client::new();

// Format the prompt as specified in the Python example
// Format the prompt according to MorphLLM's new format with instruction
let user_prompt = format!(
"<code>{}</code>\n<update>{}</update>",
original_code, update_snippet
"<instruction>{}</instruction>\n<code>{}</code>\n<update>{}</update>",
instruction, original_code, update_snippet
);

// Prepare the request body for OpenAI-compatible API
Expand Down Expand Up @@ -98,6 +99,7 @@ impl EditorModelImpl for MorphLLMEditor {

fn get_str_replace_description(&self) -> &'static str {
"Use the edit_file to propose an edit to an existing file.

This will be read by a less intelligent model, which will quickly apply the edit. You should make it clear what the edit is, while also minimizing the unchanged code you write.
When writing the edit, you should specify each edit in sequence, with the special comment // ... existing code ... to represent unchanged code in between edited lines.

Expand All @@ -114,6 +116,13 @@ impl EditorModelImpl for MorphLLMEditor {
Each edit should contain sufficient context of unchanged lines around the code you're editing to resolve ambiguity.
If you plan on deleting a section, you must provide surrounding context to indicate the deletion.
DO NOT omit spans of pre-existing code without using the // ... existing code ... comment to indicate its absence.

**IMPORTANT**: You must also provide an `instruction` parameter - a single sentence written in the first person describing what you are going to do for the sketched edit. This instruction helps the less intelligent model understand and apply your edit correctly.

Examples of good instructions:
- \"I am adding error handling to the user authentication function and removing the old authentication method\"

The instruction should be specific enough to disambiguate any uncertainty in your edit.
"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl EditorModelImpl for OpenAICompatibleEditor {
original_code: &str,
_old_str: &str,
update_snippet: &str,
_instruction: &str, // Not used by OpenAI compatible editor
) -> Result<String, String> {
eprintln!("Calling OpenAI-compatible Editor API");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl EditorModelImpl for RelaceEditor {
original_code: &str,
_old_str: &str,
update_snippet: &str,
_instruction: &str, // Not used by Relace editor
) -> Result<String, String> {
eprintln!("Calling Relace Editor API");

Expand Down
Loading
Loading