(self, question, search_chain_length, split_flag=True)
| 235 | self.documents = [] |
| 236 | |
| 237 | def get_answer(self, question, search_chain_length, split_flag=True): |
| 238 | self.input = f"The question: {question}" |
| 239 | self.output = "" |
| 240 | length = 0 |
| 241 | while True: |
| 242 | if length>=search_chain_length: |
| 243 | break |
| 244 | else: |
| 245 | self.input = self.input + self.output |
| 246 | conversation = [{"role": "system","content": "You are a helpful assistant"},{"role": "user","content": self.input}] |
| 247 | outputs = self.llm.chat( |
| 248 | messages=conversation, |
| 249 | sampling_params=self.sampling_params |
| 250 | ) |
| 251 | # stream_output = self.output + outputs# 流式显示 |
| 252 | generated_text = outputs[0].outputs[0].text |
| 253 | mydict=split_response(generated_text) |
| 254 | if mydict.get('answer'): |
| 255 | answer=mydict.get('answer') |
| 256 | self.search_chain.append(mydict) |
| 257 | length+=1 |
| 258 | self.output = self.output + generated_text |
| 259 | break |
| 260 | elif mydict.get('query'): |
| 261 | if split_flag: |
| 262 | GetStepbystepRetrievalv2(mydict, self.retrieved_ids, self.documents, self.config) |
| 263 | else: |
| 264 | GetStepbystepRetrieval(mydict, self.retrieved_ids, self.documents, self.config) |
| 265 | self.search_chain.append(mydict) |
| 266 | length+=1 |
| 267 | self.output = self.output + generated_text +"\n"+ f"The retrieval documents: {mydict['doc']}" +"\n" |
| 268 | pdb.set_trace() |
| 269 | self.history_down = [] |
| 270 | self.search_chain = [] |
| 271 | self.retrieved_ids = [] |
| 272 | self.documents = [] |
| 273 | return self.output |
| 274 | |
| 275 | def main(): |
| 276 | parser = argparse.ArgumentParser(description="使用vLLM部署Llama模型进行多轮对话") |
no test coverage detected