-
-
Notifications
You must be signed in to change notification settings - Fork 1k
[FEAT] [TEST] [DOCS] Streaming Callback for Majority Voting #1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6b80101
[FEAT] Majority Voting Streaming Feature
aparekh02 d54857e
Create test_majority_voting_streaming.py
aparekh02 d81f2ff
[TEST] Streaming Callback for Majority Voting with custom Streaming F…
aparekh02 090d731
[DOCS] Streaming for Majority Voting
aparekh02 de76a3a
Update test_majority_voting_streaming.py
aparekh02 946ae70
[TEST] Majority Voting with Streaming Feature
aparekh02 0dd6d25
[CLEANUP]
aparekh02 52dbfbf
[Add] Old Tests with New Tests
aparekh02 7f33161
[TEST-EDITS] Added Testing Terminology
aparekh02 e839dc5
Merge branch 'master' into mvstream
kyegomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| from swarms import Agent | ||
| from swarms.prompts.finance_agent_sys_prompt import ( | ||
| FINANCIAL_AGENT_SYS_PROMPT, | ||
| ) | ||
| from swarms.structs.majority_voting import MajorityVoting | ||
| from dotenv import load_dotenv | ||
|
|
||
|
|
||
| def streaming_callback(agent_name: str, chunk: str, is_final: bool): | ||
| # Chunk buffer static per call (reset each session) | ||
| if not hasattr(streaming_callback, "_buffer"): | ||
| streaming_callback._buffer = "" | ||
|
|
||
| streaming_callback._buffer_size = 0 | ||
|
|
||
|
|
||
| min_chunk_size = 512 # or any large chunk size you want | ||
|
|
||
| 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_size = 0 | ||
| if is_final: | ||
| print() | ||
|
|
||
| load_dotenv() | ||
|
|
||
|
|
||
| # Initialize the agent | ||
| agent = Agent( | ||
| agent_name="Financial-Analysis-Agent", | ||
| agent_description="Personal finance advisor agent", | ||
| system_prompt=FINANCIAL_AGENT_SYS_PROMPT, | ||
| max_loops=1, | ||
| model_name="gpt-4.1", | ||
| dynamic_temperature_enabled=True, | ||
| user_name="swarms_corp", | ||
| retry_attempts=3, | ||
| context_length=8192, | ||
| return_step_meta=False, | ||
| output_type="str", # "json", "dict", "csv" OR "string" "yaml" and | ||
| auto_generate_prompt=False, # Auto generate prompt for the agent based on name, description, and system prompt, task | ||
| 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]) | ||
|
|
||
| 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, | ||
|
|
||
| ) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / Pyre
Call error Error