Skip to content

Commit

Permalink
add user_question
Browse files Browse the repository at this point in the history
  • Loading branch information
baejoonam-univ committed Jun 1, 2024
1 parent 5741f36 commit aee8972
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
9 changes: 3 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)

@app.post("/ocr")
def get(image_file: UploadFile = File(...), is_landlord: str = Form("0")):
def get(image_file: UploadFile = File(...), is_landlord: str = Form("0"), user_question: str = Form("")):
image_files = [image_file]

file_extension = get_file_extension(image_file.filename)
Expand All @@ -22,9 +22,9 @@ def get(image_file: UploadFile = File(...), is_landlord: str = Form("0")):

texts = [get_text(image_file) for image_file in image_files]
text = '\n\n'.join(texts)
response = get_response(text, is_landlord)

return response
response = get_rag_response(text, is_landlord, user_question)
return {"result": response}

def get_file_extension(filename):
_, file_extension = os.path.splitext(filename)
Expand Down Expand Up @@ -88,8 +88,5 @@ def get_text(image_file):

return text

def get_response(contract, is_landlord):
return get_rag_response(contract, is_landlord)

# uvicorn main:app --host 0.0.0.0 --port 8000
# http://localhost:8000/docs
11 changes: 7 additions & 4 deletions rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@
"contract": RunnablePassthrough()
} | non_landlord_prompt | llm | StrOutputParser()

def get_rag_response(contract, is_landlord):
print(retriever.get_relevant_documents(contract))
def get_rag_response(contract, is_landlord, user_question):
input = contract

if user_question != "":
input += "\n\n응답을 마친 후 다음 질문에 대해서도 답해주세요:" + user_question

if is_landlord == "1":
return landlord_chain.invoke(contract)
return non_landlord_chain.invoke(contract)
return landlord_chain.invoke(input)
return non_landlord_chain.invoke(input)

0 comments on commit aee8972

Please sign in to comment.