(self, lang)
| 1495 | self.memory = ConversationBufferMemory(memory_key="chat_history", output_key='output') |
| 1496 | |
| 1497 | def init_agent(self, lang): |
| 1498 | self.memory.clear() #clear previous history |
| 1499 | if lang=='English': |
| 1500 | PREFIX, FORMAT_INSTRUCTIONS, SUFFIX = VISUAL_CHATGPT_PREFIX, VISUAL_CHATGPT_FORMAT_INSTRUCTIONS, VISUAL_CHATGPT_SUFFIX |
| 1501 | place = "Enter text and press enter, or upload an image" |
| 1502 | label_clear = "Clear" |
| 1503 | else: |
| 1504 | PREFIX, FORMAT_INSTRUCTIONS, SUFFIX = VISUAL_CHATGPT_PREFIX_CN, VISUAL_CHATGPT_FORMAT_INSTRUCTIONS_CN, VISUAL_CHATGPT_SUFFIX_CN |
| 1505 | place = "输入文字并回车,或者上传图片" |
| 1506 | label_clear = "清除" |
| 1507 | self.agent = initialize_agent( |
| 1508 | self.tools, |
| 1509 | self.llm, |
| 1510 | agent="conversational-react-description", |
| 1511 | verbose=True, |
| 1512 | memory=self.memory, |
| 1513 | return_intermediate_steps=True, |
| 1514 | agent_kwargs={'prefix': PREFIX, 'format_instructions': FORMAT_INSTRUCTIONS, |
| 1515 | 'suffix': SUFFIX}, ) |
| 1516 | return gr.update(visible = True), gr.update(visible = False), gr.update(placeholder=place), gr.update(value=label_clear) |
| 1517 | |
| 1518 | def run_text(self, text, state): |
| 1519 | self.agent.memory.buffer = cut_dialogue_history(self.agent.memory.buffer, keep_last_n_words=500) |
nothing calls this directly
no outgoing calls
no test coverage detected