Introduction to Funcion Calling
Function calls allow you to connect models such as gpt-4o to external tools and systems. This is useful for many things, such as empowering AI assistants or creating deep integrations between your apps and models.
If you know or have used Semantic Kernel may find that in addition to OpenAI support Function Calling models, automatic function calling does not seem to be good, domestic big models almost can not be used, due to want to solve this problem, in GitHub to find a big brother's method.
GitHub Address:/Jenscaasen/UniversalLLMFunctionCaller
Biggie is doing it by prompting the engineering with the principle of calling local functions in Semantic Kernel. I looked at Biggie's code and changed the prompt word to Chinese, which may be more applicable to the big domestic models.
Wrote a post about it earlier:
But at that time they did not have an open source project, interested friends, there is no way to quickly get started to experience, only to do it all over again, and now has been integrated into this part of my open source project SimpleRAG, interested friends only need to fill in their own API Key can be a quick experience, you can also easily view the code.
GitHub Address:/Ming-jiayou/SimpleRAG
A Generic Approach to Function Calling
Before we start the presentation, let's look at the effect:
Compare the effect of not using FunctionCalling:
One more example:
Compare the effect of not using Function Calling:
The exact code can be viewed in GitHub, and the focus here is on the implementation.
Here is an example of the Qwen2-7B-Instruct.
First create a Kernel:
Import plugins in Kernel:
The above are just simulation functions used for testing.
Just write it like this:
Now explore the process inside.
First convert the plugin to text:
Add examples to the dialog history:
Add a command to the dialog history:
Embed all the available functions into this Prompt now, as shown below:
Add the command to the dialog history now, as shown below:
Let LLM choose which function should be called first or not, depending on the task:
LLM returns the function that needs to be called to accomplish this task:
Verify this function:
Calls a function in the plugin:
The result returned by the first function:
Sending another request to the LLM, which function should now be called, the LLM returns as shown below:
Similarly execute the second function in the plugin:
The return of the second function:
The request is then sent to the LLM:
The function called is named Finished, indicating that the process is complete and you can jump out, as shown below:
Got the last of the information:
The results are shown below:
The above is the approximate flow of this method, the specific implementation can be seen in the GitHub open source code.
After testing this method available LLM
flat-roofed building | usable model |
---|---|
Silicon-based flow | Llama-3.1-405/70/8B、Llama-3-70/8B-Instruct、DeepSeek-V2-Chat、deepseek-llm-67b-chat、Qwen2-72/57/7/1.5B-Instruct、Qwen2-57B-A14B-Instruct、Qwen1.5-110/32/14B-Chat、Qwen2-Math-72B-Instruct、Yi-1.5-34/9/6B-Chat-16K、internlm2_5-20/7b-chat |
Xunfei Starburst (1940-), Chinese science fiction writer and dramatist | Spark Lite、Spark Pro-128K、Spark Max、Spark4.0 Ultra |
lit. zero-one million things | yi-large、yi-medium、yi-spark、yi-large-rag、yi-large-fc、yi-large-turbo |
The Dark Side of the Moon | moonshot-v1-8k、moonshot-v1-32k、moonshot-v1-128k |
Smart Spectrum AI | glm-4-0520、glm-4、glm-4-air、glm-4-airx、glm-4-flash、glm-4v、glm-3-turbo |
DeepSeek | deepseek-chat、deepseek-coder |
jumping stars | step-1-8k、step-1-32k、step-1-128k、step-2-16k-nightly、step-1-flash |
Minimax | abab6.5s-chat、abab5.5-chat |
Alibaba's hundreds of refinements | qwen-max、qwen2-math-72b-instruct、qwen-max-0428、qwen2-72b-instruct、qwen2-57b-a14b-instruct、qwen2-7b-instruct |
The above is not necessarily complete, there are still some models that have not been tested, so feel free to continue to add.