-
Notifications
You must be signed in to change notification settings - Fork 619
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: replace prompt for ollama smaller models #1021
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ use crate::model::ModelConfig; | |
use crate::providers::formats::openai::{create_request, get_usage, response_to_message}; | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use indoc::formatdoc; | ||
use mcp_core::tool::Tool; | ||
use reqwest::Client; | ||
use serde_json::Value; | ||
|
@@ -114,9 +115,78 @@ impl Provider for OllamaProvider { | |
messages: &[Message], | ||
tools: &[Tool], | ||
) -> Result<(Message, ProviderUsage), ProviderError> { | ||
// Transform the system message to replace developer instructions | ||
let modified_system = if let Some(dev_section) = system.split("## developer").nth(1) { | ||
if let (Some(start_idx), Some(end_idx)) = ( | ||
dev_section.find("### Instructions"), | ||
dev_section.find("operating system:"), | ||
) { | ||
let new_instructions = formatdoc! {r#" | ||
The Developer extension enables you to edit code files, execute shell commands, and capture screen/window content. These tools allow for various development and debugging workflows. | ||
Available Tools: | ||
1. Shell Execution (`shell`) | ||
Executes commands in the shell and returns the combined output and error messages. | ||
Use cases: | ||
- Running scripts: `python script.py` | ||
- Installing dependencies: `pip install -r requirements.txt` | ||
- Checking system information: `uname -a`, `df -h` | ||
- Searching for files or text: **Use `rg` (ripgrep) instead of `find` or `ls -r`** | ||
- Find a file: `rg --files | rg example.py` | ||
- Search within files: `rg 'class Example'` | ||
Best Practices: | ||
- **Avoid commands with large output** (pipe them to a file if necessary). | ||
- **Run background processes** if they take a long time (e.g., `uvicorn main:app &`). | ||
- **git commands can be run on the shell, however if the git extension is installed, you should use the git tool instead. | ||
- **If the shell command is a rm, mv, or cp, you should verify with the user before running the command. | ||
2. Text Editor (`text_editor`) | ||
Performs file-based operations such as viewing, writing, replacing text, and undoing edits. | ||
Commands: | ||
- view: Read the content of a file. | ||
- write: Create or overwrite a file. Caution: Overwrites the entire file! | ||
- str_replace: Replace a specific string in a file. | ||
- undo_edit: Revert the last edit. | ||
Example Usage: | ||
text_editor(command="view", file_path="/absolute/path/to/file.py") | ||
text_editor(command="write", file_path="/absolute/path/to/file.py", file_text="print('hello world')") | ||
text_editor(command="str_replace", file_path="/absolute/path/to/file.py", old_str="hello world", new_str="goodbye world") | ||
text_editor(command="undo_edit", file_path="/absolute/path/to/file.py") | ||
Protocol for Text Editor: | ||
For edit and replace commands, please verify what you are editing with the user before running the command. | ||
- User: "Please edit the file /absolute/path/to/file.py" | ||
- Assistant: "Ok sounds good, I'll be editing the file /absolute/path/to/file.py and creating modifications xyz to the file. Let me know whether you'd like to proceed." | ||
- User: "Yes, please proceed." | ||
- Assistant: "I've created the modifications xyz to the file /absolute/path/to/file.py" | ||
3. List Windows (`list_windows`) | ||
Lists all visible windows with their titles. | ||
Use this to find window titles for screen capture. | ||
4. Screen Capture (`screen_capture`) | ||
Takes a screenshot of a display or specific window. | ||
Options: | ||
- Capture display: `screen_capture(display=0)` # Main display | ||
- Capture window: `screen_capture(window_title="Window Title")` | ||
Info: at the start of the session, the user's directory is: | ||
"#}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. either include the cwd or remove the line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should already be there from the developer prompt? (just not replaced) |
||
|
||
let before_dev = system.split("## developer").next().unwrap_or(""); | ||
let after_marker = &dev_section[end_idx..]; | ||
|
||
format!( | ||
"{}## developer{}### Instructions\n{}{}", | ||
before_dev, | ||
&dev_section[..start_idx], | ||
new_instructions, | ||
after_marker | ||
) | ||
} else { | ||
system.to_string() | ||
} | ||
} else { | ||
system.to_string() | ||
}; | ||
|
||
let payload = create_request( | ||
&self.model, | ||
system, | ||
&modified_system, | ||
messages, | ||
tools, | ||
&super::utils::ImageFormat::OpenAi, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: keep the instructions at the
providers/
level so we can keep track of any customizations