Spaces:
Running
Running
filipsedivy
commited on
Commit
·
fc6868b
1
Parent(s):
d458310
Update prompts
Browse files
app.py
CHANGED
@@ -13,15 +13,23 @@ def respond(
|
|
13 |
message,
|
14 |
history: list[tuple[str, str]],
|
15 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
matching_docs = db.similarity_search(message)
|
17 |
|
18 |
if not matching_docs:
|
19 |
prompt = (
|
20 |
-
f"You are an expert in generating responses when there is no information available. "
|
21 |
f"Unfortunately, there are no relevant documents available to answer the following query:\n\n"
|
22 |
f"Query: {message}\n\n"
|
23 |
f"Please provide a polite and original response to inform the user that the requested information is not "
|
24 |
-
f"available."
|
25 |
)
|
26 |
else:
|
27 |
context = ""
|
@@ -33,23 +41,31 @@ def respond(
|
|
33 |
current_length += doc_length
|
34 |
|
35 |
prompt = (
|
36 |
-
f"You are an expert in summarizing and answering questions based on given documents. "
|
37 |
f"You're an expert in English grammar at the same time. "
|
38 |
f"This means that your texts are flawless, correct and grammatically correct."
|
|
|
39 |
f"Please provide a detailed and well-explained answer to the following query in 4-6 sentences:\n\n"
|
40 |
f"Query: {message}\n\n"
|
41 |
f"Based on the following documents:\n{context}\n\n"
|
42 |
-
f"Answer:"
|
43 |
)
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
|
|
53 |
|
54 |
|
55 |
demo = gr.ChatInterface(
|
|
|
13 |
message,
|
14 |
history: list[tuple[str, str]],
|
15 |
):
|
16 |
+
messages = []
|
17 |
+
|
18 |
+
for val in history:
|
19 |
+
if val[0]:
|
20 |
+
messages.append({"role": "user", "content": val[0]})
|
21 |
+
if val[1]:
|
22 |
+
messages.append({"role": "assistant", "content": val[1]})
|
23 |
+
|
24 |
matching_docs = db.similarity_search(message)
|
25 |
|
26 |
if not matching_docs:
|
27 |
prompt = (
|
28 |
+
f"<s>[INST] You are an expert in generating responses when there is no information available. "
|
29 |
f"Unfortunately, there are no relevant documents available to answer the following query:\n\n"
|
30 |
f"Query: {message}\n\n"
|
31 |
f"Please provide a polite and original response to inform the user that the requested information is not "
|
32 |
+
f"available.[/INST]</s>"
|
33 |
)
|
34 |
else:
|
35 |
context = ""
|
|
|
41 |
current_length += doc_length
|
42 |
|
43 |
prompt = (
|
44 |
+
f"<s>[INST] You are an expert in summarizing and answering questions based on given documents. "
|
45 |
f"You're an expert in English grammar at the same time. "
|
46 |
f"This means that your texts are flawless, correct and grammatically correct."
|
47 |
+
f"Never write in the output response what document the response is in. It looks very unprofessional."
|
48 |
f"Please provide a detailed and well-explained answer to the following query in 4-6 sentences:\n\n"
|
49 |
f"Query: {message}\n\n"
|
50 |
f"Based on the following documents:\n{context}\n\n"
|
51 |
+
f"Answer:[/INST]</s>"
|
52 |
)
|
53 |
|
54 |
+
messages.append({"role": "user", "content": prompt})
|
55 |
+
|
56 |
+
response = ""
|
57 |
+
|
58 |
+
for message in client.chat_completion(
|
59 |
+
messages,
|
60 |
+
max_tokens=250,
|
61 |
+
stream=True,
|
62 |
+
temperature=0.7,
|
63 |
+
top_p=0.95,
|
64 |
+
):
|
65 |
+
token = message.choices[0].delta.content
|
66 |
|
67 |
+
response += token
|
68 |
+
yield response
|
69 |
|
70 |
|
71 |
demo = gr.ChatInterface(
|