Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
manthanguptaa committed Dec 24, 2024
1 parent 97a260e commit 9371e9c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

TYPEFULLY_API_URL = "https://api.typefully.com/v1/drafts/"
TYPEFULLY_API_KEY = os.getenv("TYPEFULLY_API_KEY")
HEADERS = {
"X-API-KEY": f"Bearer {TYPEFULLY_API_KEY}"
}
HEADERS = {"X-API-KEY": f"Bearer {TYPEFULLY_API_KEY}"}


# Define the enums
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@
"and business leaders while maintaining technical accuracy.\n\n"
),
"expected_output": (
"A LinkedIn post plan containing:\n"
"- content\n"
"- a main blog URL that is associated with the post\n\n"
"A LinkedIn post plan containing:\n" "- content\n" "- a main blog URL that is associated with the post\n\n"
),
},
}
44 changes: 20 additions & 24 deletions cookbook/examples/workflows/content_creator_workflow/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@

def json_to_typefully_content(thread_json: Dict[str, Any]) -> str:
"""Convert JSON thread format to Typefully's format with 4 newlines between tweets."""
tweets = thread_json['tweets']
tweets = thread_json["tweets"]
formatted_tweets = []
for tweet in tweets:
tweet_text = tweet['content']
if 'media_urls' in tweet and tweet['media_urls']:
tweet_text = tweet["content"]
if "media_urls" in tweet and tweet["media_urls"]:
tweet_text += f"\n{tweet['media_urls'][0]}"
formatted_tweets.append(tweet_text)

return '\n\n\n\n'.join(formatted_tweets)
return "\n\n\n\n".join(formatted_tweets)


def json_to_linkedin_content(thread_json: Dict[str, Any]) -> str:
"""Convert JSON thread format to Typefully's format."""
content = thread_json['content']
if 'url' in thread_json and thread_json['url']:
content = thread_json["content"]
if "url" in thread_json and thread_json["url"]:
content += f"\n{thread_json['url']}"
return content


def schedule_thread(
content: str,
schedule_date: str = "next-free-slot",
threadify: bool = False,
share: bool = False,
auto_retweet_enabled: bool = False,
auto_plug_enabled: bool = False
content: str,
schedule_date: str = "next-free-slot",
threadify: bool = False,
share: bool = False,
auto_retweet_enabled: bool = False,
auto_plug_enabled: bool = False,
) -> Optional[Dict[str, Any]]:
"""Schedule a thread on Typefully."""
payload = {
Expand All @@ -46,7 +46,7 @@ def schedule_thread(
"threadify": threadify,
"share": share,
"auto_retweet_enabled": auto_retweet_enabled,
"auto_plug_enabled": auto_plug_enabled
"auto_plug_enabled": auto_plug_enabled,
}

payload = {key: value for key, value in payload.items() if value is not None}
Expand All @@ -61,11 +61,11 @@ def schedule_thread(


def schedule(
thread_model: BaseModel,
hours_from_now: int = 1,
threadify: bool = False,
share: bool = True,
post_type: PostType = PostType.TWITTER
thread_model: BaseModel,
hours_from_now: int = 1,
threadify: bool = False,
share: bool = True,
post_type: PostType = PostType.TWITTER,
) -> Optional[Dict[str, Any]]:
"""
Schedule a thread from a Pydantic model.
Expand All @@ -91,16 +91,12 @@ def schedule(
thread_content = json_to_linkedin_content(thread_json)

# Calculate schedule time
schedule_date = (datetime.datetime.utcnow() +
datetime.timedelta(hours=hours_from_now)).isoformat() + "Z"
schedule_date = (datetime.datetime.utcnow() + datetime.timedelta(hours=hours_from_now)).isoformat() + "Z"

if thread_content:
# Schedule the thread
response = schedule_thread(
content=thread_content,
schedule_date=schedule_date,
threadify=threadify,
share=share
content=thread_content, schedule_date=schedule_date, threadify=threadify, share=share
)

if response:
Expand Down
16 changes: 11 additions & 5 deletions cookbook/examples/workflows/content_creator_workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class BlogAnalyzer(BaseModel):
Represents the response from the Blog Analyzer agent.
Includes the blog title and content in Markdown format.
"""

title: str
blog_content_markdown: str

Expand All @@ -31,6 +32,7 @@ class Tweet(BaseModel):
"""
Represents an individual tweet within a Twitter thread.
"""

content: str
is_hook: bool = False # Marks if this tweet is the "hook" (first tweet)
media_urls: Optional[List[str]] = [] # Associated media URLs, if any
Expand All @@ -40,6 +42,7 @@ class Thread(BaseModel):
"""
Represents a complete Twitter thread containing multiple tweets.
"""

topic: str
tweets: List[Tweet]

Expand All @@ -48,6 +51,7 @@ class LinkedInPost(BaseModel):
"""
Represents a LinkedIn post.
"""

content: str
media_url: Optional[str] = None # Optional media attachment URL

Expand All @@ -59,6 +63,7 @@ class ContentPlanningWorkflow(Workflow):
2. Generating a content plan for either Twitter or LinkedIn based on the scraped content.
3. Scheduling and publishing the planned content.
"""

# This description is used only in workflow UI
description: str = "Plan, schedule, and publish social media content based on a blog post."

Expand All @@ -69,7 +74,7 @@ class ContentPlanningWorkflow(Workflow):
description=f"{agents_config['blog_analyzer']['role']} - {agents_config['blog_analyzer']['goal']}",
instructions=[
f"{agents_config['blog_analyzer']['backstory']}",
tasks_config['analyze_blog']['description'], # Task-specific instructions for blog analysis
tasks_config["analyze_blog"]["description"], # Task-specific instructions for blog analysis
],
response_model=BlogAnalyzer, # Expects response to follow the BlogAnalyzer Pydantic model
)
Expand All @@ -81,7 +86,7 @@ class ContentPlanningWorkflow(Workflow):
description=f"{agents_config['twitter_thread_planner']['role']} - {agents_config['twitter_thread_planner']['goal']}",
instructions=[
f"{agents_config['twitter_thread_planner']['backstory']}",
tasks_config['create_twitter_thread_plan']['description'],
tasks_config["create_twitter_thread_plan"]["description"],
],
response_model=Thread, # Expects response to follow the Thread Pydantic model
)
Expand All @@ -93,7 +98,7 @@ class ContentPlanningWorkflow(Workflow):
description=f"{agents_config['linkedin_post_planner']['role']} - {agents_config['linkedin_post_planner']['goal']}",
instructions=[
f"{agents_config['linkedin_post_planner']['backstory']}",
tasks_config['create_linkedin_post_plan']['description'],
tasks_config["create_linkedin_post_plan"]["description"],
],
response_model=LinkedInPost, # Expects response to follow the LinkedInPost Pydantic model
)
Expand Down Expand Up @@ -174,6 +179,7 @@ def run(self, blog_post_url, post_type) -> RunResponse:
# Initialize and run the workflow
blogpost_url = "https://blog.dailydoseofds.com/p/5-chunking-strategies-for-rag"
workflow = ContentPlanningWorkflow()
response = workflow.run(blog_post_url=blogpost_url, post_type=PostType.TWITTER) # PostType.LINKEDIN for LinkedIn post
response = workflow.run(
blog_post_url=blogpost_url, post_type=PostType.TWITTER
) # PostType.LINKEDIN for LinkedIn post
logger.info(response.content)

0 comments on commit 9371e9c

Please sign in to comment.