aboutsummaryrefslogtreecommitdiff
path: root/tools/summarize.py
blob: d90c49d97e0bd4a7d51e9dda2c3ebc23dac5bc4b (plain)
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
import logging
import asyncio 
import os
from langchain.agents import tool
from dotenv import load_dotenv

from langchain.agents.agent_toolkits import GmailToolkit

from langchain.llms import OpenAI
from langchain.agents import initialize_agent, AgentType

load_dotenv()
toolkit = GmailToolkit()

tools = toolkit.get_tools()

@tool("summarize")
def summarize(input: str) -> bool:
    """
    Summarize the response to the input prompt.
    """
    prompt = input

    llm = OpenAI(temperature=0)
    agent = initialize_agent(
        prompt=prompt,
        llm=llm,
        agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
    )

    return agent.run(prompt)