Skip to content

Commit 408cebc

Browse files
committedJul 24, 2023
added document identification to stay on topic
1 parent b8d481a commit 408cebc

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed
 

‎app/agents/chain_of_thoughts.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ def run(self, query: str, context, history) -> str:
151151
data_matching_round = self.data_matching(str(topic_extraction_round), str(data_summary_round))
152152

153153
if data_matching_round == 1:
154-
questions_listing_round = questions_listing(self.question, str(context))
154+
document_evaluation_round = document_evaluation(str(context))
155+
print(document_evaluation_round)
156+
questions_listing_round = questions_listing(self.question, str(document_evaluation_round))
155157
print(Fore.CYAN + Style.BRIGHT + "The questions are:" + str(questions_listing_round) + Style.RESET_ALL)
156158
questions_answer_round = questions_answering(self.question, str(context), str(questions_listing_round))
157159
print(Fore.CYAN + Style.BRIGHT + "The answers to the questions are:" + str(questions_answer_round) + Style.RESET_ALL)

‎app/prompt_templates/exllama.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
HOST = '86.242.95.136:449' # API details
33
URI = f'http://{HOST}/api/v1/generate'
44

5-
def questions_listing(question, context):
5+
def questions_listing(question, document):
66
prompt = f'''A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.
77
### Human:
8-
Make a list of 5 questions you should ask yourself to infer the answer to '{question}' from a given context.
8+
Here is a document description: {document}
9+
Make a list of 5 questions you should ask yourself to infer the answer to '{question}' from an excerpt of the document described above.
910
1011
### Assistant: '''
1112
print(str(prompt))
@@ -100,4 +101,24 @@ def phatic_api_answer(question, history, context):
100101
if response.status_code == 200:
101102
result = response.json()['results'][0]['text']
102103
return result
103-
104+
105+
106+
107+
def document_evaluation(context):
108+
prompt = f'''A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.
109+
### Human:
110+
Identify the kind of document the following context is taken from: "{context}".
111+
112+
### Assistant: '''
113+
print(str(prompt))
114+
request = {
115+
'prompt': prompt,
116+
'max_new_tokens': 200,
117+
'preset': 'Divine Intellect',
118+
}
119+
120+
response = requests.post(URI, json=request)
121+
122+
if response.status_code == 200:
123+
result = response.json()['results'][0]['text']
124+
return result

0 commit comments

Comments
 (0)
Failed to load comments.