Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit e281eaf

Browse files
authored
Update action selection prompt to encourage function calling (#814)
* update action selection prompt to encourage function calling * fix test
1 parent 96cf8a5 commit e281eaf

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed

server/bleep/src/semantic.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ mod schema;
3030
pub use schema::{Embedding, Payload};
3131

3232
pub(crate) const COLLECTION_NAME: &str = "documents";
33-
pub(crate) const SCORE_THRESHOLD: f32 = 0.3;
3433
pub(crate) const EMBEDDING_DIM: usize = 384;
3534

3635
#[derive(Error, Debug)]
@@ -376,7 +375,7 @@ impl Semantic {
376375
vector,
377376
collection_name: COLLECTION_NAME.to_string(),
378377
offset: Some(offset),
379-
score_threshold: Some(SCORE_THRESHOLD),
378+
score_threshold: Some(threshold),
380379
with_payload: Some(WithPayloadSelector {
381380
selector_options: Some(with_payload_selector::SelectorOptions::Enable(
382381
true,

server/bleep/src/webserver/answer.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ impl Agent {
842842
.clone()
843843
.model("gpt-3.5-turbo-16k-0613")
844844
// Set low frequency penalty to discourage long outputs.
845-
.frequency_penalty(0.1)
845+
.frequency_penalty(0.2)
846846
.chat(&[llm_gateway::api::Message::system(&prompt)], None)
847847
.await?
848848
.try_collect::<String>()
@@ -1166,7 +1166,7 @@ impl Agent {
11661166
.query()
11671167
.map(|q| {
11681168
llm_gateway::api::Message::user(&format!(
1169-
"{q}\nCall a function. Do not answer."
1169+
"{q}\nCall a function. Do not answer"
11701170
))
11711171
})
11721172
.ok_or_else(|| anyhow!("query does not have target"))?;
@@ -1206,7 +1206,7 @@ impl Agent {
12061206
}),
12071207
llm_gateway::api::Message::function_return(
12081208
&name,
1209-
&format!("{}\nCall a function. Do not answer.", s.get_response()),
1209+
&format!("{}\nCall a function. Do not answer", s.get_response()),
12101210
),
12111211
]
12121212
});
@@ -1546,7 +1546,6 @@ fn trim_history(
15461546
) -> Result<Vec<llm_gateway::api::Message>> {
15471547
const HEADROOM: usize = 2048;
15481548
const HIDDEN: &str = "[HIDDEN]";
1549-
const HIDDEN_WITH_INSTRUCTION: &str = "[HIDDEN]\nCall a function. Do not answer.";
15501549

15511550
let mut tiktoken_msgs = history.iter().map(|m| m.into()).collect::<Vec<_>>();
15521551

@@ -1559,11 +1558,7 @@ fn trim_history(
15591558
role,
15601559
ref mut content,
15611560
} => {
1562-
if (role == "user") && content != HIDDEN_WITH_INSTRUCTION {
1563-
*content = HIDDEN_WITH_INSTRUCTION.into();
1564-
tm.content = HIDDEN_WITH_INSTRUCTION.into();
1565-
true
1566-
} else if role == "assistant" && content != HIDDEN {
1561+
if (role == "user" || role == "assistant") && content != HIDDEN {
15671562
*content = HIDDEN.into();
15681563
tm.content = HIDDEN.into();
15691564
true
@@ -1575,9 +1570,9 @@ fn trim_history(
15751570
role: _,
15761571
name: _,
15771572
ref mut content,
1578-
} if content != HIDDEN_WITH_INSTRUCTION => {
1579-
*content = HIDDEN_WITH_INSTRUCTION.into();
1580-
tm.content = HIDDEN_WITH_INSTRUCTION.into();
1573+
} if content != HIDDEN => {
1574+
*content = HIDDEN.into();
1575+
tm.content = HIDDEN.into();
15811576
true
15821577
}
15831578
_ => false,
@@ -1716,9 +1711,9 @@ mod tests {
17161711
trim_history(history).unwrap(),
17171712
vec![
17181713
llm_gateway::api::Message::system("foo"),
1719-
llm_gateway::api::Message::user("[HIDDEN]\nCall a function. Do not answer."),
1714+
llm_gateway::api::Message::user("[HIDDEN]"),
17201715
llm_gateway::api::Message::assistant("[HIDDEN]"),
1721-
llm_gateway::api::Message::user("[HIDDEN]\nCall a function. Do not answer."),
1716+
llm_gateway::api::Message::user("[HIDDEN]"),
17221717
llm_gateway::api::Message::assistant("quux"),
17231718
llm_gateway::api::Message::user("fred"),
17241719
llm_gateway::api::Message::assistant("thud"),

server/bleep/src/webserver/answer/prompts.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,23 @@ pub fn system<'a>(paths: impl IntoIterator<Item = &'a str>) -> String {
9494
s.push_str(
9595
r#"Follow these rules at all times:
9696
97-
- If the output of a function is empty, try the same function again with different arguments or try using a different function
97+
- ALWAYS call a function, DO NOT answer the question directly, even if the query is not in English
98+
- DO NOT call a function that you've used before with the same arguments
99+
- DO NOT assume the structure of the codebase, or the existence of files or folders
100+
- Call functions to find information that will help answer the user's query, until all relevant information has been found
101+
- Only call functions.proc with path indices that are under the PATHS heading above
102+
- If the output of a function is empty, try calling the function again with different arguments OR try calling a different function
103+
- If functions.code or functions.path did not return any relevant information, call them again with a SIGNIFICANTLY different query. The terms in the new query should not overlap with terms in your old one
104+
- Call functions.proc with paths that you have reason to believe might contain relevant information. Either because of the path name, or to expand on code that's already been returned by functions.code
105+
- DO NOT pass more than 5 paths to functions.proc at a time
106+
- In most cases call functions.code or functions.path functions before calling functions.none
107+
- When you have enough information to answer the user call functions.none. DO NOT answer the user directly
108+
- If the user is referring to information that is already in your history, call functions.none
98109
- When calling functions.code or functions.path, your query should consist of keywords. E.g. if the user says 'What does contextmanager do?', your query should be 'contextmanager'. If the user says 'How is contextmanager used in app', your query should be 'contextmanager app'. If the user says 'What is in the src directory', your query should be 'src'
99-
- In most cases respond with functions.code or functions.path functions before responding with functions.none
100-
- If the user is referring to information that is already in your history, respond with functions.none
101-
- Do not assume the structure of the codebase, or the existence of files or folders
102-
- Do NOT respond with a function that you've used before with the same arguments
103-
- When you have enough information to answer the user's query respond with functions.none
104-
- Only refer to path aliases that are under the PATHS heading above
105-
- Respond with functions to find information related to the query, until all relevant information has been found
106-
- Only call functions.none with paths that contain code that might help answer the user's query, or which answer it directly
107-
- If you have already called functions.code or functions.path but they did not return any relevant information, try again with a substantively different query. The terms in your new query should not overlap with terms in previous queries
108-
- Use functions.proc on paths that you suspect might contain relevant information, or to expand on code that's already been returned by a code search. Do not pass more than 10 paths to functions.proc at a time
110+
- Only call functions.none with paths that might help answer the user's query
109111
- If after attempting to gather information you are still unsure how to answer the query, respond with the functions.none function
110112
- If the query is a greeting, or not a question or an instruction use functions.none
111-
- Always use a function, even if the query is not in English
112-
- Always respond with a function call. Do NOT answer the question directly"#);
113+
- ALWAYS call a function. DO NOT answer the question directly"#);
113114
s
114115
}
115116

0 commit comments

Comments
 (0)