-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support function calling #514
Conversation
64efcc4
to
28e49d0
Compare
The text generated by function calls is beyond the capabilities of the LLM. Including it in session conversation will only cause interference. Note: the functions is bound to role other than session. It's recommended to use temporary roles during the session. Another factor to consider is the unpredictable variety of text generated by external tools. The text can be empty (for example, if the tool simply opens another application), dynamic (like a progress bar), or unexpectedly large. It is inappropriate to include such output in a conversation. |
AIChat now fully supports the function calling feature. It can retrieve information from functions and pass it back to the LLM for further processing. @tkanarsky |
@sigoden in the current implementation the functions are called later in the conversation even though they were already called with the same parameters. Is this required in some scenario? |
AIChat save the question and final result in the session. The intermediate data returned by the function call has an uncertain format and variable size, not as valuable as you think. Cache makes no sense, how do you know when the cache should be invalidated? |
In my testing I got the impression that the tool was not storing the results in the session. If that's not the case then should be fine :) And yes I agree there is no need to over-optimize :) |
If the LLM doesn't support parallel function calling, it will cause an infinite loop:
Is this what you're talking about? @gilcu3 Despite multiple requests, they are counted as a single round-trip message. we can and need to reuse function call results. |
Aichat can now reuse tool call results. LLMs that don't support parallel function calls now work. |
What I observed was thr LLM making a function call that was superfluous, because the answer was already mentioned in the conversation before. This infinite loop is/was a different issue. |
@sigoden you're the GOAT!! Thank you for the implementation! |
Why use LLM function calling?
LLM function calling is a powerful technique that allows Large Language Models (LLMs) to interact with external tools and data sources. This significantly enhances their capabilities and opens up exciting possibilities for various applications.
AIChat LLM Functions
AIChat implements function calling by running an external tool.
I created a new repo https://github.com/sigoden/llm-functions and write some tools that cooperate with function calls.
You can configure function calling feature according to its readme.
The client types that currently support function calling are: openai, claude, gemini and cohere.
Function calling in AIChat must work with a role or session.
A
function_filter
field is added to the role/session. It controls which functions are used.AIChat provides a built-in
%functions%
role whosefunction_filter
is.*
, matching all functions.In AIChat, the roles are smiliar to GPTs.
Function Types
Retrieve Type
The function returns JSON data.
AIChat retrieves the data and send it to LLM for further processing.
AIChat does not ask permission to run the function or print the output.
Execute Type
The function can do anything.
AIChat will ask permission before running the function.
AIChat categorizes functions starting with "may_" as "execute" type and all others as "retrieve" type.
Conclusion
close #507