KeyError in LLMService.unregister_function for functions without a start_callback
pipecat version
0.0.90
Python version
3.12.9
Operating System
macos 15.6.1
Issue description
When calling LLMService.unregister_function, it will properly remove the function_name from _functions. It will then check if the function is registered in _start_callbacks which throws a KeyError if the function_name is not in the dictionary.
If the key isn't in _functions, that would also throw a KeyError.
Reproduction steps
- Call
LLMService.register_functionto register a function. Do not provide an argument forstart_callback. - Call
LLMService.unregister_functionwith that function's name.
Expected behavior
I would expect unregister_function to function without error if my function name is registered as a function but is not registered as a start_callback.
If my function was not registered in the first place, I might expect this to also function without error. This case is more reasonable to throw a KeyError, though I might still expect it be ignored as a no-op. That is more of a style choice.
Actual behavior
A KeyError is thrown from unregister_function.
Logs
.venv/lib/python3.12/site-packages/pipecat/services/llm_service.py", line 395, in unregister_function
if self._start_callbacks[function_name]:
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: MyFunctionName