Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request to merge the following minor improvements: #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions langchain_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@


load_dotenv()
embeddings = OpenAIEmbeddings()


def create_db_from_youtube_video_url(video_url: str) -> FAISS:
def create_db_from_youtube_video_url(video_url: str,openai_api_key) -> FAISS:
loader = YoutubeLoader.from_youtube_url(video_url)
transcript = loader.load()

text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
docs = text_splitter.split_documents(transcript)

embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
db = FAISS.from_documents(docs, embeddings)
return db


def get_response_from_query(db, query, k=4):
def get_response_from_query(db, query, openai_api_key, k=4):
"""
text-davinci-003 can handle up to 4097 tokens. Setting the chunksize to 1000 and k to 4 maximizes
the number of tokens to analyze.
Expand All @@ -32,7 +32,7 @@ def get_response_from_query(db, query, k=4):
docs = db.similarity_search(query, k=k)
docs_page_content = " ".join([d.page_content for d in docs])

llm = OpenAI(model_name="text-davinci-003")
llm = OpenAI(model_name="text-davinci-003",openai_api_key=openai_api_key)

prompt = PromptTemplate(
input_variables=["question", "docs"],
Expand Down
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
with st.form(key='my_form'):
youtube_url = st.sidebar.text_area(
label="What is the YouTube video URL?",
max_chars=50
max_chars=150
)
query = st.sidebar.text_area(
label="Ask me about the video?",
Expand All @@ -18,7 +18,7 @@
openai_api_key = st.sidebar.text_input(
label="OpenAI API Key",
key="langchain_search_api_key_openai",
max_chars=50,
max_chars=150,
type="password"
)
"[Get an OpenAI API key](https://platform.openai.com/account/api-keys)"
Expand All @@ -30,7 +30,7 @@
st.info("Please add your OpenAI API key to continue.")
st.stop()
else:
db = lch.create_db_from_youtube_video_url(youtube_url)
response, docs = lch.get_response_from_query(db, query)
db = lch.create_db_from_youtube_video_url(youtube_url,openai_api_key)
response, docs = lch.get_response_from_query(db, query,openai_api_key)
st.subheader("Answer:")
st.text(textwrap.fill(response, width=85))