Skip to content

Commit 8cdf7c7

Browse files
committed
Update (see details)
app.py, README.md, README.zh-TW.md, img 1. add logo docGPT.py 1. Add refine prompt 2. Redesign the prompt to enhance the readability of the response.
1 parent 63ff0d6 commit 8cdf7c7

File tree

6 files changed

+45
-22
lines changed

6 files changed

+45
-22
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# docGPT
1+
<p align="center">
2+
<img style="width: 50%; height: auto;" src="./img/repos_logo.png" alt="Chatbot Image">
3+
</p>
4+
25

36
[English](./README.md) | [中文版](./README.zh-TW.md)
47

README.zh-TW.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# docGPT
1+
<p align="center">
2+
<img style="width: 50%; height: auto;" src="./img/repos_logo.png" alt="Chatbot Image">
3+
</p>
24

35
[English](./README.md) | [中文版](./README.zh-TW.md)
46

app.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@
2727

2828

2929
def theme() -> None:
30-
st.set_page_config(page_title="DocGPT")
31-
icon, title = st.columns([3, 20])
32-
with icon:
33-
st.image('./img/chatbot.png')
34-
with title:
35-
st.title('PDF Chatbot')
36-
30+
st.set_page_config(page_title="Document GPT")
31+
st.image('./img/repos_logo.png', width=250)
32+
3733
with st.sidebar:
3834

3935
with st.expander(':orange[How to use?]'):

docGPT/docGPT.py

+35-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from langchain.memory import ConversationBufferMemory
1414
from langchain.prompts import PromptTemplate
1515
from langchain.vectorstores import FAISS
16-
from tenacity import retry, stop_after_attempt
1716

1817
openai.api_key = os.getenv('OPENAI_API_KEY')
1918

@@ -87,22 +86,44 @@ def __init__(self, docs):
8786
self.qa_chain = None
8887
self._llm = None
8988

90-
self.prompt_template = """
91-
Only answer what is asked. Answer step-by-step.
92-
If the content has sections, please summarize them in order and present them in a bulleted format.
93-
Utilize line breaks for better readability.
94-
For example, sequentially summarize the introduction, methods, results, and so on.
95-
96-
{context}
97-
98-
Question: {question}
99-
"""
100-
89+
self.prompt_template = (
90+
"Only answer what is asked. Answer step-by-step.\n"
91+
"If the content has sections, please summarize them "
92+
"in order and present them in a bulleted format.\n"
93+
"Utilize line breaks for better readability.\n"
94+
"For example, sequentially summarize the "
95+
"introduction, methods, results, and so on.\n"
96+
"Please use Python's newline symbols appropriately to "
97+
"enhance the readability of the response, "
98+
"but don't use two newline symbols consecutive.\n\n"
99+
"{context}\n\n"
100+
"Question: {question}\n"
101+
)
101102
self.prompt = PromptTemplate(
102103
template=self.prompt_template,
103104
input_variables=['context', 'question']
104105
)
105106

107+
self.refine_prompt_template = (
108+
"The original question is as follows: {question}\n"
109+
"We have provided an existing answer: {existing_answer}\n"
110+
"We have the opportunity to refine the existing answer"
111+
"(only if needed) with some more context below.\n"
112+
"------------\n"
113+
"{context_str}\n"
114+
"------------\n"
115+
"Given the new context, refine the original answer to better "
116+
"answer the question. "
117+
"If the context isn't useful, return the original answer.\n"
118+
"Please use Python's newline symbols "
119+
"appropriately to enhance the readability of the response, "
120+
"but don't use two newline symbols consecutive.\n"
121+
)
122+
self.refine_prompt = PromptTemplate(
123+
template=self.refine_prompt_template,
124+
input_variables=['question', 'existing_answer', 'context_str']
125+
)
126+
106127
@property
107128
def llm(self):
108129
return self._llm
@@ -143,7 +164,8 @@ def create_qa_chain(
143164
self._helper_prompt(chain_type)
144165
chain_type_kwargs = {
145166
'question_prompt': self.prompt,
146-
'verbose': True
167+
'verbose': True,
168+
'refine_prompt': self.refine_prompt
147169
}
148170

149171
db = self._embeddings()

img/chatbot_v2.png

217 KB
Loading

img/repos_logo.png

96 KB
Loading

0 commit comments

Comments
 (0)