Skip to content

Commit

Permalink
feat: Set temperature when working with OpenAI
Browse files Browse the repository at this point in the history
feat: Store chat in a chat archive which persists between sessions
  • Loading branch information
namuan committed Feb 5, 2023
1 parent cb37d99 commit 63cfd1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/doc_search/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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,
)
Expand All @@ -20,7 +21,7 @@
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}**
Expand All @@ -38,6 +39,7 @@ def add_qa_to_panel(question: str, answer: str) -> None:
),
)
)
return qa_block


def get_conversations(_: Any) -> pn.Column:
Expand All @@ -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)))

Expand All @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion src/doc_search/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -269,7 +275,7 @@ def llm_provider(self) -> BaseLLM:
)
return HuggingFacePipeline(pipeline=pipe)
else:
return OpenAI()
return OpenAI(temperature=0)

def execute(self) -> dict:
llm = self.llm_provider()
Expand Down

0 comments on commit 63cfd1c

Please sign in to comment.