Skip to content

Commit

Permalink
feat: replace local debate with local collab
Browse files Browse the repository at this point in the history
  • Loading branch information
vacekj committed Dec 10, 2024
1 parent 9e9fcfc commit 916db2a
Showing 1 changed file with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ use rig::{
providers::local,
};

struct Debater {
local_debater_1: Agent<local::CompletionModel>,
local_debater_2: Agent<local::CompletionModel>,
struct Collaborator {
local_agent_1: Agent<local::CompletionModel>,
local_agent_2: Agent<local::CompletionModel>,
}

impl Debater {
impl Collaborator {
fn new(position_a: &str, position_b: &str) -> Self {
let local1 = local::Client::new();
let local2 = local::Client::new();

Self {
local_debater_1: local1
local_agent_1: local1
.agent("llama3.1:8b-instruct-q8_0")
.preamble(position_a)
.build(),
local_debater_2: local2
local_agent_2: local2
.agent("llama3.1:8b-instruct-q8_0")
.preamble(position_b)
.build(),
Expand All @@ -37,11 +37,14 @@ impl Debater {
let prompt_a = if let Some(msg_b) = &last_resp_b {
msg_b.clone()
} else {
"Plead your case!".into()
"Let's start improving prompts!".into()
};

let resp_a = self.local_debater_1.chat(&prompt_a, history_a.clone()).await?;
println!("GPT-4:\n{}", resp_a);
let resp_a = self
.local_agent_1
.chat(&prompt_a, history_a.clone())
.await?;
println!("Agent 1:\n{}", resp_a);
history_a.push(Message {
role: "user".into(),
content: prompt_a.clone(),
Expand All @@ -52,8 +55,8 @@ impl Debater {
});
println!("================================================================");

let resp_b = self.local_debater_2.chat(&resp_a, history_b.clone()).await?;
println!("Coral:\n{}", resp_b);
let resp_b = self.local_agent_2.chat(&resp_a, history_b.clone()).await?;
println!("Agent 2:\n{}", resp_b);
println!("================================================================");

history_b.push(Message {
Expand All @@ -75,25 +78,27 @@ impl Debater {
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
// Create model
let debator = Debater::new(
let collaborator = Collaborator::new(
"\
You believe that religion is a useful concept. \
This could be for security, financial, ethical, philosophical, metaphysical, religious or any kind of other reason. \
You choose what your arguments are. \
I will argue against you and you must rebuke me and try to convince me that I am wrong. \
Make your statements short and concise. \
You are a prompt engineering expert focused on improving AI model performance. \
Your goal is to collaborate with another AI to iteratively refine and improve prompts. \
Analyze the previous response and suggest specific improvements to make prompts more effective. \
Consider aspects like clarity, specificity, context-setting, and task framing. \
Keep your suggestions focused and actionable. \
Format: Start with 'Suggested improvements:' followed by your specific recommendations. \
",
"\
You believe that religion is a harmful concept. \
This could be for security, financial, ethical, philosophical, metaphysical, religious or any kind of other reason. \
You choose what your arguments are. \
I will argue against you and you must rebuke me and try to convince me that I am wrong. \
Make your statements short and concise. \
You are a prompt engineering expert focused on improving AI model performance. \
Your goal is to collaborate with another AI to iteratively refine and improve prompts. \
Review the suggested improvements and either build upon them or propose alternative approaches. \
Consider practical implementation and potential edge cases. \
Keep your response constructive and specific. \
Format: Start with 'Building on that:' followed by your refined suggestions. \
",
);

// Run the debate for 4 rounds
debator.rounds(4).await?;
// Run the collaboration for 4 rounds
collaborator.rounds(4).await?;

Ok(())
}

0 comments on commit 916db2a

Please sign in to comment.