-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebbase_loader.py
More file actions
31 lines (24 loc) · 922 Bytes
/
Copy pathwebbase_loader.py
File metadata and controls
31 lines (24 loc) · 922 Bytes
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
from langchain_community.document_loaders import WebBaseLoader
from bs4 import BeautifulSoup
from langchain_groq import ChatGroq
from dotenv import load_dotenv
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import PromptTemplate
from langchain.schema.runnable import RunnableSequence
import os
url='https://www.deathwishcoffee.com/?srsltid=AfmBOooKq0mAKywLJL-FAFtqCfVdMg1ZwDt6INxFcltDEWIyruvbKBxh'
loader=WebBaseLoader(url)
load_dotenv()
docs=loader.load()
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
llm= ChatGroq(
model='llama-3.3-70b-versatile'
)
parser=StrOutputParser()
prompt=PromptTemplate(
template='answer the following {question} from the text: {text}',
input_variables=["text", "question"],
)
chain=RunnableSequence(prompt, llm, parser)
final_result=chain.invoke({"text": docs[0].page_content, "question": "name of the darkest coffee"})
print(final_result)