Skip to content

Commit

Permalink
TUTORIAL60
Browse files Browse the repository at this point in the history
  • Loading branch information
ronidas39 committed May 7, 2024
1 parent 49fba18 commit 20934ae
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 2 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion tutorial2/single_url.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from langchain.document_loaders import youtube
import io

loader=youtube.YoutubeLoader.from_youtube_url("https://youtu.be/RiL-eLdGC9U")
loader=youtube.YoutubeLoader.from_youtube_url("https://youtu.be/3Qkkxp48284")
docs=loader.load()
print(docs)
with io.open("transcript.txt","w",encoding="utf-8")as f1:
Expand Down
2 changes: 1 addition & 1 deletion tutorial2/transcript.txt

Large diffs are not rendered by default.

Binary file modified tutorial58/tutorial58.pptx
Binary file not shown.
Binary file removed tutorial59/~$tutorial59.pptx
Binary file not shown.
Binary file not shown.
16 changes: 16 additions & 0 deletions tutorial60/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from langchain_community.document_loaders import PyPDFLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import Chroma
from langchain_openai import OpenAIEmbeddings
import os

loader=PyPDFLoader("vedas.pdf")
docs=loader.load()
text_splitter=RecursiveCharacterTextSplitter(chunk_size=1000,chunk_overlap=50)
chunked_documents=text_splitter.split_documents(docs)
vectordb=Chroma.from_documents(
documents=chunked_documents,
embedding=OpenAIEmbeddings(),
persist_directory=os.getcwd()+"/vector_index"
)
vectordb.persist()
19 changes: 19 additions & 0 deletions tutorial60/prompt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
You are very smart AI assistant who is very good in explaining and expressing answer for anything asked by the user
user will ask question as {question}
you must give answer with detailed explanation with bullets, heading , subheading etc. based on the {context} only
always rename the title ,headings, subheaing in your answer but keep the meaning same.
you must follow this very stricty , dont use anything else other than the given {context}
if no related information found from the {context} just reply with "I dont know", this is very important
answer:
"""


"""
You are very smart AI assistant who is very good in explaining and expressing answer for anything asked by the user
user will ask question as {question}
you must give answer with detailed explanation based on the {context} only
you must follow this very stricty , dont use anything else other than the given {context}
if no related information found from the {context} just reply with "I dont know", this is very important
answer:
"""
37 changes: 37 additions & 0 deletions tutorial60/rag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from langchain_community.vectorstores import Chroma
from langchain_openai import ChatOpenAI,OpenAIEmbeddings
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
import streamlit as st
import os
st.title("TALK TO ME")
st.write("promting example with rag")

vectordb=Chroma(persist_directory=os.getcwd()+"/vector_index",embedding_function=OpenAIEmbeddings())
prompt_template="""
You are very smart AI assistant who is very good in explaining and expressing answer for anything asked by the user
user will ask question as {question}
you must give answer with detailed explanation with bullets, heading , subheading etc. based on the {context} only
always rewrite the title ,headings, subheading in your ,try to avoid section numbers chapter numbers in the title or heading dont keep the same as the given in the {context} but keep the meaning same.
you must follow this very stricty , dont use anything else other than the given {context}
if no related information found from the {context} just reply with "I dont know", this is very important
answer:
answer:
"""
llm=ChatOpenAI(model="gpt-4-turbo",max_tokens=1024)
qa_chain=LLMChain(llm=llm,prompt=PromptTemplate.from_template(prompt_template))
question=st.text_area("ask your question")

if question is not None:
button=st.button("submit")
if button:
rd=vectordb.similarity_search(question,k=12)
context=""
for d in rd:
context +=d.page_content
response=qa_chain.invoke({"question":question,"context":context})
result=response["text"]
st.write(result)



Binary file added tutorial60/tutorial60.pptx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file added tutorial60/vector_index/chroma.sqlite3
Binary file not shown.
Binary file added tutorial60/vedas.pdf
Binary file not shown.
File renamed without changes.

0 comments on commit 20934ae

Please sign in to comment.