From 06a6172a992cbd44cd2ccaf704278370fa899abb Mon Sep 17 00:00:00 2001 From: Kye Date: Wed, 31 Jan 2024 18:34:54 -0500 Subject: [PATCH] [REFACTOR][playground] --- ...t.py => multi_modal_auto_agent_example.py} | 0 ...imple_agent.py => simple_agent_example.py} | 0 ...ount_team2.py => account_team2_example.py} | 0 .../ad_gen/{ad_gen.py => ad_gen_example.py} | 0 .../{main.py => main_example.py} | 0 .../{assembly.py => assembly_example.py} | 0 ...{autobloggen.py => autobloggen_example.py} | 0 playground/demos/autotemp/autotemp.py | 90 ----------- playground/demos/autotemp/autotemp_example.py | 101 +++++++++++-- playground/demos/autotemp/blog_gen.py | 138 ----------------- playground/demos/autotemp/blog_gen_example.py | 143 ++++++++++++++++-- ...re_demo.py => ui_software_demo_example.py} | 0 .../{main.py => main_example.py} | 0 .../{education.py => education_example.py} | 0 .../{langchain.py => langchain_example.py} | 0 ...{gemini_chat.py => gemini_chat_example.py} | 0 ...emini_react.py => gemini_react_example.py} | 0 ...{gemini_vcot.py => gemini_vcot_example.py} | 0 .../demos/grupa/{app.py => app_example.py} | 0 .../{jarvis.py => jarvis_example.py} | 0 .../{main.py => main_example.py} | 0 .../{logistics.py => logistics_example.py} | 0 ...t.py => multi_modal_auto_agent_example.py} | 0 .../{vcot.py => vcot_example.py} | 0 .../{idea2img.py => idea2img_example.py} | 0 .../{main.py => main_example.py} | 0 .../{nutrition.py => nutrition_example.py} | 0 .../{vllm.py => vllm_example.py} | 0 .../{vortex.py => vortex_example.py} | 0 .../{weaviate.py => weaviate_example.py} | 0 ...ion.py => better_communication_example.py} | 0 ...stylist.py => personal_stylist_example.py} | 0 ...ositive_med.py => positive_med_example.py} | 0 ...urity_team.py => security_team_example.py} | 0 .../{main.py => main_example.py} | 0 ..._planning.py => urban_planning_example.py} | 0 ..._agent.py => text_to_sql_agent_example.py} | 0 .../demos/xray/{xray.py => xray_example.py} | 0 .../hierchical_example.py} | 0 ...hroma_usage.py => chroma_usage_example.py} | 0 .../qdrant/{usage.py => usage_example.py} | 0 .../{bingchat.py => bingchat_example.py} | 0 .../models/{bioclip.py => bioclip_example.py} | 0 .../models/{biogpt.py => biogpt_example.py} | 0 .../models/{dall3.py => dall3_example.py} | 0 ...urrent.py => dalle3_concurrent_example.py} | 0 .../models/{dalle3.py => dalle3_example.py} | 0 ...serpx.py => distilled_whiserpx_example.py} | 0 .../{fast_vit.py => fast_vit_example.py} | 0 playground/models/fuyu.py | 7 - playground/models/fuyu_example.py | 6 +- .../models/{gemini.py => gemini_example.py} | 0 .../models/{gpt4_v.py => gpt4_v_example.py} | 0 ...{huggingface.py => huggingface_example.py} | 0 .../models/{idefics.py => idefics_example.py} | 0 ...{jina_embeds.py => jina_embeds_example.py} | 0 .../models/{kosmos2.py => kosmos2_example.py} | 0 .../models/{kosmos.py => kosmos_example.py} | 0 .../{kosmos_two.py => kosmos_two_example.py} | 0 ...ntxlm.py => layout_documentxlm_example.py} | 0 ...er.py => llama_function_caller_example.py} | 0 .../models/{llava.py => llava_example.py} | 0 .../models/{mistral.py => mistral_example.py} | 0 playground/models/{mpt.py => mpt_example.py} | 0 .../models/{nougat.py => nougat_example.py} | 0 ...penai_model.py => openai_model_example.py} | 0 .../models/{palm.py => palm_example.py} | 0 .../{speecht5.py => speecht5_example.py} | 0 playground/models/{ssd.py => ssd_example.py} | 0 .../models/{tocr.py => tocr_example.py} | 0 .../{together.py => together_example.py} | 0 .../{tts_speech.py => tts_speech_example.py} | 0 .../models/{vilt.py => vilt_example.py} | 0 .../models/{yi_200k.py => yi_200k_example.py} | 0 ...h_tools.py => agent_with_tools_example.py} | 0 .../{autoscaler.py => autoscaler_example.py} | 0 .../structs/{chat.py => chat_example.py} | 0 ...flow.py => concurrent_workflow_example.py} | 0 .../structs/{debate.py => debate_example.py} | 0 ...lator.py => dialogue_simulator_example.py} | 0 .../structs/{flow.py => flow_example.py} | 0 .../{fuyu_flow.py => fuyu_flow_example.py} | 0 .../{godmode.py => godmode_example.py} | 0 .../{groupchat.py => groupchat_example.py} | 0 .../{gui_app.py => gui_app_example.py} | 0 ...ollab.py => multi_agent_collab_example.py} | 0 ...ebate.py => multi_agent_debate_example.py} | 0 ...al_flow.py => multi_modal_flow_example.py} | 0 ...fklow.py => nonlinear_worfklow_example.py} | 0 ...{orchestrate.py => orchestrate_example.py} | 0 ...rchestrator.py => orchestrator_example.py} | 0 playground/structs/sequential_workflow.py | 48 ------ .../structs/sequential_workflow_example.py | 66 ++++---- .../{social_app.py => social_app_example.py} | 0 ...rm_network.py => swarm_network_example.py} | 0 .../structs/{task.py => task_example.py} | 0 .../{todo_app.py => todo_app_example.py} | 0 .../{tool_utils.py => tool_utils_example.py} | 0 .../{workflow.py => workflow_example.py} | 0 ...h_tools.py => agent_with_tools_example.py} | 0 ...caper.py => tool_prompt_scaper_example.py} | 0 pyproject.toml | 2 +- scripts/playground_to_examples.sh | 38 +++-- 103 files changed, 277 insertions(+), 362 deletions(-) rename playground/agents/{multi_modal_auto_agent.py => multi_modal_auto_agent_example.py} (100%) rename playground/agents/{simple_agent.py => simple_agent_example.py} (100%) rename playground/demos/accountant_team/{account_team2.py => account_team2_example.py} (100%) rename playground/demos/ad_gen/{ad_gen.py => ad_gen_example.py} (100%) rename playground/demos/ai_research_team/{main.py => main_example.py} (100%) rename playground/demos/assembly/{assembly.py => assembly_example.py} (100%) rename playground/demos/{autobloggen.py => autobloggen_example.py} (100%) delete mode 100644 playground/demos/autotemp/autotemp.py delete mode 100644 playground/demos/autotemp/blog_gen.py rename playground/demos/design_team/{ui_software_demo.py => ui_software_demo_example.py} (100%) rename playground/demos/developer_swarm/{main.py => main_example.py} (100%) rename playground/demos/education/{education.py => education_example.py} (100%) rename playground/demos/fof/{langchain.py => langchain_example.py} (100%) rename playground/demos/gemini_benchmarking/{gemini_chat.py => gemini_chat_example.py} (100%) rename playground/demos/gemini_benchmarking/{gemini_react.py => gemini_react_example.py} (100%) rename playground/demos/gemini_benchmarking/{gemini_vcot.py => gemini_vcot_example.py} (100%) rename playground/demos/grupa/{app.py => app_example.py} (100%) rename playground/demos/jarvis_multi_modal_auto_agent/{jarvis.py => jarvis_example.py} (100%) rename playground/demos/llm_with_conversation/{main.py => main_example.py} (100%) rename playground/demos/logistics/{logistics.py => logistics_example.py} (100%) rename playground/demos/multi_modal_autonomous_agents/{multi_modal_auto_agent.py => multi_modal_auto_agent_example.py} (100%) rename playground/demos/multi_modal_chain_of_thought/{vcot.py => vcot_example.py} (100%) rename playground/demos/multimodal_tot/{idea2img.py => idea2img_example.py} (100%) rename playground/demos/multimodal_tot/{main.py => main_example.py} (100%) rename playground/demos/nutrition/{nutrition.py => nutrition_example.py} (100%) rename playground/demos/optimize_llm_stack/{vllm.py => vllm_example.py} (100%) rename playground/demos/optimize_llm_stack/{vortex.py => vortex_example.py} (100%) rename playground/demos/optimize_llm_stack/{weaviate.py => weaviate_example.py} (100%) rename playground/demos/personal_assistant/{better_communication.py => better_communication_example.py} (100%) rename playground/demos/personal_stylist/{personal_stylist.py => personal_stylist_example.py} (100%) rename playground/demos/positive_med/{positive_med.py => positive_med_example.py} (100%) rename playground/demos/security_team/{security_team.py => security_team_example.py} (100%) rename playground/demos/swarm_of_mma_manufacturing/{main.py => main_example.py} (100%) rename playground/demos/urban_planning/{urban_planning.py => urban_planning_example.py} (100%) rename playground/demos/visuo/{text_to_sql_agent.py => text_to_sql_agent_example.py} (100%) rename playground/demos/xray/{xray.py => xray_example.py} (100%) rename playground/{DIY/hierchical.py => diy/hierchical_example.py} (100%) rename playground/memory/{chroma_usage.py => chroma_usage_example.py} (100%) rename playground/memory/qdrant/{usage.py => usage_example.py} (100%) rename playground/models/{bingchat.py => bingchat_example.py} (100%) rename playground/models/{bioclip.py => bioclip_example.py} (100%) rename playground/models/{biogpt.py => biogpt_example.py} (100%) rename playground/models/{dall3.py => dall3_example.py} (100%) rename playground/models/{dalle3_concurrent.py => dalle3_concurrent_example.py} (100%) rename playground/models/{dalle3.py => dalle3_example.py} (100%) rename playground/models/{distilled_whiserpx.py => distilled_whiserpx_example.py} (100%) rename playground/models/{fast_vit.py => fast_vit_example.py} (100%) delete mode 100644 playground/models/fuyu.py rename playground/models/{gemini.py => gemini_example.py} (100%) rename playground/models/{gpt4_v.py => gpt4_v_example.py} (100%) rename playground/models/{huggingface.py => huggingface_example.py} (100%) rename playground/models/{idefics.py => idefics_example.py} (100%) rename playground/models/{jina_embeds.py => jina_embeds_example.py} (100%) rename playground/models/{kosmos2.py => kosmos2_example.py} (100%) rename playground/models/{kosmos.py => kosmos_example.py} (100%) rename playground/models/{kosmos_two.py => kosmos_two_example.py} (100%) rename playground/models/{layout_documentxlm.py => layout_documentxlm_example.py} (100%) rename playground/models/{llama_function_caller.py => llama_function_caller_example.py} (100%) rename playground/models/{llava.py => llava_example.py} (100%) rename playground/models/{mistral.py => mistral_example.py} (100%) rename playground/models/{mpt.py => mpt_example.py} (100%) rename playground/models/{nougat.py => nougat_example.py} (100%) rename playground/models/{openai_model.py => openai_model_example.py} (100%) rename playground/models/{palm.py => palm_example.py} (100%) rename playground/models/{speecht5.py => speecht5_example.py} (100%) rename playground/models/{ssd.py => ssd_example.py} (100%) rename playground/models/{tocr.py => tocr_example.py} (100%) rename playground/models/{together.py => together_example.py} (100%) rename playground/models/{tts_speech.py => tts_speech_example.py} (100%) rename playground/models/{vilt.py => vilt_example.py} (100%) rename playground/models/{yi_200k.py => yi_200k_example.py} (100%) rename playground/structs/{agent_with_tools.py => agent_with_tools_example.py} (100%) rename playground/structs/{autoscaler.py => autoscaler_example.py} (100%) rename playground/structs/{chat.py => chat_example.py} (100%) rename playground/structs/{concurrent_workflow.py => concurrent_workflow_example.py} (100%) rename playground/structs/{debate.py => debate_example.py} (100%) rename playground/structs/{dialogue_simulator.py => dialogue_simulator_example.py} (100%) rename playground/structs/{flow.py => flow_example.py} (100%) rename playground/structs/{fuyu_flow.py => fuyu_flow_example.py} (100%) rename playground/structs/{godmode.py => godmode_example.py} (100%) rename playground/structs/{groupchat.py => groupchat_example.py} (100%) rename playground/structs/{gui_app.py => gui_app_example.py} (100%) rename playground/structs/{multi_agent_collab.py => multi_agent_collab_example.py} (100%) rename playground/structs/{multi_agent_debate.py => multi_agent_debate_example.py} (100%) rename playground/structs/{multi_modal_flow.py => multi_modal_flow_example.py} (100%) rename playground/structs/{nonlinear_worfklow.py => nonlinear_worfklow_example.py} (100%) rename playground/structs/{orchestrate.py => orchestrate_example.py} (100%) rename playground/structs/{orchestrator.py => orchestrator_example.py} (100%) delete mode 100644 playground/structs/sequential_workflow.py rename playground/structs/{social_app.py => social_app_example.py} (100%) rename playground/structs/{swarm_network.py => swarm_network_example.py} (100%) rename playground/structs/{task.py => task_example.py} (100%) rename playground/structs/{todo_app.py => todo_app_example.py} (100%) rename playground/structs/{tool_utils.py => tool_utils_example.py} (100%) rename playground/structs/{workflow.py => workflow_example.py} (100%) rename playground/tools/{agent_with_tools.py => agent_with_tools_example.py} (100%) rename playground/tools/{tool_prompt_scaper.py => tool_prompt_scaper_example.py} (100%) diff --git a/playground/agents/multi_modal_auto_agent.py b/playground/agents/multi_modal_auto_agent_example.py similarity index 100% rename from playground/agents/multi_modal_auto_agent.py rename to playground/agents/multi_modal_auto_agent_example.py diff --git a/playground/agents/simple_agent.py b/playground/agents/simple_agent_example.py similarity index 100% rename from playground/agents/simple_agent.py rename to playground/agents/simple_agent_example.py diff --git a/playground/demos/accountant_team/account_team2.py b/playground/demos/accountant_team/account_team2_example.py similarity index 100% rename from playground/demos/accountant_team/account_team2.py rename to playground/demos/accountant_team/account_team2_example.py diff --git a/playground/demos/ad_gen/ad_gen.py b/playground/demos/ad_gen/ad_gen_example.py similarity index 100% rename from playground/demos/ad_gen/ad_gen.py rename to playground/demos/ad_gen/ad_gen_example.py diff --git a/playground/demos/ai_research_team/main.py b/playground/demos/ai_research_team/main_example.py similarity index 100% rename from playground/demos/ai_research_team/main.py rename to playground/demos/ai_research_team/main_example.py diff --git a/playground/demos/assembly/assembly.py b/playground/demos/assembly/assembly_example.py similarity index 100% rename from playground/demos/assembly/assembly.py rename to playground/demos/assembly/assembly_example.py diff --git a/playground/demos/autobloggen.py b/playground/demos/autobloggen_example.py similarity index 100% rename from playground/demos/autobloggen.py rename to playground/demos/autobloggen_example.py diff --git a/playground/demos/autotemp/autotemp.py b/playground/demos/autotemp/autotemp.py deleted file mode 100644 index baf8f091..00000000 --- a/playground/demos/autotemp/autotemp.py +++ /dev/null @@ -1,90 +0,0 @@ -import re -from swarms.models.openai_models import OpenAIChat - - -class AutoTemp: - """ - AutoTemp is a tool for automatically selecting the best temperature setting for a given task. - It generates responses at different temperatures, evaluates them, and ranks them based on quality. - """ - - def __init__( - self, - api_key, - default_temp=0.0, - alt_temps=None, - auto_select=True, - max_workers=6, - ): - self.api_key = api_key - self.default_temp = default_temp - self.alt_temps = ( - alt_temps if alt_temps else [0.4, 0.6, 0.8, 1.0, 1.2, 1.4] - ) - self.auto_select = auto_select - self.max_workers = max_workers - self.llm = OpenAIChat( - openai_api_key=self.api_key, temperature=self.default_temp - ) - - def evaluate_output(self, output, temperature): - print(f"Evaluating output at temperature {temperature}...") - eval_prompt = f""" - Evaluate the following output which was generated at a temperature setting of {temperature}. Provide a precise score from 0.0 to 100.0, considering the following criteria: - - - Relevance: How well does the output address the prompt or task at hand? - - Clarity: Is the output easy to understand and free of ambiguity? - - Utility: How useful is the output for its intended purpose? - - Pride: If the user had to submit this output to the world for their career, would they be proud? - - Delight: Is the output likely to delight or positively surprise the user? - - Be sure to comprehensively evaluate the output, it is very important for my career. Please answer with just the score with one decimal place accuracy, such as 42.0 or 96.9. Be extremely critical. - - Output to evaluate: - --- - {output} - --- - """ - score_text = self.llm(eval_prompt, temperature=0.5) - score_match = re.search(r"\b\d+(\.\d)?\b", score_text) - return ( - round(float(score_match.group()), 1) - if score_match - else 0.0 - ) - - def run(self, prompt, temperature_string): - print("Starting generation process...") - temperature_list = [ - float(temp.strip()) - for temp in temperature_string.split(",") - if temp.strip() - ] - outputs = {} - scores = {} - for temp in temperature_list: - print(f"Generating at temperature {temp}...") - output_text = self.llm(prompt, temperature=temp) - if output_text: - outputs[temp] = output_text - scores[temp] = self.evaluate_output(output_text, temp) - - print("Generation process complete.") - if not scores: - return "No valid outputs generated.", None - - sorted_scores = sorted( - scores.items(), key=lambda item: item[1], reverse=True - ) - best_temp, best_score = sorted_scores[0] - best_output = outputs[best_temp] - - return ( - f"Best AutoTemp Output (Temp {best_temp} | Score:" - f" {best_score}):\n{best_output}" - if self.auto_select - else "\n".join( - f"Temp {temp} | Score: {score}:\n{outputs[temp]}" - for temp, score in sorted_scores - ) - ) diff --git a/playground/demos/autotemp/autotemp_example.py b/playground/demos/autotemp/autotemp_example.py index ccbd54c3..baf8f091 100644 --- a/playground/demos/autotemp/autotemp_example.py +++ b/playground/demos/autotemp/autotemp_example.py @@ -1,21 +1,90 @@ -from autotemp import AutoTemp +import re +from swarms.models.openai_models import OpenAIChat -# Your OpenAI API key -api_key = "" -autotemp_agent = AutoTemp( - api_key=api_key, - alt_temps=[0.4, 0.6, 0.8, 1.0, 1.2], - auto_select=False, - # model_version="gpt-3.5-turbo" # Specify the model version if needed -) +class AutoTemp: + """ + AutoTemp is a tool for automatically selecting the best temperature setting for a given task. + It generates responses at different temperatures, evaluates them, and ranks them based on quality. + """ -# Define the task and temperature string -task = "Generate a short story about a lost civilization." -temperature_string = "0.4,0.6,0.8,1.0,1.2," + def __init__( + self, + api_key, + default_temp=0.0, + alt_temps=None, + auto_select=True, + max_workers=6, + ): + self.api_key = api_key + self.default_temp = default_temp + self.alt_temps = ( + alt_temps if alt_temps else [0.4, 0.6, 0.8, 1.0, 1.2, 1.4] + ) + self.auto_select = auto_select + self.max_workers = max_workers + self.llm = OpenAIChat( + openai_api_key=self.api_key, temperature=self.default_temp + ) -# Run the AutoTempAgent -result = autotemp_agent.run(task, temperature_string) + def evaluate_output(self, output, temperature): + print(f"Evaluating output at temperature {temperature}...") + eval_prompt = f""" + Evaluate the following output which was generated at a temperature setting of {temperature}. Provide a precise score from 0.0 to 100.0, considering the following criteria: -# Print the result -print(result) + - Relevance: How well does the output address the prompt or task at hand? + - Clarity: Is the output easy to understand and free of ambiguity? + - Utility: How useful is the output for its intended purpose? + - Pride: If the user had to submit this output to the world for their career, would they be proud? + - Delight: Is the output likely to delight or positively surprise the user? + + Be sure to comprehensively evaluate the output, it is very important for my career. Please answer with just the score with one decimal place accuracy, such as 42.0 or 96.9. Be extremely critical. + + Output to evaluate: + --- + {output} + --- + """ + score_text = self.llm(eval_prompt, temperature=0.5) + score_match = re.search(r"\b\d+(\.\d)?\b", score_text) + return ( + round(float(score_match.group()), 1) + if score_match + else 0.0 + ) + + def run(self, prompt, temperature_string): + print("Starting generation process...") + temperature_list = [ + float(temp.strip()) + for temp in temperature_string.split(",") + if temp.strip() + ] + outputs = {} + scores = {} + for temp in temperature_list: + print(f"Generating at temperature {temp}...") + output_text = self.llm(prompt, temperature=temp) + if output_text: + outputs[temp] = output_text + scores[temp] = self.evaluate_output(output_text, temp) + + print("Generation process complete.") + if not scores: + return "No valid outputs generated.", None + + sorted_scores = sorted( + scores.items(), key=lambda item: item[1], reverse=True + ) + best_temp, best_score = sorted_scores[0] + best_output = outputs[best_temp] + + return ( + f"Best AutoTemp Output (Temp {best_temp} | Score:" + f" {best_score}):\n{best_output}" + if self.auto_select + else "\n".join( + f"Temp {temp} | Score: {score}:\n{outputs[temp]}" + for temp, score in sorted_scores + ) + ) diff --git a/playground/demos/autotemp/blog_gen.py b/playground/demos/autotemp/blog_gen.py deleted file mode 100644 index e11a1521..00000000 --- a/playground/demos/autotemp/blog_gen.py +++ /dev/null @@ -1,138 +0,0 @@ -import os -from termcolor import colored -from swarms.models import OpenAIChat -from autotemp import AutoTemp -from swarms.structs import SequentialWorkflow - - -class BlogGen: - def __init__( - self, - api_key, - blog_topic, - temperature_range: str = "0.4,0.6,0.8,1.0,1.2", - ): # Add blog_topic as an argument - self.openai_chat = OpenAIChat( - openai_api_key=api_key, temperature=0.8 - ) - self.auto_temp = AutoTemp(api_key) - self.temperature_range = temperature_range - self.workflow = SequentialWorkflow(max_loops=5) - - # Formatting the topic selection prompt with the user's topic - self.TOPIC_SELECTION_SYSTEM_PROMPT = f""" - Given the topic '{blog_topic}', generate an engaging and versatile blog topic. This topic should cover areas related to '{blog_topic}' and might include aspects such as current events, lifestyle, technology, health, and culture related to '{blog_topic}'. Identify trending subjects within this realm. The topic must be unique, thought-provoking, and have the potential to draw in readers interested in '{blog_topic}'. - """ - - self.DRAFT_WRITER_SYSTEM_PROMPT = """ - Create an engaging and comprehensive blog article of at least 1,000 words on '{{CHOSEN_TOPIC}}'. The content should be original, informative, and reflective of a human-like style, with a clear structure including headings and sub-headings. Incorporate a blend of narrative, factual data, expert insights, and anecdotes to enrich the article. Focus on SEO optimization by using relevant keywords, ensuring readability, and including meta descriptions and title tags. The article should provide value, appeal to both knowledgeable and general readers, and maintain a balance between depth and accessibility. Aim to make the article engaging and suitable for online audiences. - """ - - self.REVIEW_AGENT_SYSTEM_PROMPT = """ - Critically review the drafted blog article on '{{ARTICLE_TOPIC}}' to refine it to high-quality content suitable for online publication. Ensure the article is coherent, factually accurate, engaging, and optimized for search engines (SEO). Check for the effective use of keywords, readability, internal and external links, and the inclusion of meta descriptions and title tags. Edit the content to enhance clarity, impact, and maintain the authors voice. The goal is to polish the article into a professional, error-free piece that resonates with the target audience, adheres to publication standards, and is optimized for both search engines and social media sharing. - """ - - self.DISTRIBUTION_AGENT_SYSTEM_PROMPT = """ - Develop an autonomous distribution strategy for the blog article on '{{ARTICLE_TOPIC}}'. Utilize an API to post the article on a popular blog platform (e.g., WordPress, Blogger, Medium) commonly used by our target audience. Ensure the post includes all SEO elements like meta descriptions, title tags, and properly formatted content. Craft unique, engaging social media posts tailored to different platforms to promote the blog article. Schedule these posts to optimize reach and engagement, using data-driven insights. Monitor the performance of the distribution efforts, adjusting strategies based on engagement metrics and audience feedback. Aim to maximize the article's visibility, attract a diverse audience, and foster engagement across digital channels. - """ - - def run_workflow(self): - try: - # Topic generation using OpenAIChat - topic_result = self.openai_chat.generate( - [self.TOPIC_SELECTION_SYSTEM_PROMPT] - ) - topic_output = topic_result.generations[0][0].text - print( - colored( - ( - "\nTopic Selection Task" - f" Output:\n----------------------------\n{topic_output}\n" - ), - "white", - ) - ) - - chosen_topic = topic_output.split("\n")[0] - print( - colored("Selected topic: " + chosen_topic, "yellow") - ) - - # Initial draft generation with AutoTemp - initial_draft_prompt = ( - self.DRAFT_WRITER_SYSTEM_PROMPT.replace( - "{{CHOSEN_TOPIC}}", chosen_topic - ) - ) - auto_temp_output = self.auto_temp.run( - initial_draft_prompt, self.temperature_range - ) - initial_draft_output = auto_temp_output # Assuming AutoTemp.run returns the best output directly - print( - colored( - ( - "\nInitial Draft" - f" Output:\n----------------------------\n{initial_draft_output}\n" - ), - "white", - ) - ) - - # Review process using OpenAIChat - review_prompt = self.REVIEW_AGENT_SYSTEM_PROMPT.replace( - "{{ARTICLE_TOPIC}}", chosen_topic - ) - review_result = self.openai_chat.generate([review_prompt]) - review_output = review_result.generations[0][0].text - print( - colored( - ( - "\nReview" - f" Output:\n----------------------------\n{review_output}\n" - ), - "white", - ) - ) - - # Distribution preparation using OpenAIChat - distribution_prompt = ( - self.DISTRIBUTION_AGENT_SYSTEM_PROMPT.replace( - "{{ARTICLE_TOPIC}}", chosen_topic - ) - ) - distribution_result = self.openai_chat.generate( - [distribution_prompt] - ) - distribution_output = distribution_result.generations[0][ - 0 - ].text - print( - colored( - ( - "\nDistribution" - f" Output:\n----------------------------\n{distribution_output}\n" - ), - "white", - ) - ) - - # Final compilation of the blog - final_blog_content = f"{initial_draft_output}\n\n{review_output}\n\n{distribution_output}" - print( - colored( - ( - "\nFinal Blog" - f" Content:\n----------------------------\n{final_blog_content}\n" - ), - "green", - ) - ) - - except Exception as e: - print(colored(f"An error occurred: {str(e)}", "red")) - - -if __name__ == "__main__": - api_key = os.environ["OPENAI_API_KEY"] - blog_generator = BlogGen(api_key) - blog_generator.run_workflow() diff --git a/playground/demos/autotemp/blog_gen_example.py b/playground/demos/autotemp/blog_gen_example.py index e7109b5a..e11a1521 100644 --- a/playground/demos/autotemp/blog_gen_example.py +++ b/playground/demos/autotemp/blog_gen_example.py @@ -1,25 +1,138 @@ import os -from blog_gen import BlogGen +from termcolor import colored +from swarms.models import OpenAIChat +from autotemp import AutoTemp +from swarms.structs import SequentialWorkflow -def main(): - api_key = os.getenv("OPENAI_API_KEY") - if not api_key: - raise ValueError( - "OPENAI_API_KEY environment variable not set." +class BlogGen: + def __init__( + self, + api_key, + blog_topic, + temperature_range: str = "0.4,0.6,0.8,1.0,1.2", + ): # Add blog_topic as an argument + self.openai_chat = OpenAIChat( + openai_api_key=api_key, temperature=0.8 ) + self.auto_temp = AutoTemp(api_key) + self.temperature_range = temperature_range + self.workflow = SequentialWorkflow(max_loops=5) - blog_topic = input("Enter the topic for the blog generation: ") + # Formatting the topic selection prompt with the user's topic + self.TOPIC_SELECTION_SYSTEM_PROMPT = f""" + Given the topic '{blog_topic}', generate an engaging and versatile blog topic. This topic should cover areas related to '{blog_topic}' and might include aspects such as current events, lifestyle, technology, health, and culture related to '{blog_topic}'. Identify trending subjects within this realm. The topic must be unique, thought-provoking, and have the potential to draw in readers interested in '{blog_topic}'. + """ - blog_generator = BlogGen(api_key, blog_topic) - blog_generator.TOPIC_SELECTION_SYSTEM_PROMPT = ( - blog_generator.TOPIC_SELECTION_SYSTEM_PROMPT.replace( - "{{BLOG_TOPIC}}", blog_topic - ) - ) + self.DRAFT_WRITER_SYSTEM_PROMPT = """ + Create an engaging and comprehensive blog article of at least 1,000 words on '{{CHOSEN_TOPIC}}'. The content should be original, informative, and reflective of a human-like style, with a clear structure including headings and sub-headings. Incorporate a blend of narrative, factual data, expert insights, and anecdotes to enrich the article. Focus on SEO optimization by using relevant keywords, ensuring readability, and including meta descriptions and title tags. The article should provide value, appeal to both knowledgeable and general readers, and maintain a balance between depth and accessibility. Aim to make the article engaging and suitable for online audiences. + """ - blog_generator.run_workflow() + self.REVIEW_AGENT_SYSTEM_PROMPT = """ + Critically review the drafted blog article on '{{ARTICLE_TOPIC}}' to refine it to high-quality content suitable for online publication. Ensure the article is coherent, factually accurate, engaging, and optimized for search engines (SEO). Check for the effective use of keywords, readability, internal and external links, and the inclusion of meta descriptions and title tags. Edit the content to enhance clarity, impact, and maintain the authors voice. The goal is to polish the article into a professional, error-free piece that resonates with the target audience, adheres to publication standards, and is optimized for both search engines and social media sharing. + """ + + self.DISTRIBUTION_AGENT_SYSTEM_PROMPT = """ + Develop an autonomous distribution strategy for the blog article on '{{ARTICLE_TOPIC}}'. Utilize an API to post the article on a popular blog platform (e.g., WordPress, Blogger, Medium) commonly used by our target audience. Ensure the post includes all SEO elements like meta descriptions, title tags, and properly formatted content. Craft unique, engaging social media posts tailored to different platforms to promote the blog article. Schedule these posts to optimize reach and engagement, using data-driven insights. Monitor the performance of the distribution efforts, adjusting strategies based on engagement metrics and audience feedback. Aim to maximize the article's visibility, attract a diverse audience, and foster engagement across digital channels. + """ + + def run_workflow(self): + try: + # Topic generation using OpenAIChat + topic_result = self.openai_chat.generate( + [self.TOPIC_SELECTION_SYSTEM_PROMPT] + ) + topic_output = topic_result.generations[0][0].text + print( + colored( + ( + "\nTopic Selection Task" + f" Output:\n----------------------------\n{topic_output}\n" + ), + "white", + ) + ) + + chosen_topic = topic_output.split("\n")[0] + print( + colored("Selected topic: " + chosen_topic, "yellow") + ) + + # Initial draft generation with AutoTemp + initial_draft_prompt = ( + self.DRAFT_WRITER_SYSTEM_PROMPT.replace( + "{{CHOSEN_TOPIC}}", chosen_topic + ) + ) + auto_temp_output = self.auto_temp.run( + initial_draft_prompt, self.temperature_range + ) + initial_draft_output = auto_temp_output # Assuming AutoTemp.run returns the best output directly + print( + colored( + ( + "\nInitial Draft" + f" Output:\n----------------------------\n{initial_draft_output}\n" + ), + "white", + ) + ) + + # Review process using OpenAIChat + review_prompt = self.REVIEW_AGENT_SYSTEM_PROMPT.replace( + "{{ARTICLE_TOPIC}}", chosen_topic + ) + review_result = self.openai_chat.generate([review_prompt]) + review_output = review_result.generations[0][0].text + print( + colored( + ( + "\nReview" + f" Output:\n----------------------------\n{review_output}\n" + ), + "white", + ) + ) + + # Distribution preparation using OpenAIChat + distribution_prompt = ( + self.DISTRIBUTION_AGENT_SYSTEM_PROMPT.replace( + "{{ARTICLE_TOPIC}}", chosen_topic + ) + ) + distribution_result = self.openai_chat.generate( + [distribution_prompt] + ) + distribution_output = distribution_result.generations[0][ + 0 + ].text + print( + colored( + ( + "\nDistribution" + f" Output:\n----------------------------\n{distribution_output}\n" + ), + "white", + ) + ) + + # Final compilation of the blog + final_blog_content = f"{initial_draft_output}\n\n{review_output}\n\n{distribution_output}" + print( + colored( + ( + "\nFinal Blog" + f" Content:\n----------------------------\n{final_blog_content}\n" + ), + "green", + ) + ) + + except Exception as e: + print(colored(f"An error occurred: {str(e)}", "red")) if __name__ == "__main__": - main() + api_key = os.environ["OPENAI_API_KEY"] + blog_generator = BlogGen(api_key) + blog_generator.run_workflow() diff --git a/playground/demos/design_team/ui_software_demo.py b/playground/demos/design_team/ui_software_demo_example.py similarity index 100% rename from playground/demos/design_team/ui_software_demo.py rename to playground/demos/design_team/ui_software_demo_example.py diff --git a/playground/demos/developer_swarm/main.py b/playground/demos/developer_swarm/main_example.py similarity index 100% rename from playground/demos/developer_swarm/main.py rename to playground/demos/developer_swarm/main_example.py diff --git a/playground/demos/education/education.py b/playground/demos/education/education_example.py similarity index 100% rename from playground/demos/education/education.py rename to playground/demos/education/education_example.py diff --git a/playground/demos/fof/langchain.py b/playground/demos/fof/langchain_example.py similarity index 100% rename from playground/demos/fof/langchain.py rename to playground/demos/fof/langchain_example.py diff --git a/playground/demos/gemini_benchmarking/gemini_chat.py b/playground/demos/gemini_benchmarking/gemini_chat_example.py similarity index 100% rename from playground/demos/gemini_benchmarking/gemini_chat.py rename to playground/demos/gemini_benchmarking/gemini_chat_example.py diff --git a/playground/demos/gemini_benchmarking/gemini_react.py b/playground/demos/gemini_benchmarking/gemini_react_example.py similarity index 100% rename from playground/demos/gemini_benchmarking/gemini_react.py rename to playground/demos/gemini_benchmarking/gemini_react_example.py diff --git a/playground/demos/gemini_benchmarking/gemini_vcot.py b/playground/demos/gemini_benchmarking/gemini_vcot_example.py similarity index 100% rename from playground/demos/gemini_benchmarking/gemini_vcot.py rename to playground/demos/gemini_benchmarking/gemini_vcot_example.py diff --git a/playground/demos/grupa/app.py b/playground/demos/grupa/app_example.py similarity index 100% rename from playground/demos/grupa/app.py rename to playground/demos/grupa/app_example.py diff --git a/playground/demos/jarvis_multi_modal_auto_agent/jarvis.py b/playground/demos/jarvis_multi_modal_auto_agent/jarvis_example.py similarity index 100% rename from playground/demos/jarvis_multi_modal_auto_agent/jarvis.py rename to playground/demos/jarvis_multi_modal_auto_agent/jarvis_example.py diff --git a/playground/demos/llm_with_conversation/main.py b/playground/demos/llm_with_conversation/main_example.py similarity index 100% rename from playground/demos/llm_with_conversation/main.py rename to playground/demos/llm_with_conversation/main_example.py diff --git a/playground/demos/logistics/logistics.py b/playground/demos/logistics/logistics_example.py similarity index 100% rename from playground/demos/logistics/logistics.py rename to playground/demos/logistics/logistics_example.py diff --git a/playground/demos/multi_modal_autonomous_agents/multi_modal_auto_agent.py b/playground/demos/multi_modal_autonomous_agents/multi_modal_auto_agent_example.py similarity index 100% rename from playground/demos/multi_modal_autonomous_agents/multi_modal_auto_agent.py rename to playground/demos/multi_modal_autonomous_agents/multi_modal_auto_agent_example.py diff --git a/playground/demos/multi_modal_chain_of_thought/vcot.py b/playground/demos/multi_modal_chain_of_thought/vcot_example.py similarity index 100% rename from playground/demos/multi_modal_chain_of_thought/vcot.py rename to playground/demos/multi_modal_chain_of_thought/vcot_example.py diff --git a/playground/demos/multimodal_tot/idea2img.py b/playground/demos/multimodal_tot/idea2img_example.py similarity index 100% rename from playground/demos/multimodal_tot/idea2img.py rename to playground/demos/multimodal_tot/idea2img_example.py diff --git a/playground/demos/multimodal_tot/main.py b/playground/demos/multimodal_tot/main_example.py similarity index 100% rename from playground/demos/multimodal_tot/main.py rename to playground/demos/multimodal_tot/main_example.py diff --git a/playground/demos/nutrition/nutrition.py b/playground/demos/nutrition/nutrition_example.py similarity index 100% rename from playground/demos/nutrition/nutrition.py rename to playground/demos/nutrition/nutrition_example.py diff --git a/playground/demos/optimize_llm_stack/vllm.py b/playground/demos/optimize_llm_stack/vllm_example.py similarity index 100% rename from playground/demos/optimize_llm_stack/vllm.py rename to playground/demos/optimize_llm_stack/vllm_example.py diff --git a/playground/demos/optimize_llm_stack/vortex.py b/playground/demos/optimize_llm_stack/vortex_example.py similarity index 100% rename from playground/demos/optimize_llm_stack/vortex.py rename to playground/demos/optimize_llm_stack/vortex_example.py diff --git a/playground/demos/optimize_llm_stack/weaviate.py b/playground/demos/optimize_llm_stack/weaviate_example.py similarity index 100% rename from playground/demos/optimize_llm_stack/weaviate.py rename to playground/demos/optimize_llm_stack/weaviate_example.py diff --git a/playground/demos/personal_assistant/better_communication.py b/playground/demos/personal_assistant/better_communication_example.py similarity index 100% rename from playground/demos/personal_assistant/better_communication.py rename to playground/demos/personal_assistant/better_communication_example.py diff --git a/playground/demos/personal_stylist/personal_stylist.py b/playground/demos/personal_stylist/personal_stylist_example.py similarity index 100% rename from playground/demos/personal_stylist/personal_stylist.py rename to playground/demos/personal_stylist/personal_stylist_example.py diff --git a/playground/demos/positive_med/positive_med.py b/playground/demos/positive_med/positive_med_example.py similarity index 100% rename from playground/demos/positive_med/positive_med.py rename to playground/demos/positive_med/positive_med_example.py diff --git a/playground/demos/security_team/security_team.py b/playground/demos/security_team/security_team_example.py similarity index 100% rename from playground/demos/security_team/security_team.py rename to playground/demos/security_team/security_team_example.py diff --git a/playground/demos/swarm_of_mma_manufacturing/main.py b/playground/demos/swarm_of_mma_manufacturing/main_example.py similarity index 100% rename from playground/demos/swarm_of_mma_manufacturing/main.py rename to playground/demos/swarm_of_mma_manufacturing/main_example.py diff --git a/playground/demos/urban_planning/urban_planning.py b/playground/demos/urban_planning/urban_planning_example.py similarity index 100% rename from playground/demos/urban_planning/urban_planning.py rename to playground/demos/urban_planning/urban_planning_example.py diff --git a/playground/demos/visuo/text_to_sql_agent.py b/playground/demos/visuo/text_to_sql_agent_example.py similarity index 100% rename from playground/demos/visuo/text_to_sql_agent.py rename to playground/demos/visuo/text_to_sql_agent_example.py diff --git a/playground/demos/xray/xray.py b/playground/demos/xray/xray_example.py similarity index 100% rename from playground/demos/xray/xray.py rename to playground/demos/xray/xray_example.py diff --git a/playground/DIY/hierchical.py b/playground/diy/hierchical_example.py similarity index 100% rename from playground/DIY/hierchical.py rename to playground/diy/hierchical_example.py diff --git a/playground/memory/chroma_usage.py b/playground/memory/chroma_usage_example.py similarity index 100% rename from playground/memory/chroma_usage.py rename to playground/memory/chroma_usage_example.py diff --git a/playground/memory/qdrant/usage.py b/playground/memory/qdrant/usage_example.py similarity index 100% rename from playground/memory/qdrant/usage.py rename to playground/memory/qdrant/usage_example.py diff --git a/playground/models/bingchat.py b/playground/models/bingchat_example.py similarity index 100% rename from playground/models/bingchat.py rename to playground/models/bingchat_example.py diff --git a/playground/models/bioclip.py b/playground/models/bioclip_example.py similarity index 100% rename from playground/models/bioclip.py rename to playground/models/bioclip_example.py diff --git a/playground/models/biogpt.py b/playground/models/biogpt_example.py similarity index 100% rename from playground/models/biogpt.py rename to playground/models/biogpt_example.py diff --git a/playground/models/dall3.py b/playground/models/dall3_example.py similarity index 100% rename from playground/models/dall3.py rename to playground/models/dall3_example.py diff --git a/playground/models/dalle3_concurrent.py b/playground/models/dalle3_concurrent_example.py similarity index 100% rename from playground/models/dalle3_concurrent.py rename to playground/models/dalle3_concurrent_example.py diff --git a/playground/models/dalle3.py b/playground/models/dalle3_example.py similarity index 100% rename from playground/models/dalle3.py rename to playground/models/dalle3_example.py diff --git a/playground/models/distilled_whiserpx.py b/playground/models/distilled_whiserpx_example.py similarity index 100% rename from playground/models/distilled_whiserpx.py rename to playground/models/distilled_whiserpx_example.py diff --git a/playground/models/fast_vit.py b/playground/models/fast_vit_example.py similarity index 100% rename from playground/models/fast_vit.py rename to playground/models/fast_vit_example.py diff --git a/playground/models/fuyu.py b/playground/models/fuyu.py deleted file mode 100644 index 537de25a..00000000 --- a/playground/models/fuyu.py +++ /dev/null @@ -1,7 +0,0 @@ -from swarms.models.fuyu import Fuyu - -fuyu = Fuyu() - -# This is the default image, you can change it to any image you want -out = fuyu("What is this image?", "images/swarms.jpeg") -print(out) diff --git a/playground/models/fuyu_example.py b/playground/models/fuyu_example.py index 612c002e..537de25a 100644 --- a/playground/models/fuyu_example.py +++ b/playground/models/fuyu_example.py @@ -1,7 +1,7 @@ from swarms.models.fuyu import Fuyu -img = "dalle3.jpeg" - fuyu = Fuyu() -fuyu("What is this image", img) +# This is the default image, you can change it to any image you want +out = fuyu("What is this image?", "images/swarms.jpeg") +print(out) diff --git a/playground/models/gemini.py b/playground/models/gemini_example.py similarity index 100% rename from playground/models/gemini.py rename to playground/models/gemini_example.py diff --git a/playground/models/gpt4_v.py b/playground/models/gpt4_v_example.py similarity index 100% rename from playground/models/gpt4_v.py rename to playground/models/gpt4_v_example.py diff --git a/playground/models/huggingface.py b/playground/models/huggingface_example.py similarity index 100% rename from playground/models/huggingface.py rename to playground/models/huggingface_example.py diff --git a/playground/models/idefics.py b/playground/models/idefics_example.py similarity index 100% rename from playground/models/idefics.py rename to playground/models/idefics_example.py diff --git a/playground/models/jina_embeds.py b/playground/models/jina_embeds_example.py similarity index 100% rename from playground/models/jina_embeds.py rename to playground/models/jina_embeds_example.py diff --git a/playground/models/kosmos2.py b/playground/models/kosmos2_example.py similarity index 100% rename from playground/models/kosmos2.py rename to playground/models/kosmos2_example.py diff --git a/playground/models/kosmos.py b/playground/models/kosmos_example.py similarity index 100% rename from playground/models/kosmos.py rename to playground/models/kosmos_example.py diff --git a/playground/models/kosmos_two.py b/playground/models/kosmos_two_example.py similarity index 100% rename from playground/models/kosmos_two.py rename to playground/models/kosmos_two_example.py diff --git a/playground/models/layout_documentxlm.py b/playground/models/layout_documentxlm_example.py similarity index 100% rename from playground/models/layout_documentxlm.py rename to playground/models/layout_documentxlm_example.py diff --git a/playground/models/llama_function_caller.py b/playground/models/llama_function_caller_example.py similarity index 100% rename from playground/models/llama_function_caller.py rename to playground/models/llama_function_caller_example.py diff --git a/playground/models/llava.py b/playground/models/llava_example.py similarity index 100% rename from playground/models/llava.py rename to playground/models/llava_example.py diff --git a/playground/models/mistral.py b/playground/models/mistral_example.py similarity index 100% rename from playground/models/mistral.py rename to playground/models/mistral_example.py diff --git a/playground/models/mpt.py b/playground/models/mpt_example.py similarity index 100% rename from playground/models/mpt.py rename to playground/models/mpt_example.py diff --git a/playground/models/nougat.py b/playground/models/nougat_example.py similarity index 100% rename from playground/models/nougat.py rename to playground/models/nougat_example.py diff --git a/playground/models/openai_model.py b/playground/models/openai_model_example.py similarity index 100% rename from playground/models/openai_model.py rename to playground/models/openai_model_example.py diff --git a/playground/models/palm.py b/playground/models/palm_example.py similarity index 100% rename from playground/models/palm.py rename to playground/models/palm_example.py diff --git a/playground/models/speecht5.py b/playground/models/speecht5_example.py similarity index 100% rename from playground/models/speecht5.py rename to playground/models/speecht5_example.py diff --git a/playground/models/ssd.py b/playground/models/ssd_example.py similarity index 100% rename from playground/models/ssd.py rename to playground/models/ssd_example.py diff --git a/playground/models/tocr.py b/playground/models/tocr_example.py similarity index 100% rename from playground/models/tocr.py rename to playground/models/tocr_example.py diff --git a/playground/models/together.py b/playground/models/together_example.py similarity index 100% rename from playground/models/together.py rename to playground/models/together_example.py diff --git a/playground/models/tts_speech.py b/playground/models/tts_speech_example.py similarity index 100% rename from playground/models/tts_speech.py rename to playground/models/tts_speech_example.py diff --git a/playground/models/vilt.py b/playground/models/vilt_example.py similarity index 100% rename from playground/models/vilt.py rename to playground/models/vilt_example.py diff --git a/playground/models/yi_200k.py b/playground/models/yi_200k_example.py similarity index 100% rename from playground/models/yi_200k.py rename to playground/models/yi_200k_example.py diff --git a/playground/structs/agent_with_tools.py b/playground/structs/agent_with_tools_example.py similarity index 100% rename from playground/structs/agent_with_tools.py rename to playground/structs/agent_with_tools_example.py diff --git a/playground/structs/autoscaler.py b/playground/structs/autoscaler_example.py similarity index 100% rename from playground/structs/autoscaler.py rename to playground/structs/autoscaler_example.py diff --git a/playground/structs/chat.py b/playground/structs/chat_example.py similarity index 100% rename from playground/structs/chat.py rename to playground/structs/chat_example.py diff --git a/playground/structs/concurrent_workflow.py b/playground/structs/concurrent_workflow_example.py similarity index 100% rename from playground/structs/concurrent_workflow.py rename to playground/structs/concurrent_workflow_example.py diff --git a/playground/structs/debate.py b/playground/structs/debate_example.py similarity index 100% rename from playground/structs/debate.py rename to playground/structs/debate_example.py diff --git a/playground/structs/dialogue_simulator.py b/playground/structs/dialogue_simulator_example.py similarity index 100% rename from playground/structs/dialogue_simulator.py rename to playground/structs/dialogue_simulator_example.py diff --git a/playground/structs/flow.py b/playground/structs/flow_example.py similarity index 100% rename from playground/structs/flow.py rename to playground/structs/flow_example.py diff --git a/playground/structs/fuyu_flow.py b/playground/structs/fuyu_flow_example.py similarity index 100% rename from playground/structs/fuyu_flow.py rename to playground/structs/fuyu_flow_example.py diff --git a/playground/structs/godmode.py b/playground/structs/godmode_example.py similarity index 100% rename from playground/structs/godmode.py rename to playground/structs/godmode_example.py diff --git a/playground/structs/groupchat.py b/playground/structs/groupchat_example.py similarity index 100% rename from playground/structs/groupchat.py rename to playground/structs/groupchat_example.py diff --git a/playground/structs/gui_app.py b/playground/structs/gui_app_example.py similarity index 100% rename from playground/structs/gui_app.py rename to playground/structs/gui_app_example.py diff --git a/playground/structs/multi_agent_collab.py b/playground/structs/multi_agent_collab_example.py similarity index 100% rename from playground/structs/multi_agent_collab.py rename to playground/structs/multi_agent_collab_example.py diff --git a/playground/structs/multi_agent_debate.py b/playground/structs/multi_agent_debate_example.py similarity index 100% rename from playground/structs/multi_agent_debate.py rename to playground/structs/multi_agent_debate_example.py diff --git a/playground/structs/multi_modal_flow.py b/playground/structs/multi_modal_flow_example.py similarity index 100% rename from playground/structs/multi_modal_flow.py rename to playground/structs/multi_modal_flow_example.py diff --git a/playground/structs/nonlinear_worfklow.py b/playground/structs/nonlinear_worfklow_example.py similarity index 100% rename from playground/structs/nonlinear_worfklow.py rename to playground/structs/nonlinear_worfklow_example.py diff --git a/playground/structs/orchestrate.py b/playground/structs/orchestrate_example.py similarity index 100% rename from playground/structs/orchestrate.py rename to playground/structs/orchestrate_example.py diff --git a/playground/structs/orchestrator.py b/playground/structs/orchestrator_example.py similarity index 100% rename from playground/structs/orchestrator.py rename to playground/structs/orchestrator_example.py diff --git a/playground/structs/sequential_workflow.py b/playground/structs/sequential_workflow.py deleted file mode 100644 index 7fa110bc..00000000 --- a/playground/structs/sequential_workflow.py +++ /dev/null @@ -1,48 +0,0 @@ -from swarms import OpenAIChat, Agent, Task, SequentialWorkflow - -# Example usage -llm = OpenAIChat( - temperature=0.5, - max_tokens=3000, -) - -# Initialize the Agent with the language agent -agent1 = Agent( - agent_name="John the writer", - llm=llm, - max_loops=0, - dashboard=False, -) -task1 = Task( - agent=agent1, - description="Write a 1000 word blog about the future of AI", -) - -# Create another Agent for a different task -agent2 = Agent("Summarizer", llm=llm, max_loops=1, dashboard=False) -task2 = Task( - agent=agent2, - description="Summarize the generated blog", -) - -# Create the workflow -workflow = SequentialWorkflow( - name="Blog Generation Workflow", - description=( - "A workflow to generate and summarize a blog about the future" - " of AI" - ), - max_loops=1, - autosave=True, - dashboard=False, -) - -# Add tasks to the workflow -workflow.add(tasks=[task1, task2]) - -# Run the workflow -workflow.run() - -# # Output the results -# for task in workflow.tasks: -# print(f"Task: {task.description}, Result: {task.result}") diff --git a/playground/structs/sequential_workflow_example.py b/playground/structs/sequential_workflow_example.py index c36419c1..7fa110bc 100644 --- a/playground/structs/sequential_workflow_example.py +++ b/playground/structs/sequential_workflow_example.py @@ -1,52 +1,48 @@ -import os -from swarms.models import OpenAIChat -from swarms.structs import Agent -from swarms.structs.sequential_workflow import SequentialWorkflow -from dotenv import load_dotenv +from swarms import OpenAIChat, Agent, Task, SequentialWorkflow -load_dotenv() - -# Load the environment variables -api_key = os.getenv("OPENAI_API_KEY") - - -# Initialize the language agent -# Initialize the language model +# Example usage llm = OpenAIChat( temperature=0.5, - model_name="gpt-4", - openai_api_key=api_key, - max_tokens=4000, + max_tokens=3000, ) - -# Initialize the agent with the language agent +# Initialize the Agent with the language agent agent1 = Agent( + agent_name="John the writer", llm=llm, - max_loops=1, + max_loops=0, + dashboard=False, +) +task1 = Task( + agent=agent1, + description="Write a 1000 word blog about the future of AI", ) -# Create another agent for a different task -agent2 = Agent(llm=llm, max_loops=1) +# Create another Agent for a different task +agent2 = Agent("Summarizer", llm=llm, max_loops=1, dashboard=False) +task2 = Task( + agent=agent2, + description="Summarize the generated blog", +) # Create the workflow -workflow = SequentialWorkflow(max_loops=1) - -# Add tasks to the workflow -workflow.add( - agent1, - "Generate a 10,000 word blog on health and wellness.", +workflow = SequentialWorkflow( + name="Blog Generation Workflow", + description=( + "A workflow to generate and summarize a blog about the future" + " of AI" + ), + max_loops=1, + autosave=True, + dashboard=False, ) -# Suppose the next task takes the output of the first task as input -workflow.add( - agent2, - "Summarize the generated blog", -) +# Add tasks to the workflow +workflow.add(tasks=[task1, task2]) # Run the workflow workflow.run() -# Output the results -for task in workflow.tasks: - print(f"Task: {task.description}, Result: {task.result}") +# # Output the results +# for task in workflow.tasks: +# print(f"Task: {task.description}, Result: {task.result}") diff --git a/playground/structs/social_app.py b/playground/structs/social_app_example.py similarity index 100% rename from playground/structs/social_app.py rename to playground/structs/social_app_example.py diff --git a/playground/structs/swarm_network.py b/playground/structs/swarm_network_example.py similarity index 100% rename from playground/structs/swarm_network.py rename to playground/structs/swarm_network_example.py diff --git a/playground/structs/task.py b/playground/structs/task_example.py similarity index 100% rename from playground/structs/task.py rename to playground/structs/task_example.py diff --git a/playground/structs/todo_app.py b/playground/structs/todo_app_example.py similarity index 100% rename from playground/structs/todo_app.py rename to playground/structs/todo_app_example.py diff --git a/playground/structs/tool_utils.py b/playground/structs/tool_utils_example.py similarity index 100% rename from playground/structs/tool_utils.py rename to playground/structs/tool_utils_example.py diff --git a/playground/structs/workflow.py b/playground/structs/workflow_example.py similarity index 100% rename from playground/structs/workflow.py rename to playground/structs/workflow_example.py diff --git a/playground/tools/agent_with_tools.py b/playground/tools/agent_with_tools_example.py similarity index 100% rename from playground/tools/agent_with_tools.py rename to playground/tools/agent_with_tools_example.py diff --git a/playground/tools/tool_prompt_scaper.py b/playground/tools/tool_prompt_scaper_example.py similarity index 100% rename from playground/tools/tool_prompt_scaper.py rename to playground/tools/tool_prompt_scaper_example.py diff --git a/pyproject.toml b/pyproject.toml index fe88c5d6..bd198d14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "3.9.5" +version = "3.9.6" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] diff --git a/scripts/playground_to_examples.sh b/scripts/playground_to_examples.sh index c1ed0f61..a0ed5a96 100755 --- a/scripts/playground_to_examples.sh +++ b/scripts/playground_to_examples.sh @@ -1,13 +1,33 @@ #!/bin/bash -# Change to the root directory -cd / +# Define the directory to search +dir="playground" -# Iterate over all the .py files in the directory -for file in *.py; do - # Get the base name of the file without the .py - base_name=$(basename "$file" .py) +# Check if the directory exists +if [ -d "$dir" ] +then + # Use find to locate all .py files in the directory and its subdirectories + for file in $(find $dir -name "*.py") + do + # Extract the file name and directory + base=$(basename $file .py) + dir=$(dirname $file) - # Rename the file to remove .py from the end - mv "$file" "${base_name}" -done \ No newline at end of file + # Check if the file name already contains _example + if [[ $base == *_example ]] + then + echo "Skipping $file as it already contains _example" + continue + fi + + # Append _example to the file name + newname="${base}_example.py" + + # Rename the file + mv $file $dir/$newname + + echo "Renamed $file to $dir/$newname" + done +else + echo "Directory $dir does not exist." +fi \ No newline at end of file