feat: Set temperature when working with OpenAI

feat: Store chat in a chat archive which persists between sessions
pull/13/head
namuan 1 year ago
parent cb37d995b5
commit 63cfd1c21b

@ -8,6 +8,7 @@ from py_executable_checklist.workflow import run_workflow
from doc_search.workflow import (
inference_workflow_steps,
pdf_name_from,
pdf_to_chat_archive_path,
pdf_to_faiss_db_path,
pdf_to_index_path,
)
@ -20,7 +21,7 @@ panel_conversations = [] # store all panel objects in a list
global_context = {} # store workflow context
def add_qa_to_panel(question: str, answer: str) -> None:
def add_qa_to_panel(question: str, answer: str) -> str:
qa_block = f"""
🙂 **{question}**
@ -38,6 +39,7 @@ def add_qa_to_panel(question: str, answer: str) -> None:
),
)
)
return qa_block
def get_conversations(_: Any) -> pn.Column:
@ -48,7 +50,9 @@ def get_conversations(_: Any) -> pn.Column:
run_workflow(global_context, inference_workflow_steps())
openai_answer = global_context["output"]
logging.info("Answer: %s", openai_answer)
add_qa_to_panel(input_question, openai_answer)
qa_block = add_qa_to_panel(input_question, openai_answer)
with open(global_context["archive_file"], "a") as f:
f.write(qa_block)
txt_input.value_input = ""
return pn.Column(*(reversed(panel_conversations)))
@ -61,6 +65,7 @@ def run_web(context: dict) -> None:
global global_context
context["index_path"] = pdf_to_index_path(context["app_dir"], context["input_pdf_path"])
context["faiss_db"] = pdf_to_faiss_db_path(context["app_dir"], context["input_pdf_path"])
context["archive_file"] = pdf_to_chat_archive_path(context["app_dir"], context["input_pdf_path"])
global_context = context
interactive_conversation = pn.bind(get_conversations, btn_ask)

@ -66,6 +66,12 @@ def pdf_to_index_path(app_dir: Path, input_pdf_path: Path) -> Path:
return output_dir / "docsearch.index"
def pdf_to_chat_archive_path(app_dir: Path, input_pdf_path: Path) -> Path:
output_dir = output_directory_for_pdf(app_dir, input_pdf_path) / "chat"
output_dir.mkdir(parents=True, exist_ok=True)
return output_dir / "archive.md"
class VerifyInputFile(WorkflowBase):
"""
Verify input file and return pdf stats
@ -269,7 +275,7 @@ ${question}
)
return HuggingFacePipeline(pipeline=pipe)
else:
return OpenAI()
return OpenAI(temperature=0)
def execute(self) -> dict:
llm = self.llm_provider()

Loading…
Cancel
Save