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

137 lines
2.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""
Swarm Agent
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.
Distribution Agent:
- Social Media posts for the article.
# TODO
- Make prompts better
- Add shorter and better topic generator prompt
- Optimize writer prompt to create longer and more enjoyeable blogs
- Use Local Models like Storywriter
"""
import os
from termcolor import colored
from swarms.models import OpenAIChat
from swarms.prompts.autobloggen import (
AUTOBLOG_REVIEW_PROMPT,
DRAFT_AGENT_SYSTEM_PROMPT,
SOCIAL_MEDIA_SYSTEM_PROMPT_AGENT,
TOPIC_GENERATOR_SYSTEM_PROMPT,
)
api_key = os.environ["OPENAI_API_KEY"]
llm = OpenAIChat(openai_api_key=api_key)
def get_review_prompt(article):
prompt = AUTOBLOG_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
# Agent that generates topics
topic_selection_task = (
"Generate 10 topics on gaining mental clarity using ancient"
" practices"
)
topics = llm(
f"Your System Instructions: {TOPIC_GENERATOR_SYSTEM_PROMPT}, Your"
f" current task: {topic_selection_task}"
)
dashboard = print(
colored(
f"""
Topic Selection Agent
-----------------------------
Topics:
------------------------
{topics}
""",
"blue",
)
)
draft_blog = llm(DRAFT_AGENT_SYSTEM_PROMPT)
draft_out = print(
colored(
f"""
------------------------------------
Drafter Writer Agent
-----------------------------
Draft:
------------------------
{draft_blog}
""",
"red",
)
)
# 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",
)
)
# Agent that publishes on social media
distribution_agent = llm(
social_media_prompt(draft_blog, goal="Clicks and engagement")
)
distribution_agent_out = print(
colored(
f"""
--------------------------------
Distribution Agent
-------------------
Social Media Posts
-------------------
{distribution_agent}
""",
"magenta",
)
)