Skip to content

Commit 61e14fb

Browse files
committed
feat: polish system prompt to support image input handling
1 parent fc02de6 commit 61e14fb

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/ops/functions/extract_by_llm.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ struct Executor {
2828
value_extractor: base::json_schema::ValueExtractor,
2929
}
3030

31-
fn get_system_prompt(instructions: &Option<String>, extra_instructions: Option<String>) -> String {
32-
let mut message =
33-
"You are a helpful assistant that extracts structured information from text. \
34-
Your task is to analyze the input text and output valid JSON that matches the specified schema. \
35-
Be precise and only include information that is explicitly stated in the text. \
36-
Output only the JSON without any additional messages or explanations."
37-
.to_string();
31+
fn get_system_prompt(
32+
instructions: &Option<String>,
33+
extra_instructions: Option<String>,
34+
is_image_input: bool,
35+
) -> String {
36+
let input_type = if is_image_input { "image" } else { "text" };
37+
let mut message = format!(
38+
"You are a helpful assistant that processes {} inputs to produce structured outputs. \
39+
Your task is to follow the provided instructions to generate or extract information and output valid JSON matching the specified schema. \
40+
For generative tasks, provide accurate and relevant responses based on the input. \
41+
Output only the JSON without additional messages or explanations, unless instructed otherwise.",
42+
input_type
43+
);
3844

3945
if let Some(custom_instructions) = instructions {
4046
message.push_str("\n\n");
@@ -54,12 +60,17 @@ impl Executor {
5460
let client =
5561
new_llm_generation_client(spec.llm_spec.api_type, spec.llm_spec.address).await?;
5662
let schema_output = build_json_schema(spec.output_type, client.json_schema_options())?;
63+
let is_image_input = args.image.is_some();
5764
Ok(Self {
5865
args,
5966
client,
6067
model: spec.llm_spec.model,
6168
output_json_schema: schema_output.schema,
62-
system_prompt: get_system_prompt(&spec.instruction, schema_output.extra_instructions),
69+
system_prompt: get_system_prompt(
70+
&spec.instruction,
71+
schema_output.extra_instructions,
72+
is_image_input,
73+
),
6374
value_extractor: schema_output.value_extractor,
6475
})
6576
}

0 commit comments

Comments
 (0)