MCPcopy Create free account
hub / github.com/InternScience/InternAgent / answer_question

Method answer_question

tasks/AutoMem/code/eval.py:140–209  ·  view source on GitHub ↗

Generate answer for a question given the conversation context.

(self, question: str, category: int, answer: str)

Source from the content-addressed store, hash-verified

138 return response
139
140 def answer_question(self, question: str, category: int, answer: str) -> str:
141 """Generate answer for a question given the conversation context."""
142 keywords = self.generate_query_llm(question)
143 # if category == 3:
144 # raw_context = self.retrieve_memory(keywords,k=10)
145 # # context = self.retrieve_memory_llm(raw_context, keywords)
146 # else:
147 raw_context = self.retrieve_memory(keywords,k=self.retrieve_k)
148 context = raw_context
149 # print("context:", context)
150 # context = self.retrieve_memory_llm(raw_context, question)
151 # context = raw_context
152 assert category in [1,2,3,4,5]
153 user_prompt = f"""Context:
154 {context}
155
156 Question: {question}
157
158 Answer the question based only on the information provided in the context above."""
159 temperature = 0.7
160 if category == 5: # adversial question, follow the initial paper.
161 answer_tmp = list()
162 if random.random() < 0.5:
163 answer_tmp.append('Not mentioned in the conversation')
164 answer_tmp.append(answer)
165 else:
166 answer_tmp.append(answer)
167 answer_tmp.append('Not mentioned in the conversation')
168 user_prompt = f"""
169 Based on the context: {context}, answer the following question. {question}
170
171 Select the correct answer: {answer_tmp[0]} or {answer_tmp[1]} Short answer:
172 """
173 temperature = self.temperature_c5
174 elif category == 2:
175 user_prompt = f"""
176 Based on the context: {context}, answer the following question. Use DATE of CONVERSATION to answer with an approximate date.
177 Please generate the shortest possible answer, using words from the conversation where possible, and avoid using any subjects.
178
179 Question: {question} Short answer:
180 """
181 elif category == 3:
182 user_prompt = f"""
183 Based on the context: {context}, write an answer in the form of a short phrase for the following question. Answer with exact words from the context whenever possible.
184
185 Question: {question} Short answer:
186 """
187 else:
188 user_prompt = f"""Based on the context: {context}, write an answer in the form of a short phrase for the following question. Answer with exact words from the context whenever possible.
189
190 Question: {question} Short answer:
191 """
192 response = self.memory_system.llm_controller.llm.get_completion(
193 user_prompt,response_format={"type": "json_schema", "json_schema": {
194 "name": "response",
195 "schema": {
196 "type": "object",
197 "properties": {

Callers 1

process_single_sampleFunction · 0.45

Calls 3

generate_query_llmMethod · 0.95
retrieve_memoryMethod · 0.95
get_completionMethod · 0.45

Tested by

no test coverage detected