fix: some nit Rust reference issues (#3849)
Fix some small references issue. No behavioural change. Just making the code cleaner
This commit is contained in:
@@ -34,13 +34,11 @@ pub struct Prompt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Prompt {
|
impl Prompt {
|
||||||
pub(crate) fn get_full_instructions(&self, model: &ModelFamily) -> Cow<'_, str> {
|
pub(crate) fn get_full_instructions<'a>(&'a self, model: &'a ModelFamily) -> Cow<'a, str> {
|
||||||
let base = self
|
let base = self
|
||||||
.base_instructions_override
|
.base_instructions_override
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.unwrap_or(model.base_instructions.deref());
|
.unwrap_or(model.base_instructions.deref());
|
||||||
let mut sections: Vec<&str> = vec![base];
|
|
||||||
|
|
||||||
// When there are no custom instructions, add apply_patch_tool_instructions if:
|
// When there are no custom instructions, add apply_patch_tool_instructions if:
|
||||||
// - the model needs special instructions (4.1)
|
// - the model needs special instructions (4.1)
|
||||||
// AND
|
// AND
|
||||||
@@ -54,9 +52,10 @@ impl Prompt {
|
|||||||
&& model.needs_special_apply_patch_instructions
|
&& model.needs_special_apply_patch_instructions
|
||||||
&& !is_apply_patch_tool_present
|
&& !is_apply_patch_tool_present
|
||||||
{
|
{
|
||||||
sections.push(APPLY_PATCH_TOOL_INSTRUCTIONS);
|
Cow::Owned(format!("{base}\n{APPLY_PATCH_TOOL_INSTRUCTIONS}"))
|
||||||
|
} else {
|
||||||
|
Cow::Borrowed(base)
|
||||||
}
|
}
|
||||||
Cow::Owned(sections.join("\n"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_formatted_input(&self) -> Vec<ResponseItem> {
|
pub(crate) fn get_formatted_input(&self) -> Vec<ResponseItem> {
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ pub(crate) struct ApplyPatchToolArgs {
|
|||||||
/// Responses API:
|
/// Responses API:
|
||||||
/// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
|
/// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
|
||||||
pub fn create_tools_json_for_responses_api(
|
pub fn create_tools_json_for_responses_api(
|
||||||
tools: &Vec<OpenAiTool>,
|
tools: &[OpenAiTool],
|
||||||
) -> crate::error::Result<Vec<serde_json::Value>> {
|
) -> crate::error::Result<Vec<serde_json::Value>> {
|
||||||
let mut tools_json = Vec::new();
|
let mut tools_json = Vec::new();
|
||||||
|
|
||||||
@@ -348,7 +348,7 @@ pub fn create_tools_json_for_responses_api(
|
|||||||
/// Chat Completions API:
|
/// Chat Completions API:
|
||||||
/// https://platform.openai.com/docs/guides/function-calling?api-mode=chat
|
/// https://platform.openai.com/docs/guides/function-calling?api-mode=chat
|
||||||
pub(crate) fn create_tools_json_for_chat_completions_api(
|
pub(crate) fn create_tools_json_for_chat_completions_api(
|
||||||
tools: &Vec<OpenAiTool>,
|
tools: &[OpenAiTool],
|
||||||
) -> crate::error::Result<Vec<serde_json::Value>> {
|
) -> crate::error::Result<Vec<serde_json::Value>> {
|
||||||
// We start with the JSON for the Responses API and than rewrite it to match
|
// We start with the JSON for the Responses API and than rewrite it to match
|
||||||
// the chat completions tool call format.
|
// the chat completions tool call format.
|
||||||
|
|||||||
@@ -32,15 +32,19 @@ pub enum Shell {
|
|||||||
impl Shell {
|
impl Shell {
|
||||||
pub fn format_default_shell_invocation(&self, command: Vec<String>) -> Option<Vec<String>> {
|
pub fn format_default_shell_invocation(&self, command: Vec<String>) -> Option<Vec<String>> {
|
||||||
match self {
|
match self {
|
||||||
Shell::Zsh(zsh) => {
|
Shell::Zsh(zsh) => format_shell_invocation_with_rc(
|
||||||
format_shell_invocation_with_rc(&command, &zsh.shell_path, &zsh.zshrc_path)
|
command.as_slice(),
|
||||||
}
|
&zsh.shell_path,
|
||||||
Shell::Bash(bash) => {
|
&zsh.zshrc_path,
|
||||||
format_shell_invocation_with_rc(&command, &bash.shell_path, &bash.bashrc_path)
|
),
|
||||||
}
|
Shell::Bash(bash) => format_shell_invocation_with_rc(
|
||||||
|
command.as_slice(),
|
||||||
|
&bash.shell_path,
|
||||||
|
&bash.bashrc_path,
|
||||||
|
),
|
||||||
Shell::PowerShell(ps) => {
|
Shell::PowerShell(ps) => {
|
||||||
// If model generated a bash command, prefer a detected bash fallback
|
// If model generated a bash command, prefer a detected bash fallback
|
||||||
if let Some(script) = strip_bash_lc(&command) {
|
if let Some(script) = strip_bash_lc(command.as_slice()) {
|
||||||
return match &ps.bash_exe_fallback {
|
return match &ps.bash_exe_fallback {
|
||||||
Some(bash) => Some(vec![
|
Some(bash) => Some(vec![
|
||||||
bash.to_string_lossy().to_string(),
|
bash.to_string_lossy().to_string(),
|
||||||
@@ -102,7 +106,7 @@ impl Shell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn format_shell_invocation_with_rc(
|
fn format_shell_invocation_with_rc(
|
||||||
command: &Vec<String>,
|
command: &[String],
|
||||||
shell_path: &str,
|
shell_path: &str,
|
||||||
rc_path: &str,
|
rc_path: &str,
|
||||||
) -> Option<Vec<String>> {
|
) -> Option<Vec<String>> {
|
||||||
@@ -118,8 +122,8 @@ fn format_shell_invocation_with_rc(
|
|||||||
Some(vec![shell_path.to_string(), "-lc".to_string(), rc_command])
|
Some(vec![shell_path.to_string(), "-lc".to_string(), rc_command])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn strip_bash_lc(command: &Vec<String>) -> Option<String> {
|
fn strip_bash_lc(command: &[String]) -> Option<String> {
|
||||||
match command.as_slice() {
|
match command {
|
||||||
// exactly three items
|
// exactly three items
|
||||||
[first, second, third]
|
[first, second, third]
|
||||||
// first two must be "bash", "-lc"
|
// first two must be "bash", "-lc"
|
||||||
|
|||||||
Reference in New Issue
Block a user