fix empty thoughts as a reply
This commit is contained in:
parent
26514e9fdd
commit
d90d4fe340
12
main.py
12
main.py
@ -77,6 +77,8 @@ def answer_question_tools(user_input: str, conversation_history: List[dict], max
|
|||||||
emit('thinking', {'step': 'Starting'})
|
emit('thinking', {'step': 'Starting'})
|
||||||
emit('conversation_history', {'history': conversation_history})
|
emit('conversation_history', {'history': conversation_history})
|
||||||
|
|
||||||
|
last_thought_content = None
|
||||||
|
|
||||||
for _ in range(max_retries):
|
for _ in range(max_retries):
|
||||||
response = ollama.chat(model=PRIMARY_MODEL, messages=conversation_history, tools=tool_manager.get_tools_for_ollama_dict(), stream=False)
|
response = ollama.chat(model=PRIMARY_MODEL, messages=conversation_history, tools=tool_manager.get_tools_for_ollama_dict(), stream=False)
|
||||||
assistant_message = response['message']
|
assistant_message = response['message']
|
||||||
@ -105,7 +107,15 @@ def answer_question_tools(user_input: str, conversation_history: List[dict], max
|
|||||||
emit('thought', {'type': 'answer', 'content': reply_answer})
|
emit('thought', {'type': 'answer', 'content': reply_answer})
|
||||||
return reply_answer
|
return reply_answer
|
||||||
else:
|
else:
|
||||||
emit('thought', {'type': 'thoughts', 'content': assistant_message['content']})
|
current_thought_content = assistant_message['content'].strip()
|
||||||
|
emit('thought', {'type': 'thoughts', 'content': current_thought_content})
|
||||||
|
|
||||||
|
# Check for two consecutive thoughts, with the second being empty
|
||||||
|
if last_thought_content and not current_thought_content:
|
||||||
|
emit('thought', {'type': 'answer', 'content': last_thought_content})
|
||||||
|
return last_thought_content
|
||||||
|
|
||||||
|
last_thought_content = current_thought_content
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return f"Max iterations reached. Last response: {assistant_message['content']}"
|
return f"Max iterations reached. Last response: {assistant_message['content']}"
|
||||||
|
2
tools.py
2
tools.py
@ -120,4 +120,4 @@ class PythonCodeTool(Tool):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Error executing code: {str(e)}"
|
return f"Error executing code: {str(e)}"
|
||||||
|
|
||||||
return '\n'.join([f"{k}: {v}" for k, v in result.items()])
|
return '\n'.join([f"{k}:\n{v}" for k, v in result.items()])
|
Loading…
Reference in New Issue
Block a user