diff --git a/src/fabledassistant/routes/chat.py b/src/fabledassistant/routes/chat.py index 34e7f96..9e83e5a 100644 --- a/src/fabledassistant/routes/chat.py +++ b/src/fabledassistant/routes/chat.py @@ -162,8 +162,19 @@ async def send_message_route(conv_id: int): # Build history from existing messages (excluding system and the placeholder) history = [] for msg in conv.messages: - if msg.role != "system": - history.append({"role": msg.role, "content": msg.content}) + if msg.role == "system": + continue + msg_dict = {"role": msg.role, "content": msg.content or ""} + if msg.tool_calls: + msg_dict["tool_calls"] = [ + {"function": {"name": tc["function"], "arguments": tc["arguments"]}} + for tc in msg.tool_calls + ] + history.append(msg_dict) + for tc in msg.tool_calls: + history.append({"role": "tool", "content": json.dumps(tc.get("result", {}))}) + else: + history.append(msg_dict) model = await get_setting(uid, "default_model", Config.OLLAMA_MODEL) or Config.OLLAMA_MODEL