self.result_output.setPlainText(str(result1)+ "\n")下面再来一个 self.result_output.setPlainText(str(result1)+ "\n")上面的输出不备下面的覆盖。
时间: 2024-03-26 21:34:43 浏览: 17
如果你想在 `self.result_output` 中追加新的输出,而不是覆盖原来的内容,可以使用 `appendPlainText` 方法。例如:
```
self.result_output.appendPlainText(str(result1) + "\n")
self.result_output.appendPlainText(str(result2) + "\n")
```
这样就可以在 `self.result_output` 中追加新的内容,不会覆盖原有的内容。
相关问题
self.result_output.setPlainText(str(result1))输出后换行输出。
你可以在输出的字符串后面加上 "\n" 或者使用 Python 中的换行字符 "\r\n",例如:
```
self.result_output.setPlainText(str(result1) + "\n")
```
或者:
```
self.result_output.setPlainText(str(result1) + "\r\n")
```
这样就可以实现换行输出了。
def generatorAnswer(self, prompt: str, history: List[List[str]] = [], streaming: bool = False): if streaming: history += [[]] for inum, (stream_resp, _) in enumerate(self.checkPoint.model.stream_chat( self.checkPoint.tokenizer, prompt, history=history[-self.history_len:-1] if self.history_len > 0 else [], max_length=self.max_token, temperature=self.temperature )): # self.checkPoint.clear_torch_cache() history[-1] = [prompt, stream_resp] answer_result = AnswerResult() answer_result.history = history answer_result.llm_output = {"answer": stream_resp} yield answer_result else: response, _ = self.checkPoint.model.chat( self.checkPoint.tokenizer, prompt, history=history[-self.history_len:] if self.history_len > 0 else [], max_length=self.max_token, temperature=self.temperature ) self.checkPoint.clear_torch_cache() history += [[prompt, response]] answer_result = AnswerResult() answer_result.history = history answer_result.llm_output = {"answer": response} yield answer_result
这段代码是用来生成AI对话回答的,其中包括以下参数:
- prompt: 代表AI的输入,即对话的开端
- history: 代表之前的对话历史,可以为空
- streaming: 是否使用流式对话,即实时回答对话
如果使用流式对话,该函数会在对话过程中不断生成回答;如果不使用流式对话,该函数会在输入完整的对话后一次性生成回答。该函数返回的是一个生成器,每次调用生成一个回答,其中包含了对话历史和AI的回答结果。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)