|
| 1 | +import os |
| 2 | +from crewai import Agent, Task, Crew, Process |
| 3 | +from langchain_community.llms import Ollama |
| 4 | +from notion_client import Client |
| 5 | +from langchain_community.utilities.google_search import GoogleSearchAPIWrapper |
| 6 | +from langchain.tools import DuckDuckGoSearchRun |
| 7 | + |
| 8 | +# Initialize the Notion client with your integration token |
| 9 | +notion = Client(auth="") # Replace with your Notion integration token |
| 10 | +database_id = "" # Replace with your database ID |
| 11 | +note_title = "Podcast Search Results" |
| 12 | + |
| 13 | +# Function to add a note to the database |
| 14 | +def add_note_to_database(database_id, title, content): |
| 15 | + new_page_data = { |
| 16 | + "parent": {"database_id": database_id}, |
| 17 | + "properties": { |
| 18 | + "Title": { |
| 19 | + "title": [ |
| 20 | + { |
| 21 | + "text": { |
| 22 | + "content": title |
| 23 | + } |
| 24 | + } |
| 25 | + ] |
| 26 | + } |
| 27 | + }, |
| 28 | + "children": [ |
| 29 | + { |
| 30 | + "object": "block", |
| 31 | + "type": "paragraph", |
| 32 | + "paragraph": { |
| 33 | + "rich_text": [ |
| 34 | + { |
| 35 | + "type": "text", |
| 36 | + "text": { |
| 37 | + "content": content |
| 38 | + } |
| 39 | + } |
| 40 | + ] |
| 41 | + } |
| 42 | + } |
| 43 | + ] |
| 44 | + } |
| 45 | + # Use the Notion SDK to create a new page in the database |
| 46 | + notion.pages.create(**new_page_data) |
| 47 | + |
| 48 | +# You can choose to use a local model through Ollama for example. |
| 49 | +# |
| 50 | +# from langchain.llms import Ollama |
| 51 | +ollama_llm = Ollama(model="openhermes") |
| 52 | + |
| 53 | +# Use DuckDuckGoSearchRun as a tool |
| 54 | +search_tool = DuckDuckGoSearchRun() |
| 55 | + |
| 56 | +# Define your agent with a role and a backstory |
| 57 | +podcast_finder = Agent( |
| 58 | + role='Podcast Curator', |
| 59 | + goal='Identify engaging and insightful podcasts across various genres for our listeners. These should not be the most popular podcasts that everyone already knows, but rather hidden gems that are worth discovering.', |
| 60 | + backstory="""As a Podcast Curator, you have a passion for audio storytelling and a keen ear for quality content. |
| 61 | + You have experience in sifting through numerous podcast episodes to find those that truly stand out in terms of |
| 62 | + content, production quality, and listener engagement. Your mission is to discover new and underappreciated podcasts |
| 63 | + as well as to keep up with the popular ones that set the trends. You understand the diverse interests of listeners |
| 64 | + and are adept at finding podcasts that cater to niche topics as well as those with broad appeal.""", |
| 65 | + verbose=True, |
| 66 | + allow_delegation=True, |
| 67 | + tools=[search_tool], |
| 68 | + llm=ollama_llm |
| 69 | + # You can pass an optional llm attribute specifying what mode you wanna use. |
| 70 | + # It can be a local model through Ollama / LM Studio or a remote |
| 71 | + # model like OpenAI, Mistral, Antrophic of others (https://python.langchain.com/docs/integrations/llms/) |
| 72 | + # |
| 73 | + # Examples: |
| 74 | + # llm=ollama_llm # was defined above in the file |
| 75 | + # llm=ChatOpenAI(model_name="gpt-3.5", temperature=0.7) |
| 76 | +) |
| 77 | + |
| 78 | +evaluator = Agent( |
| 79 | + role='Podcast Evaluator', |
| 80 | + goal='Assess the quality and relevance of podcasts found by the Podcast Curator.', |
| 81 | + backstory="""As a Podcast Evaluator, you have a critical ear and an eye for detail. You are skilled at analyzing listener feedback, |
| 82 | + assessing audio quality, and determining the uniqueness of content. Your role is to ensure that only the best podcasts make it to our |
| 83 | + recommended list.""", |
| 84 | + verbose=True, |
| 85 | + allow_delegation=True, |
| 86 | + llm=ollama_llm |
| 87 | +) |
| 88 | + |
| 89 | +summarizer = Agent( |
| 90 | + role='Content Summarizer', |
| 91 | + goal='Create concise summaries and highlights for each podcast.', |
| 92 | + backstory="""As a Content Summarizer, you have the ability to distill long audio content into engaging and informative summaries. |
| 93 | + Your summaries help listeners quickly understand what a podcast episode is about and why it might be of interest to them.""", |
| 94 | + verbose=True, |
| 95 | + allow_delegation=True, |
| 96 | + llm=ollama_llm |
| 97 | +) |
| 98 | + |
| 99 | +# Define tasks for the agents |
| 100 | +podcast_search_task = Task( |
| 101 | + description="Search for unique and engaging podcasts that are not widely known.", |
| 102 | + agent=podcast_finder |
| 103 | +) |
| 104 | + |
| 105 | +podcast_evaluate_task = Task( |
| 106 | + description="Evaluate the podcasts found for quality and relevance.", |
| 107 | + agent=evaluator |
| 108 | +) |
| 109 | + |
| 110 | +podcast_summarize_task = Task( |
| 111 | + description="Create concise summaries and highlights for the selected podcasts.", |
| 112 | + agent=summarizer |
| 113 | +) |
| 114 | + |
| 115 | +# Instantiate your crew with a sequential process |
| 116 | +# Note: The order of agents and tasks should align with the workflow |
| 117 | +crew = Crew( |
| 118 | + agents=[podcast_finder, evaluator, summarizer], |
| 119 | + tasks=[podcast_search_task, podcast_evaluate_task, podcast_summarize_task], |
| 120 | + verbose=2 # You can set it to 1 or 2 for different logging levels |
| 121 | +) |
| 122 | + |
| 123 | +# Get your crew to work! |
| 124 | +result = crew.kickoff() |
| 125 | + |
| 126 | +print("######################") |
| 127 | +print("Crew Results:") |
| 128 | +print(result) |
| 129 | + |
| 130 | +# Add the result to the database |
| 131 | +add_note_to_database(database_id, note_title, result) |
0 commit comments