You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pgml-apps/pgml-chat/README.md
+41-10Lines changed: 41 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ A command line tool to build and deploy a **_knowledge based_** chatbot using Po
3
3
4
4
There are two stages in building a knowledge based chatbot:
5
5
- Build a knowledge base by ingesting documents, chunking documents, generating embeddings and indexing these embeddings for fast query
6
-
- Generate responses to user queries by retrieving relevant documents and generating responses using OpenAI API
6
+
- Generate responses to user queries by retrieving relevant documents and generating responses using OpenAIand[OpenSourceAIAPI](https://postgresml.org/docs/introduction/apis/client-sdks/opensourceai)
7
7
8
8
This tool automates the above two stages and provides a command line interface to build and deploy a knowledge based chatbot.
9
9
@@ -12,7 +12,7 @@ Before you begin, make sure you have the following:
12
12
13
13
- PostgresML Database: Sign up for a free[GPU-powered database](https://postgresml.org/signup)
In addition to relevant context retrieved from vector search, system prompt to generate accurate responses with minimum hallucinations requires prompt engineering.
156
+
Different chat completion models require different system prompts. Since the prompts including the context are long, they suffer from**lostin the middle** problem describedin [this paper](https://arxiv.org/pdf/2307.03172.pdf). Below are some of the prompts that we have usedfor different chat completion models.
157
+
158
+
## Default prompt (GPT-3.5 and open source models)
159
+
```text
160
+
Use the following pieces of context to answer the question at the end.
161
+
If you don't know the answer, just say that you don't know, don't try to make up an answer.
162
+
Use three sentences maximum and keep the answer as concise as possible.
163
+
Always say "thanks for asking!" at the end of the answer.
164
+
```
165
+
166
+
## GPT-4 System prompt
167
+
```text
168
+
You are an assistant to answer questions about {topic}.\
169
+
Your name is {name}. You speak like {persona} in {language}. Use the given list of documents to answer user's question.\
170
+
Use the conversationhistoryif it is applicable to answer the question.\n Use the following steps:\n \
171
+
1. Identifyif the user input is really a question.\n \
172
+
2. If the user input is not related to the {topic}then respond that it is not related to the {topic}.\n \
173
+
3. If the user input is related to the {topic}then first identify relevant documents from the list of documents.\n \
174
+
4. If the documents that you found relevant have information to completely and accurately answers the questionthen respond with the answer.\n \
175
+
5. If the documents that you found relevant have code snippetsthen respond with the code snippets.\n \
176
+
6. Most importantly, don't make up code snippets that are not present in the documents.\n \
177
+
7. If the user input is generic like Cool, Thanks, Hello, etc. then respond with a generic answer. \n"
178
+
```
179
+
149
180
# Developer Guide
150
181
151
182
1. Clone this repository, start a poetry shell and install dependencies