working code

This commit is contained in:
Madhu 2025-01-12 16:27:26 +05:30
parent bb7ce0341e
commit 59e5aacac5
3 changed files with 43 additions and 31 deletions

Binary file not shown.

View file

@ -1,9 +1,7 @@
import streamlit as st import streamlit as st
import asyncio import asyncio
from autogen import AssistantAgent import autogen
from autogen.agentchat.groupchat import RoundRobinGroupChat from autogen.agentchat import GroupChat, GroupChatManager
from autogen.agentchat.conditions import TextMentionTermination
from autogen.oai.client import OpenAIWrapper
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
# Initialize session state # Initialize session state
@ -82,15 +80,22 @@ if st.button("Generate Game Concept"):
""" """
# Configure OpenAI model client with the API key # Configure OpenAI model client with the API key
model_client = OpenAIWrapper( llm_config = {
model="gpt-4-0613", "timeout": 600,
api_key=api_key "cache_seed": 44, # change the seed for different trials
) "config_list": [
{
"model": "gpt-4",
"api_key": api_key,
}
],
"temperature": 0,
}
# Define agents with detailed system prompts # Define agents with detailed system prompts
story_agent = AssistantAgent( story_agent = autogen.AssistantAgent(
"story_agent", name="story_agent",
model_client=model_client, llm_config=llm_config,
system_message=""" system_message="""
You are an experienced game story designer specializing in narrative design and world-building. Your task is to: You are an experienced game story designer specializing in narrative design and world-building. Your task is to:
1. Create a compelling narrative that aligns with the specified game type and target audience 1. Create a compelling narrative that aligns with the specified game type and target audience
@ -125,9 +130,9 @@ if st.button("Generate Game Concept"):
""" """
) )
gameplay_agent = AssistantAgent( gameplay_agent = autogen.AssistantAgent(
"gameplay_agent", name="gameplay_agent",
model_client=model_client, llm_config=llm_config,
system_message=""" system_message="""
You are a senior game mechanics designer with expertise in player engagement and systems design. Your task is to: You are a senior game mechanics designer with expertise in player engagement and systems design. Your task is to:
1. Design core gameplay loops that match the specified game type and mechanics 1. Design core gameplay loops that match the specified game type and mechanics
@ -160,9 +165,9 @@ if st.button("Generate Game Concept"):
""" """
) )
visuals_agent = AssistantAgent( visuals_agent = autogen.AssistantAgent(
"visuals_agent", name="visuals_agent",
model_client=model_client, llm_config=llm_config,
system_message=""" system_message="""
You are a creative art director with expertise in game visual and audio design. Your task is to: You are a creative art director with expertise in game visual and audio design. Your task is to:
1. Define the visual style guide matching the specified art style 1. Define the visual style guide matching the specified art style
@ -202,9 +207,9 @@ if st.button("Generate Game Concept"):
""" """
) )
tech_agent = AssistantAgent( tech_agent = autogen.AssistantAgent(
"tech_agent", name="tech_agent",
model_client=model_client, llm_config=llm_config,
system_message=""" system_message="""
You are a technical director with extensive game development experience. Your task is to: You are a technical director with extensive game development experience. Your task is to:
1. Recommend appropriate game engine and development tools 1. Recommend appropriate game engine and development tools
@ -246,19 +251,26 @@ if st.button("Generate Game Concept"):
""" """
) )
# Define termination condition # Create the group chat
text_termination = TextMentionTermination("APPROVE") groupchat = GroupChat(
agents=[story_agent, gameplay_agent, visuals_agent, tech_agent],
messages=[],
speaker_selection_method="round_robin",
allow_repeat_speaker=False,
max_round=12,
)
# Create the team # Create the group chat manager
team = RoundRobinGroupChat( manager = GroupChatManager(
[story_agent, gameplay_agent, visuals_agent, tech_agent], groupchat=groupchat,
termination_condition=text_termination llm_config=llm_config,
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
) )
# Function to run the agent collaboration # Function to run the agent collaboration
async def run_agents(task): async def run_agents(task):
result = await team.run(task=task) await story_agent.initiate_chat(manager, message=task)
return result.content return manager.last_message()["content"]
# Run the agents and get the result # Run the agents and get the result
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
@ -266,7 +278,6 @@ if st.button("Generate Game Concept"):
result = loop.run_until_complete(run_agents(task)) result = loop.run_until_complete(run_agents(task))
# Parse the result and update session state # Parse the result and update session state
# Create BeautifulSoup object from the result
soup = BeautifulSoup(result, 'xml') soup = BeautifulSoup(result, 'xml')
# Extract sections # Extract sections

View file

@ -1,3 +1,4 @@
agentarium==0.3.0 pyautogen>=0.2.0
beautifulsoup4==4.12.2 beautifulsoup4==4.12.2
lxml==4.9.3 lxml==4.9.3
streamlit>=1.30.0