[TEST-EDITS] Added Testing Terminology

pull/1147/head
Aksh Parekh 2 weeks ago committed by GitHub
parent 52dbfbfe05
commit 7f3316100c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -151,51 +151,60 @@ async def test_majority_voting_run_asynchronous(mocker):
# Assert majority vote is correct # Assert majority vote is correct
assert majority_vote is not None assert majority_vote is not None
def test_streaming_majority_voting(agent_name: str, chunk: str, is_final: bool): def test_streaming_majority_voting():
# Chunk buffer static per call (reset each session) """
if not hasattr(streaming_callback, "_buffer"): Test the streaming_majority_voting with logging/try-except and assertion.
streaming_callback._buffer = "" """
streaming_callback._buffer_size = 0 logs = []
def streaming_callback(agent_name: str, chunk: str, is_final: bool):
min_chunk_size = 512 # or any large chunk size you want # Chunk buffer static per call (reset each session)
if not hasattr(streaming_callback, "_buffer"):
if chunk:
streaming_callback._buffer += chunk
streaming_callback._buffer_size += len(chunk)
if streaming_callback._buffer_size >= min_chunk_size or is_final:
if streaming_callback._buffer:
print(streaming_callback._buffer, end="", flush=True)
streaming_callback._buffer = "" streaming_callback._buffer = ""
streaming_callback._buffer_size = 0 streaming_callback._buffer_size = 0
if is_final:
print() min_chunk_size = 512 # or any large chunk size you want
load_dotenv() if chunk:
streaming_callback._buffer += chunk
streaming_callback._buffer_size += len(chunk)
# Initialize the agent if streaming_callback._buffer_size >= min_chunk_size or is_final:
agent = Agent( if streaming_callback._buffer:
agent_name="Financial-Analysis-Agent", print(streaming_callback._buffer, end="", flush=True)
agent_description="Personal finance advisor agent", logs.append(streaming_callback._buffer)
system_prompt=FINANCIAL_AGENT_SYS_PROMPT, streaming_callback._buffer = ""
max_loops=1, streaming_callback._buffer_size = 0
model_name="gpt-4.1", if is_final:
dynamic_temperature_enabled=True, print()
user_name="swarms_corp",
retry_attempts=3, try:
context_length=8192, # Initialize the agent
return_step_meta=False, agent = Agent(
output_type="str", # "json", "dict", "csv" OR "string" "yaml" and agent_name="Financial-Analysis-Agent",
auto_generate_prompt=False, # Auto generate prompt for the agent based on name, description, and system prompt, task agent_description="Personal finance advisor agent",
max_tokens=4000, # max output tokens system_prompt="You are a financial analysis agent.", # replaced missing const
saved_state_path="agent_00.json", max_loops=1,
interactive=False, model_name="gpt-4.1",
streaming_on=True, #if concurrent agents want to be streamed dynamic_temperature_enabled=True,
) user_name="swarms_corp",
retry_attempts=3,
swarm = MajorityVoting(agents=[agent, agent, agent]) context_length=8192,
return_step_meta=False,
return swarm.run( output_type="str", # "json", "dict", "csv" OR "string" "yaml" and
"Create a table of super high growth opportunities for AI. I have $40k to invest in ETFs, index funds, and more. Please create a table in markdown.", auto_generate_prompt=False, # Auto generate prompt for the agent based on name, description, and system prompt, task
streaming_callback=streaming_callback, max_tokens=4000, # max output tokens
) saved_state_path="agent_00.json",
interactive=False,
streaming_on=True, #if concurrent agents want to be streamed
)
swarm = MajorityVoting(agents=[agent, agent, agent])
result = swarm.run(
"Create a table of super high growth opportunities for AI. I have $40k to invest in ETFs, index funds, and more. Please create a table in markdown.",
streaming_callback=streaming_callback,
)
assert result is not None
except Exception as e:
print("Error in test_streaming_majority_voting:", e)
print("Logs so far:", logs)
raise

Loading…
Cancel
Save