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/demos/positive_med.py

128 lines
2.7 KiB

"""
1 year ago
Swarm Flow
1 year ago
Topic selection agent -> draft agent -> review agent -> distribution agent
Topic Selection Agent:
- Generate 10 topics on gaining mental clarity using Taosim and Christian meditation
Draft Agent:
- Write a 100% unique, creative and in human-like style article of a minimum of 5,000 words using headings and sub-headings.
Review Agent:
- Refine the article to meet PositiveMeds stringent publication standards.
1 year ago
Distribution Agent:
1 year ago
- Social Media posts for the article.
# TODO
- Add shorter and better topic generator prompt
- Optimize writer prompt to create longer and more enjoyeable blogs
- Use Local Models like Storywriter
"""
1 year ago
from termcolor import colored
from swarms.models import OpenAIChat
from swarms.prompts.autoblogen import (
DRAFT_AGENT_SYSTEM_PROMPT,
REVIEW_PROMPT,
SOCIAL_MEDIA_SYSTEM_PROMPT_AGENT,
TOPIC_GENERATOR,
)
import os
1 year ago
api_key = os.environ["OPENAI_API_KEY"]
llm = OpenAIChat(openai_api_key=api_key)
1 year ago
1 year ago
1 year ago
def get_review_prompt(article):
prompt = REVIEW_PROMPT.replace("{{ARTICLE}}", article)
return prompt
def social_media_prompt(article: str, goal: str = "Clicks and engagement"):
prompt = SOCIAL_MEDIA_SYSTEM_PROMPT_AGENT.replace("{{ARTICLE}}", article).replace(
"{{GOAL}}", goal
)
return prompt
1 year ago
# Agent that generates topics
1 year ago
topic_selection_task = (
"Generate 10 topics on gaining mental clarity using ancient practices"
1 year ago
)
topics = llm(
1 year ago
f"Your System Instructions: {TOPIC_GENERATOR}, Your current task: {topic_selection_task}"
)
1 year ago
dashboard = print(
colored(
f"""
Topic Selection Agent
-----------------------------
Topics:
------------------------
{topics}
1 year ago
""",
"blue",
)
)
draft_blog = llm(DRAFT_AGENT_SYSTEM_PROMPT)
1 year ago
draft_out = print(
colored(
f"""
------------------------------------
1 year ago
Drafter Writer Agent
-----------------------------
Draft:
------------------------
{draft_blog}
1 year ago
""",
"red",
1 year ago
)
)
# Agent that reviews the draft
review_agent = llm(get_review_prompt(draft_blog))
reviewed_draft = print(
colored(
f"""
------------------------------------
Quality Assurance Writer Agent
-----------------------------
Complete Narrative:
------------------------
{draft_blog}
""",
"blue",
)
)
1 year ago
# Agent that publishes on social media
1 year ago
distribution_agent = llm(social_media_prompt(draft_blog, goal="Clicks and engagement"))
1 year ago
distribution_agent_out = print(
colored(
f"""
--------------------------------
1 year ago
Distribution Agent
-------------------
Social Media Posts
-------------------
{distribution_agent}
1 year ago
""",
"magenta",
1 year ago
)
1 year ago
)