File size: 1,249 Bytes
ba1cae1
 
 
 
 
 
 
 
 
 
 
4381bf9
ba1cae1
 
 
 
 
 
 
 
 
 
 
 
 
 
221b989
ba1cae1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langchain_google_genai import GoogleGenerativeAI
import requests
from bs4 import BeautifulSoup
from dotenv import load_dotenv
import os
load_dotenv()


class RAG:
    def __init__(self):
        self.url = 'https://lalitmahale.github.io'
        self.llm = GoogleGenerativeAI(google_api_key=os.getenv("GOOGLE_API"),model="gemini-pro")

    
    def get_data(self):
        try:
            res = requests.get(self.url)
            soup = BeautifulSoup(res.content, "html.parser")
            return soup.get_text()
        except Exception as e:
            print(e)

    def clean_text(self):
        return self.get_data().replace("\n","")

    def prompt(self):
        return """You are a helpfull assistant for me and Your name is lalit mahale. understand the below context and give answer for user question.
        
        context : {context}\n\nQuestion : {question}\n\nGive proper answer for this questions."""


    def pipeline(self,query):
        try:
            prompt = self.prompt().format(context = self.clean_text(),question = query)
            return self.llm.invoke(prompt)
        except Exception as e:
            print(e)
    

if __name__ == "__main__":
    res = RAG().pipeline("who is lalit mahale")
    print(res)