File size: 1,727 Bytes
7945f21
a3039c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7945f21
a3039c8
 
 
7945f21
 
 
a3039c8
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
import gradio as gr
from composio_crewai import ComposioToolSet, App, Action
from crewai import Agent, Task, Crew, Process
from langchain_openai import ChatOpenAI
from dotenv import load_dotenv
import os

load_dotenv()

llm = ChatOpenAI(model="gpt-4")

toolset = ComposioToolSet()
tools = toolset.get_tools(apps=[App.SERPAPI, App.WEBTOOL])

def find_hackernews_posts(message):
    profile = message

    hacnews_agent = Agent(
        role="Technical Researcher",
        goal="Find the best technical posts on Hackernews",
        backstory="You are a technical person who loves reading Hackernews and looking for technical posts. You spend all your time looking for interesting posts of the day.",
        llm=llm,
        tools=tools
    )

    hacnews_task = Task(
        description=f"""
            Use the serp tool to search for the user's twitter profile of name {profile} to read his bio, 
            and then scrape it. Based on his bio, find good technical hackernews posts suited to his bio.
        """,
        expected_output="A list of technical hackernews posts printed",
        agent=hacnews_agent,
        tools=tools
    )

    crew = Crew(
        agents=[hacnews_agent],
        tasks=[hacnews_task],
        process=Process.sequential,
        verbose=True
    )

    result = crew.kickoff()
    return result

chat_interface = gr.ChatInterface(
    fn=find_hackernews_posts,
    title="HackerNews Post Finder",
    description="Enter a Twitter username to find relevant technical HackerNews posts.",
    examples=[
        ["elonmusk"],
        ["naval"],
        ["paulg"]
    ],
    retry_btn=None,
    undo_btn=None,
    clear_btn="Clear"
)

if __name__ == "__main__":
    chat_interface.launch()