File size: 9,057 Bytes
31fd2e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from crewai import Agent, Task
from tools import scrape_website, generate_images_and_add_to_blog, generate_video
# from langchain_groq import ChatGroq
from langchain_openai import ChatOpenAI
from utils import post_image_and_text

def get_agents_and_tasks(is_token):

    # llm = ChatGroq(model="llama3-70b-8192", api_key=groq_api_key)
    llm = ChatOpenAI(model='gpt-4o-mini')    

    information_retriever_agent = Agent(
        role="Web Information Retriever",
        goal="To retieve all the information from the website and summarize the information.",
        backstory="You are web information retriever agent. You are expert in scraping websites and summarizing the content.",
        verbose=True,
        llm=llm,
        allow_delegation=False
    )

    task_scrape = Task(
        description="Scrape all the informatin from the website: {website}.",
        expected_output="Scraped information from the website: {website}",
        agent=information_retriever_agent,
        tools=[scrape_website]
    )

    task_summarize = Task(
        description="provide a neet summary of the company. Do not add up things. ",
        expected_output="Detailed summary of a company web page. "
        # "Start with Company name, Mission and Vision, Leadership. "
        # "Explain it's Products and Services, Market presence, Financial highlights, Recent Developments and Future plans. "
        # "If there are not mentioned, explain they have mentioned."
        "Do not add up things.",
        agent=information_retriever_agent,
        context=[task_scrape]
    )

    blog_agent = Agent(
        role="Blog Writer",
        goal="Create captivating blog that inspire and educate readers.",
        backstory="You are a skilled blog writer for a company, creating insightful and engaging blog posts on various topics. You have a passion for sharing knowledge through writing. With years of experience in the industry, you know how to craft compelling narratives and provide valuable insights to your audience.",
        verbose=True,
        llm=llm,
        allow_delegation=False
    )

    task_create_blog = Task(
    description=
        "Write a compelling blog on the topic '{topic}' for the company."
        "Begin by explaining the topic, followed by an introduction to the company. Do not add up things. "
        # "In the second half of blog, include a brief mention of the company to highlight its relevance to the topic. "
        "The blog should cover various aspects relevant to {topic}, ensuring it provides comprehensive insights and value to the readers. "
        "The blog should contain 2 image, so insert '<-IMAGE->' where image has to be inserted. One image should be after first paragraph. "
        "The blog should not contain author details.",
    expected_output="A full engaging and informative blog post about the topic: '{topic}'",
    # output_file="topic_blog_post.md",
    agent=blog_agent,
    context=[task_summarize]
    )

    task_visual_prompts = Task(
        description = "Replace <-IMAGE-> with prompts.There should be 2 images in the blog. "
        "Every prompt should be enclosed in '<image> prompt </image>' tag. "
        "The image should not contain any form of text, names of persons, company or company logo, etc.  "
        "Prompt is 'What you wish to see in the output image'. "
        "A descriptive prompt that clearly defines elements, colors, and subjects will lead to better results. "
        # "To control the weight of a given word use the format (word:weight), where word is the word you'd like to control the weight of and weight is a value between 0 and 1. "
        "For example: The sky was a crisp (blue:0.3) and (green:0.8) would convey a sky that was blue and green, but more green than blue. The weight applies to all words in the prompt. ",
        # "Image should not contain names of persons, company or company logo, etc. ",
        expected_output= "A full blog with prompts enclosed in '<image> prompt </image>' tag.",
        agent = blog_agent,
        context = [task_create_blog]
    )

    task_add_images = Task(
        description = "Generate images and add to blog using the provided tool. If image generation fails, stop the execution.",
        expected_output= "A full blog with images.",
        agent = blog_agent,
        # output_file="blog_post.md",
        tools = [generate_images_and_add_to_blog],
        context = [task_visual_prompts]
    )

    content_creation_agent = Agent(
        role="Content Creator",
        goal="To generate accurate and engaging narration and image prompt pairs for video scripts and subsequently generate videos using these pairs.",
        backstory="The agent is designed to assist in creating engaging video content by generating narrations and image prompts, and then compiling them into videos.",
        verbose=True,
        llm=llm,
        allow_delegation=False
    )

    # task_summarize_blog = Task(
    #     description = "Summarize the blog into two to three paragraphs.",
    #     #   focusing on the topic: '{topic}'. "
    #     #  "Ensure the summary is concise yet comprehensive, capturing the essence of the '{topic}' and its significance. ",
    #     expected_output = "Two to three paragraphs of summary of the blog, mainly focussed on '{topic}'. ",
    #     agent = content_creation_agent,
    #     context = [task_visual_prompts]
    # )

    # task_video_script = Task(
    #     description = "Write a script for video about the topic: {topic}. Remember to use context as just reference, do not use context as script.",
    #     expected_output = "Two to three paragraphs of script for the video, mainly focussed on '{topic}'. ",
    #     agent = content_creation_agent,
    #     context = [task_visual_prompts]
    # )

    task_generate_narration_image_pairs = Task(
    description = "Generate narration and image prompt pairs for video script about the topic: '{topic}'. The number of pairs are limited to two. Total words in narration should be less than 100."
    "Image should not contain any form of text, names of persons, company or company logo, etc. "
    "Prompt is 'What you wish to see in the output image'. "
    "A descriptive prompt that clearly defines elements, colors, and subjects will lead to better results. "
    "To control the weight of a given word use the format (word:weight), where word is the word you'd like to control the weight of and weight is a value between 0 and 1. "
    "For example: The sky was a crisp (blue:0.3) and (green:0.8) would convey a sky that was blue and green, but more green than blue. The weight applies to all words in the prompt. ",
    # "Image should not contain names of persons, company or company logo, etc. ",
    expected_output="Pairs of sentences. Narrations are enclosed in <narration> narration here </narration> tag. Image prompts are enclosed in <image> image prompt here </image> tag.",
    agent=content_creation_agent,
    # context = [task_video_script]
    )

    task_generate_video = Task(
        description="Generate video using narration and image prompt pairs. If image generation fails, stop the execution.",
        expected_output="Path of the video",
        agent=content_creation_agent,
        context = [task_generate_narration_image_pairs],
        tools=[generate_video]
    )

    LinkedInPosterAgent = Agent(
    role="LinkedIn Poster",
    goal="To post articles on LinkedIn",
    backstory="This agent is responsible for automating the posting of articles on LinkedIn to keep the profile active and engaging.",
    verbose=True,
    llm=llm,
    allow_delegation=False
    )

    BlogtoArticle = Task(
        description="Convert the blog into engaging LinkedIn post of 150 words. " 
        "Make the post attractive using emojis and symbols ."
        "Use one image from blog for LinkedIn post",
        expected_output="A dictionary containing image_path, post_content. ",
        agent=LinkedInPosterAgent,
        context = [task_add_images]
    )

    PostArticleToLinkedIn = Task(
        description="""post article on LinkedIn.

        token:

        {token}
        
        """,
        expected_output="A confirmation that the article was successfully posted on LinkedIn.",
        agent=LinkedInPosterAgent,
        context = [BlogtoArticle],
        tools=[post_image_and_text]
    )

    agents = [
              information_retriever_agent, 
              blog_agent, 
              content_creation_agent,
              ]
    
    tasks = [
             task_scrape, 
             task_summarize, 
             task_create_blog,
             task_visual_prompts, 
             task_add_images, 
            # task_summarize_blog,
            # task_video_script,
             task_generate_narration_image_pairs, 
             task_generate_video,
             
            ]
    
    if is_token:
        agents.append(LinkedInPosterAgent)
        tasks.append(BlogtoArticle)
        tasks.append(PostArticleToLinkedIn)
    
    return agents, tasks