File size: 1,055 Bytes
1842d77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langchain_groq import ChatGroq
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain.tools import Tool
import os

# summeriser
GROQ_API_KEY = os.getenv("GROQ_API_KEY")

if not GROQ_API_KEY:
    raise ValueError("GROQ_API_KEY environment variable is not set.")

# Initialize ChatGroq for summarization
summarizer_llm = ChatGroq(
    temperature=0.7,
    model="llama3-8b-8192",
    api_key=GROQ_API_KEY,
    streaming=True,
    verbose=True
)

# Define a prompt template for summarization
summarization_prompt = PromptTemplate(
    input_variables=["text"],
    template="Summarize the following content: {text}"
)

# Create the summarization chain
summarization_chain = LLMChain(
    llm=summarizer_llm,
    prompt=summarization_prompt
)

# Define the summarizer tool
def summarize_content_tool(text: str) -> str:
    return summarization_chain.run(text=text)

summarizer_tool = Tool(
    name="summarizer",
    description="Summarizes content using a language model.",
    func=summarize_content_tool
)