File size: 797 Bytes
e63103b
 
 
 
 
 
3b3d8b9
7d2e972
e63103b
 
 
 
 
 
1a93363
 
 
 
 
 
e63103b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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, model):
  print('model: ', model)
  pages = None
  if pdf_url:
    pages = getPDF(pdf_url)
  else:
    pages = getPDF()
  retriever = create_retriever(pages)
  # rag_chain = None
  rag_chain = create_retrieval_chain(retriever, create_prompt_llm_chain(system_prompt, model))
  # if model:
    # rag_chain = create_retrieval_chain(retriever, create_prompt_llm_chain(system_prompt, model))
  # else:
    # rag_chain = create_retrieval_chain(retriever, create_prompt_llm_chain(system_prompt))
  results = rag_chain.invoke({"input": user_prompt})
  return results