File size: 2,996 Bytes
7a67c6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from crewai import Agent, Task, Crew, Process
from langchain_google_genai import ChatGoogleGenerativeAI
from crewai_tools import SerperDevTool
import os
from langchain_community.utilities import GoogleSerperAPIWrapper
from langchain_community.tools import DuckDuckGoSearchRun
from langchain_openai import OpenAI
from langchain.agents import initialize_agent, Tool
from crewai_tools import tool
import gradio as gr


@tool('DuckDuckGoSearch')
def search(search_query: str):
    """Search the web for information on a given topic"""
    return DuckDuckGoSearchRun().run(search_query)



llm = ChatGoogleGenerativeAI(
        model="gemini-pro", verbose=True, temperature=0.1, google_api_key=os.getenv('GOOGLE_API_KEY')
    )

search = DuckDuckGoSearchRun()
@tool('DuckDuckGoSearch')
def search(search_query: str):
    """Search the web for information on a given topic"""
    return DuckDuckGoSearchRun(max_results=5).run(search_query)

SerpBot = Agent(
  role='Search Expert',
  goal=' You find all the information that the Writer requests you to find. Then you compile it and give it back to him.',
  backstory="""
  You are an agent that uses SERP in the best way to search for the input query. Action input
  is the following format: {"search_query"="input text"}
  """,
  verbose=True,
  tools=[search],
  llm=llm
)

Writer = Agent(
      role='Expert Writer',
      goal='Write engaging, well written articles with a pinch of humour',
      backstory="""
      A seasoned funny writer who writes about the latest news on that topic and 
      can convert boring information to amazing articles that everyone loves reading.
      Your articles have a satirical tone and the humour is based on real life events
      """,
      verbose=True,
      allow_delegation=True,
      tools=[search],
      llm=llm
)

def get_human_input(input):
    """Get the human input for the search query"""
    human_input = input
    return human_input

def create_task(human_input):
    """Create a task based on the human input"""
    task1 = Task(
        description=f"Write a newsletter based on the following topics: +{human_input}. Research on topic separately and write detailed articles about them",
        agent = Writer,
        human_feedback=True,
        expected_output="When the entire newsletter is generated",
    )
    return task1

def create_crew(task):
    """Create a crew with the task and agents"""
    story_crew = Crew(
        agents=[SerpBot, Writer],
        tasks=[task],
        verbose=True,
        process=Process.sequential,
    )
    return story_crew

def kickoff_crew(story_crew):
    """Kick off the crew"""
    story_output = story_crew.kickoff()
    return story_output

def response(input,history=[]):
    human_input = get_human_input(input)
    task = create_task(human_input)
    story_crew = create_crew(task)
    res = kickoff_crew(story_crew)
    return res


#story_output = kickoff_crew(story_crew)
gr.ChatInterface(response).launch(share=True, debug=True)