Skip to content

Commit 6310c7c

Browse files
authored
Merge pull request #33 from filipw/instructions
do not use default system prompt
2 parents b05817a + cabb3b8 commit 6310c7c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

samples/ios/phi.engine.sample/phi.engine.sample/AiViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Phi3ViewModel: ObservableObject {
2020
init() {
2121
let inferenceOptionsBuilder = InferenceOptionsBuilder()
2222
try! inferenceOptionsBuilder.withTemperature(temperature: 0.9)
23-
try! inferenceOptionsBuilder.withSeed(seed: 146628346)
23+
try! inferenceOptionsBuilder.withSeed(seed: 146628345)
2424
self.inferenceOptions = try! inferenceOptionsBuilder.build()
2525
}
2626

@@ -34,7 +34,7 @@ class Phi3ViewModel: ObservableObject {
3434
try! engineBuilder.withModelProvider(modelProvider: modelProvider)
3535
try! engineBuilder.withEventHandler(eventHandler: BoxedPhiEventHandler(handler: ModelEventsHandler(parent: self)))
3636

37-
self.engine = try! engineBuilder.buildStateful(cacheDir: FileManager.default.temporaryDirectory.path(), systemInstruction: "You are a sports store agent. you speak only about sports equipment. Be brief, direct and polite.")
37+
self.engine = try! engineBuilder.buildStateful(cacheDir: FileManager.default.temporaryDirectory.path(), systemInstruction: "You are a hockey wise old man. Share your wisdom briefly like an oracle. Be brief and to the point.")
3838
DispatchQueue.main.async {
3939
self.isLoadingEngine = false
4040
self.isReady = true

strathweb-phi-engine/src/engine.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,14 @@ impl PhiEngine {
634634
})
635635
.collect::<String>();
636636

637-
let system_instruction = conversation_context.system_instruction.clone().unwrap_or("You are a helpful assistant that answers user questions. Be short and direct in your answers.".to_string());
638-
639-
let prompt_with_history = format!("<|system|>\n{}<|end|>\n<|assistant|>Understood, I will adhere to these instructions<|end|>{}\n<|assistant|>\n", system_instruction, history_prompt);
637+
let prompt_with_history = {
638+
// if system instruction is there, use it, otherwise construct prompt without system instruction
639+
if let Some(system_instruction) = conversation_context.system_instruction.clone() {
640+
format!("<|system|>{}<|end|>{}\n<|assistant|>\n", system_instruction, history_prompt)
641+
} else {
642+
format!("{}\n<|assistant|>\n", history_prompt)
643+
}
644+
};
640645

641646
let mut pipeline = TextGenerator::new(
642647
&self.model,

0 commit comments

Comments
 (0)