Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- examples/debate/__init__.py +2 -0
- examples/debate/run.py +52 -0
examples/debate/__init__.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# coding: utf-8
|
2 |
+
# Copyright (c) 2025 inclusionAI.
|
examples/debate/run.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
import os
|
3 |
+
import uuid
|
4 |
+
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
|
7 |
+
from aworld import trace
|
8 |
+
from examples.debate.agent.debate_agent import DebateAgent
|
9 |
+
from examples.debate.agent.main import DebateArena
|
10 |
+
from examples.debate.agent.moderator_agent import ModeratorAgent
|
11 |
+
from examples.debate.agent.prompts import generate_opinions_prompt
|
12 |
+
from aworld.config import AgentConfig
|
13 |
+
from aworld.output import WorkSpace
|
14 |
+
|
15 |
+
if __name__ == '__main__':
|
16 |
+
load_dotenv()
|
17 |
+
trace.configure()
|
18 |
+
|
19 |
+
base_config = {
|
20 |
+
"llm_provider": "openai",
|
21 |
+
"llm_model_name": os.environ['LLM_MODEL_NAME'],
|
22 |
+
"llm_base_url": os.environ['LLM_BASE_URL'],
|
23 |
+
"llm_api_key": os.environ['LLM_API_KEY'],
|
24 |
+
}
|
25 |
+
|
26 |
+
agentConfig = AgentConfig.model_validate(base_config)
|
27 |
+
|
28 |
+
agent1 = DebateAgent(name="affirmativeSpeaker", stance="affirmative", conf=AgentConfig.model_validate(base_config))
|
29 |
+
agent2 = DebateAgent(name="negativeSpeaker", stance="negative", conf=AgentConfig.model_validate(base_config))
|
30 |
+
|
31 |
+
moderator_agent = ModeratorAgent(
|
32 |
+
conf=AgentConfig.model_validate(base_config | {
|
33 |
+
"name": "moderator_agent",
|
34 |
+
"agent_prompt": generate_opinions_prompt
|
35 |
+
})
|
36 |
+
)
|
37 |
+
|
38 |
+
debate_arena = DebateArena(affirmative_speaker=agent1, negative_speaker=agent2, moderator=moderator_agent,
|
39 |
+
workspace=WorkSpace.from_local_storages(str(uuid.uuid4())))
|
40 |
+
|
41 |
+
|
42 |
+
async def start_debate(debate_arena, topic, rounds):
|
43 |
+
speeches = debate_arena.async_run(topic=topic, rounds=rounds)
|
44 |
+
async for speech in speeches:
|
45 |
+
if speech.parts:
|
46 |
+
async for part in speech.parts:
|
47 |
+
print(part.content, flush=True, end="")
|
48 |
+
|
49 |
+
print(f"{speech.name}: {speech.content}")
|
50 |
+
|
51 |
+
|
52 |
+
asyncio.run(start_debate(debate_arena, topic="张居正", rounds=3))
|