You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/new_features_examples/groupchat_examples/group_chat_example.py

70 lines
2.0 KiB

3 weeks ago
import os
from dotenv import load_dotenv
from swarm_models import OpenAIChat
3 weeks ago
from swarms import Agent, GroupChat
3 weeks ago
if __name__ == "__main__":
load_dotenv()
# Get the OpenAI API key from the environment variable
3 weeks ago
api_key = os.getenv("GROQ_API_KEY")
3 weeks ago
3 weeks ago
# Model
3 weeks ago
model = OpenAIChat(
3 weeks ago
openai_api_base="https://api.groq.com/openai/v1",
3 weeks ago
openai_api_key=api_key,
3 weeks ago
model_name="llama-3.1-70b-versatile",
3 weeks ago
temperature=0.1,
)
# Example agents
agent1 = Agent(
agent_name="Financial-Analysis-Agent",
3 weeks ago
system_prompt="You are a friendly financial analyst specializing in investment strategies. Be approachable and conversational.",
3 weeks ago
llm=model,
max_loops=1,
dynamic_temperature_enabled=True,
user_name="swarms_corp",
output_type="string",
3 weeks ago
streaming_on=True,
3 weeks ago
)
agent2 = Agent(
agent_name="Tax-Adviser-Agent",
3 weeks ago
system_prompt="You are a tax adviser who provides clear, concise, and approachable guidance on tax-related queries.",
3 weeks ago
llm=model,
max_loops=1,
dynamic_temperature_enabled=True,
user_name="swarms_corp",
output_type="string",
3 weeks ago
streaming_on=True,
3 weeks ago
)
3 weeks ago
# agent3 = Agent(
# agent_name="Stock-Buying-Agent",
# system_prompt="You are a stock market expert who provides insights on buying and selling stocks. Be informative and concise.",
# llm=model,
# max_loops=1,
# dynamic_temperature_enabled=True,
# user_name="swarms_corp",
# retry_attempts=1,
# context_length=200000,
# output_type="string",
# streaming_on=True,
# )
3 weeks ago
agents = [agent1, agent2]
chat = GroupChat(
name="Investment Advisory",
3 weeks ago
description="Financial, tax, and stock analysis group",
3 weeks ago
agents=agents,
)
history = chat.run(
3 weeks ago
"How to save on taxes for stocks, ETFs, and mutual funds?"
3 weeks ago
)
print(history.model_dump_json(indent=2))