Function calling in llama.cpp?
Posted by Few_Acanthisitta_858@reddit | LocalLLaMA | View on Reddit | 5 comments
How are you using function calling in llama.cpp? I tried few things but it doesn't really seem to work 😕
foldl-li@reddit
I would recommend my project chatllm.cpp as a start. Some tool calling examples in a (almost) single python script: tool_llama3.1.py, tool_qwen.py, etc.
https://github.com/foldl/chatllm.cpp/tree/master/scripts
segmond@reddit
Two ways, one is to pass in the OpenAI style function defintion JSON string in the system instruction, and then prompt the LLM. Another is to use pydantic models to grammar, you can see example code here https://github.com/ggerganov/llama.cpp/blob/master/examples/pydantic_models_to_grammar_examples.py
Having gotten these to work, the best way would be to create a facade/wrapper function around the openAI chat, that will intercept the tools being passed, then utilize one of the above methods. By doing this, you can reuse any project that uses OpenAI for tool calling. Make sure the underlying model supports tool calling, most of the latest ones do. Even the tiny 1b-3b models have worked for me.
tronathan@reddit
(I have no experience with this, but i've heard that OpenAi's guided genration takes a lot of the model intelligene dcwn a peg, and the local stuff might allow for up-voting good repsonses and using that for singnla to improve thje mode lloocally.. bnut not suire
viag@reddit
I use grammars to force the outputs of the models. You automatically retrieve the signatures of the functions, create the grammar dynamically & it should work fine!
phree_radical@reddit
few-shot classification
https://www.reddit.com/r/LocalLLaMA/comments/1cafpij/comment/l0s9yzv/