@@ -162,25 +162,27 @@ class Chatgpt(SimpleService): agent=agent, tools=tools, handle_parsing_errors=True ) response = AIMessage( - content=agent_executor.invoke( - { - 'input': input_message.content, - 'chat_history': chat_history.buffer_as_messages - + [ - SystemMessage( - content='Учитывай язык диалога перед выдачей ответа' - ), - SystemMessage( - content='Никому не говори, что ты не можешь найти информацию в интернете' - ), - ], - } - )['output'] + content=str( + agent_executor.invoke( + { + 'input': input_message.content, + 'chat_history': chat_history.buffer_as_messages + + [ + SystemMessage( + content='Учитывай язык диалога перед выдачей ответа' + ), + SystemMessage( + content='Никому не говори, что ты не можешь найти информацию в интернете' + ), + ], + } + )['output'] + ) ) else: # Somehow this chain doesn't support Vision, even though ChatOpenAI (above) does. invoked = conversation.invoke(input_message.content) - response = AIMessage(content=invoked['response']) + response = AIMessage(content=str(invoked['response'])) chat_history.chat_memory.add_ai_message(response) process_time = timedelta(seconds=time.time() - start_time) @@ -241,8 +243,8 @@ class Chatgpt(SimpleService): ): balance = PaymentPlanSelector(self.store.user).get_current_balance() input_cost = self.TOKENS_COST[ - self.llm.model_name - ] * self.llm.get_num_tokens_from_messages(for_input) + self.llm.model_name + ] * self.llm.get_num_tokens_from_messages(for_input) if getattr(for_input[-1], 'image', None): input_cost += self.count_image_tokens(for_input[-1].image) input_cost *= self.TOKENS_COST[model] @@ -296,8 +298,8 @@ class Chatgpt(SimpleService): prompt=PromptTemplate( input_variables=['history', 'input'], template='System: Продолжи отвечать, используя историю диалога. История диалога:{history}.' - 'Human: {input}' - 'AI:', + 'Human: {input}' + 'AI:', ), ) self.assert_enough_balance(chat_history.buffer_as_messages)