File size: 521 Bytes
e63103b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import os
from langchain_backend.utils import create_prompt_llm_chain, create_retriever, getPDF
from langchain.chains import create_retrieval_chain

os.environ.get("OPENAI_API_KEY")

def get_llm_answer(system_prompt, user_prompt, pdf_url):
  pages = None
  if pdf_url:
    pages = getPDF(pdf_url)
  else:
    pages = getPDF()
  retriever = create_retriever(pages)
  rag_chain = create_retrieval_chain(retriever, create_prompt_llm_chain(system_prompt))
  results = rag_chain.invoke({"input": user_prompt})
  return results