tool_use #1

Open
dubey wants to merge 21 commits from tool_use into main
2 changed files with 12 additions and 2 deletions
Showing only changes of commit d90d4fe340 - Show all commits

12
main.py
View File

@ -77,6 +77,8 @@ def answer_question_tools(user_input: str, conversation_history: List[dict], max
emit('thinking', {'step': 'Starting'})
emit('conversation_history', {'history': conversation_history})
last_thought_content = None
for _ in range(max_retries):
response = ollama.chat(model=PRIMARY_MODEL, messages=conversation_history, tools=tool_manager.get_tools_for_ollama_dict(), stream=False)
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})
return reply_answer
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
return f"Max iterations reached. Last response: {assistant_message['content']}"

View File

@ -120,4 +120,4 @@ class PythonCodeTool(Tool):
except Exception as 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()])