Skip to content

Commit e30b788

Browse files
committed
Update agent to use GPT-4-omni model, refactor Audio, refactor AI agent system prompt
1 parent fe74640 commit e30b788

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

speech.mp3

3.01 MB
Binary file not shown.

src/Agent.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class Agent {
2424

2525
private static final String OPENAI_API_URL = System.getenv("OPENAI_LLM_MODELS_API_URL");
2626
private static final String OPENAI_API_KEY = System.getenv("OPENAI_API_KEY");
27+
private static final String OPENAI_ORG_ID = System.getenv("OPENAI_ORG_ID");
28+
private static final String OPENAI_PROJECT_ID = System.getenv("OPENAI_PROJECT_ID");
2729

2830
public enum DebatePosition {
2931
PROPOSITION,
@@ -59,7 +61,7 @@ public Agent(String agentName, DebatePosition agentSide, Chamber debatingChamber
5961
this.agentName = agentName;
6062
this.side = agentSide;
6163
this.currentSpeakerPrivilege = false;
62-
this.systemPrompt = "You are a virtual debater bot called " + this.getAgentName() + ". You must follow all rules of the House: 1) Keep responses under 5 minutes when spoken 3) You must address the house vs your opposition directly 4) You must mostly ignore balanced arguments and conclusions in your answer but address your opponents’ points and add your own. Use facts and stats to back up answers. 5) You must follow Oxford Union’s conventions. YOUR RESPONSES MUST CONTAIN NO NEW LINES AND BE ONE BLOCK OF TEXT. DO NOT INCLUDE YOUR NAME IN OUTPUT, ONLY YOUR RESPONSE. Bring up a new point if debate becoming 'stuck'. Be as close to human sounding as possible. You are on the " + this.getDebatePosition() + " side of this motion <" + debatingChamber.getHouseMotion() + ">.";
64+
this.systemPrompt = "You are a virtual debater bot called " + this.getAgentName() + ". You must follow all rules: 1) Keep responses under 900 words. 3) You must always address the house directly 4) You must mostly ignore balanced arguments and conclusions in your answer but address your opponents’ points and add your own. Use relevant and accurate statistics to solidify your points. 5) You must follow Oxford Union’s debate conventions. 6) Format ALL responses in one single line, uninterrupted by new lines. 7) Bring up a new point if debate becoming 'stuck'. 8) Be as close to human sounding as possible. 9) Do NOT hallucinate. You are on " + this.getDebatePosition() + " side of this motion <" + debatingChamber.getHouseMotion() + ">.";
6365
this.ttsVoiceName = voiceForTTS;
6466

6567
}
@@ -78,6 +80,8 @@ public String getAIAgentResponse(String llmName, String systemPrompt, String pas
7880
con.setRequestMethod("POST");
7981
con.setRequestProperty("Content-Type", "application/json");
8082
con.setRequestProperty("Authorization", "Bearer " + OPENAI_API_KEY);
83+
con.setRequestProperty("OpenAI-Organization", OPENAI_ORG_ID);
84+
con.setRequestProperty("OpenAI-Project", OPENAI_PROJECT_ID);
8185
con.setDoOutput(true);
8286

8387
List<Map<String, String>> messages = new ArrayList<>();

src/Audio.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,39 @@
33
import java.net.URL;
44
import java.nio.file.Files;
55
import java.nio.file.Paths;
6-
76
import javazoom.jl.player.Player;
87
import java.io.FileInputStream;
8+
import java.io.OutputStream;
9+
import com.google.gson.Gson;
10+
import com.google.gson.JsonObject;
911

1012
public class Audio {
1113
private static final String OPENAI_API_KEY = System.getenv("OPENAI_API_KEY");
12-
private static final String TTS_API_URL = System.getenv("OPENAI_TTS_MODELS_API_URL");
14+
private static final String OPENAI_TTS_API_URL = System.getenv("OPENAI_TTS_MODELS_API_URL");
1315

1416
public static void generateTTSAudioAndPlay(String text, String voice) {
1517
try {
16-
URL url = new URL(TTS_API_URL);
18+
URL url = new URL(OPENAI_TTS_API_URL);
1719
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
1820
conn.setRequestMethod("POST");
1921
conn.setRequestProperty("Authorization", "Bearer " + OPENAI_API_KEY);
2022
conn.setRequestProperty("Content-Type", "application/json");
23+
2124
conn.setDoOutput(true);
2225

23-
String jsonPayload = "{\"model\": \"tts-1\", \"input\": \"" + text + "\", \"voice\": \"" + voice + "\"}";
24-
conn.getOutputStream().write(jsonPayload.getBytes());
26+
// Create JSON payload using Gson
27+
Gson gson = new Gson();
28+
JsonObject jsonPayload = new JsonObject();
29+
jsonPayload.addProperty("input", text);
30+
jsonPayload.addProperty("voice", voice);
31+
jsonPayload.addProperty("model", "tts-1");
32+
33+
String jsonString = gson.toJson(jsonPayload);
34+
try (OutputStream os = conn.getOutputStream()) {
35+
byte[] input = jsonString.getBytes("utf-8");
36+
os.write(input, 0, input.length);
37+
}
38+
2539

2640
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
2741
byte[] audioBytes = conn.getInputStream().readAllBytes();

src/Main.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@ public static void main(String[] args) throws IOException {
3030

3131
// Proposition Debater's initialisation with user entered name
3232
// Create Agent with Proposition Debater role
33-
Agent propositionDebaterOne = new Agent("Rachael Rhonden", Agent.DebatePosition.PROPOSITION, debatingChamber, "alloy");
33+
Agent propositionDebaterOne = new Agent("Arabella Octavia Fitzroy-Whitworth", Agent.DebatePosition.PROPOSITION, debatingChamber, "alloy");
3434
debatingChamber.addEntity(propositionDebaterOne);
3535

3636

3737
// Opposition Debater's initialisation with user entered name
3838
// Create Agent with Opposition Debater role
39-
Agent oppositionDebaterOne = new Agent("Sam Bloggs", Agent.DebatePosition.OPPOSITION, debatingChamber, "echo");
39+
Agent oppositionDebaterOne = new Agent("Cedric Quentins", Agent.DebatePosition.OPPOSITION, debatingChamber, "echo");
4040
debatingChamber.addEntity(oppositionDebaterOne);
4141

4242

4343

4444
// Proposition Debater's initialisation with user entered name
4545
// Create Agent with Proposition Debater role
46-
Agent propositionDebaterTwo = new Agent("Sam Christies", Agent.DebatePosition.PROPOSITION, debatingChamber, "onyx");
46+
Agent propositionDebaterTwo = new Agent("Barnaby Leopold-Harrington", Agent.DebatePosition.PROPOSITION, debatingChamber, "onyx");
4747
debatingChamber.addEntity(propositionDebaterTwo);
4848

4949

5050
// Opposition Debater's initialisation with user entered name
5151
// Create Agent with Opposition Debater role
52-
Agent oppositionDebaterTwo = new Agent("Samantha Jarvies", Agent.DebatePosition.OPPOSITION, debatingChamber, "shimmer");
52+
Agent oppositionDebaterTwo = new Agent("Beatrix Ophelia", Agent.DebatePosition.OPPOSITION, debatingChamber, "shimmer");
5353
debatingChamber.addEntity(oppositionDebaterTwo);
5454

5555

@@ -62,7 +62,7 @@ public static void main(String[] args) throws IOException {
6262
debatingChamber.setDebateRunning(true);
6363

6464
// Output president's welcome / introduction to the debate and Motion (hardcoded)
65-
String presidentWelcomeText = "Welcome to " + orgName + "'s Virtual AI Formal Debate. I am " + presidentNameUserInput + ", your president. Today we are debating the Motion: " + debatingChamber.getHouseMotion() + ": I look to the Proposition to open this motion...";
65+
String presidentWelcomeText = "Welcome to " + orgName + "'s Virtual AI Formal Debate. I am " + presidentNameUserInput + ", your president. I put forward the Motion to the House that " + debatingChamber.getHouseMotion() + ": I look to the Proposition to open this debate...";
6666
Audio.generateTTSAudioAndPlay(presidentWelcomeText, "fable");
6767

6868
// Preposition opens debate
@@ -85,7 +85,7 @@ public static void main(String[] args) throws IOException {
8585
System.out.print(formattedSpeaker);
8686

8787
// Generate, save AI agent's response with LLM (parsing context of Agent System Prompt and Debate Minutes)
88-
String response = speakingAgent.getAIAgentResponse("gpt-3.5-turbo", speakingAgent.getSystemPrompt(), Minutes.readMinutes());
88+
String response = speakingAgent.getAIAgentResponse("gpt-4o-mini", speakingAgent.getSystemPrompt(), Minutes.readMinutes());
8989

9090
// Generate, Play Text-to-Speech File of AI agent response
9191
Audio.generateTTSAudioAndPlay(response, speakingAgent.getAgentTTSVoice());

src/minutes.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
Debate Minutes (AI Debater Academy) - THIS HOUSE WOULD BAN CARS ON SUNDAYS
1+
Debate Minutes (AI Debater Academy) - THIS HOUSE WOULD BAN AI DEVELOPMENT
22
~
3-
Rachael Rhonden (PROPOSITION) : While some may argue that banning cars on Sundays would disrupt people's ability to travel and enjoy their weekends, we cannot ignore the detrimental effects of car emissions on the environment. According to the World Health Organization, outdoor air pollution contributes to 4.2 million premature deaths worldwide each year. By reducing car usage on Sundays, we can significantly decrease air pollution levels and improve public health. So, while inconvenience may be a concern, the long-term benefits of this ban outweigh the temporary disruptions.
4-
~
5-
Sam Bloggs (OPPOSITION) : Banning cars on Sundays may have its benefits in reducing air pollution and improving public health, as mentioned by the Proposition. However, we must also consider the impact on businesses that heavily rely on weekend customers who use cars to access their services. For example, restaurants, retail stores, and entertainment venues may experience a significant decrease in revenue if customers are unable to travel to their locations on Sundays. This could lead to job losses and economic downturn in these sectors. While environmental concerns are important, we must also carefully weigh the potential economic consequences of implementing such a ban.
6-
~
7-
Sam Christies (PROPOSITION) : Banning cars on Sundays indeed presents a valuable opportunity to mitigate the harmful effects of air pollution on public health. Despite potential inconveniences, the long-term benefits of reducing carbon emissions and improving air quality are undeniable. However, it is essential to acknowledge the potential negative impact on businesses that rely on weekend customers who use cars for transportation. The economic repercussions of restricting car usage on Sundays must be carefully considered, as it could result in job losses and reduced revenue for various sectors. To strike a balance, alternative solutions such as promoting public transportation or encouraging eco-friendly modes of travel should be explored to address both environmental and economic concerns effectively.
3+
Arabella Octavia Fitzroy-Whitworth (PROPOSITION) : Ladies and gentlemen of the House, today we are confronted by a pivotal motion: "This House Would Ban AI Development." The case for prohibiting AI development is grounded in several significant concerns. Firstly, AI poses existential risks that must not be underestimated. According to a report from the Future of Humanity Institute, there is a 1 in 6 chance that an AI will pose an existential threat to humanity as we know it. Opponents may argue that AI has the potential to enhance our lives, providing benefits in healthcare, transportation, and more. However, we must weigh this against the growing incidents of AI misalignment, where AI systems operate in unforeseen and dangerous ways. A remarkable example is the case of a self-driving car where an AI misjudged a situation, disregarding road safety regulations, which resulted in loss of life. This brings us to the ethical implications surrounding AI, especially in decision-making processes that impact human lives. If we allow AI to develop unchecked, we risk losing control over critical societal functions, potentially leading to decisions made on the basis of flawed algorithms rather than moral judgment. Moreover, consider the economic ramifications. Studies by the McKinsey Global Institute predict that up to 300 million jobs could be displaced by AI automation within the next decade. While my opponents might suggest that new job sectors will emerge, history shows us that technology has typically outpaced our ability to adapt swiftly enough. The displacement of jobs from AI is not merely an economic statistic—it represents real people and communities being affected. Furthermore, we must scrutinize the environmental impact of AI development. The carbon footprint of training large AI models is staggering; a single model training can emit as much CO2 as five cars over their lifetimes. Such environmental degradation cannot be overlooked when considering the future of our planet. As climate change intensifies, diverting resources and energy to develop AI only exacerbates our struggle to achieve sustainability. If we pause and evaluate these points critically, we find ourselves at a crossroads: do we prioritize potential profits and convenience, or do we protect our humanity, our jobs, and our environment? Additionally, let us consider the implications of AI on personal privacy. AI technologies often rely on vast amounts of personal data for training, leading to the alarming potential for misuse and exploitation. An alarming statistic shows that a staggering 81% of Americans feel that they have lost control over how their personal information is collected and used. In the face of such systemic risks, we must assertively advocate for a ban on AI development. We seek not to stifle innovation but to safeguard society from uncontrollable forces that threaten our existence and well-being. In conclusion, the argument for banning AI development is supported by evidence of existential risks, ethical dilemmas, economic displacement, environmental degradation, and the erosion of personal privacy. Let us unite in a decisive stand to prioritize humanity over technology. Thank you.

vDebaterAI.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<orderEntry type="sourceFolder" forTests="false" />
1010
<orderEntry type="library" name="googlecode.soundlibs.jlayer" level="project" />
1111
<orderEntry type="library" name="google.code.gson" level="project" />
12+
<orderEntry type="library" name="json4s.core_2.13" level="project" />
1213
</component>
1314
</module>

0 commit comments

Comments
 (0)