Skip to content

Commit e091dc1

Browse files
committed
fix: apply system prompt
1 parent b4b37db commit e091dc1

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/ai/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,8 @@ pub struct ResponsesChatRequest<'a> {
931931
pub model: &'a str,
932932
#[serde(skip_serializing_if = "str::is_empty")]
933933
pub previous_response_id: &'a str,
934+
#[serde(skip_serializing_if = "str::is_empty")]
935+
pub instructions: &'a str,
934936
pub input: &'a str,
935937
#[serde(flatten)]
936938
pub extra: serde_json::Value,
@@ -1220,12 +1222,18 @@ impl ResponsesSession {
12201222

12211223
let req = ResponsesChatRequest {
12221224
model: &self.model,
1225+
instructions: &self.instructions,
12231226
previous_response_id: &self.previous_response_id,
12241227
input,
12251228
extra,
12261229
stream: true,
12271230
};
12281231

1232+
log::debug!(
1233+
"#### send to responses llm:\n{}\n#####",
1234+
serde_json::to_string_pretty(&req)?
1235+
);
1236+
12291237
let mut response_builder = reqwest::Client::new().post(&self.url);
12301238
if !self.api_key.is_empty() {
12311239
response_builder = response_builder.bearer_auth(&self.api_key);
@@ -1269,6 +1277,7 @@ impl ResponsesSession {
12691277

12701278
let req = ResponsesChatRequest {
12711279
model: &self.model,
1280+
instructions: &self.instructions,
12721281
previous_response_id: &self.previous_response_id,
12731282
input: "",
12741283
extra,

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ pub struct ResponsesConfig {
7272
pub mcp_server: Vec<MCPServerConfig>,
7373
#[serde(default)]
7474
pub extra: Option<serde_json::Value>,
75+
76+
#[serde(default)]
77+
pub sys_prompts: Vec<Content>,
7578
}
7679

7780
impl ResponsesConfig {

src/services/ws/stable/llm.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,21 @@ impl crate::config::ResponsesConfig {
318318
pub async fn instructions(&self) -> String {
319319
let r = regex!(r"\{\{(?P<url>\s*https?://\S+?\s*)\}\}");
320320

321+
let instructions;
322+
323+
if let Some(system) = self.sys_prompts.first() {
324+
if system.role == crate::ai::llm::Role::System {
325+
instructions = &system.message;
326+
} else {
327+
instructions = &self.instructions;
328+
}
329+
} else {
330+
instructions = &self.instructions;
331+
}
332+
321333
let mut urls = vec![];
322334
let mut contents = HashMap::new();
323-
for cap in r.captures_iter(&self.instructions) {
335+
for cap in r.captures_iter(&instructions) {
324336
if let Some(url) = cap.name("url") {
325337
let url = url.as_str().trim();
326338
urls.push(url.to_string());
@@ -338,7 +350,7 @@ impl crate::config::ResponsesConfig {
338350
}
339351
}
340352

341-
let new_instructions = r.replace_all(&self.instructions, |caps: &lazy_regex::Captures| {
353+
let new_instructions = r.replace_all(&instructions, |caps: &lazy_regex::Captures| {
342354
let url = caps.name("url").unwrap().as_str().trim();
343355
contents.get(url).cloned().unwrap_or(url.to_string())
344356
});

0 commit comments

Comments
 (0)