-
Notifications
You must be signed in to change notification settings - Fork 5k
Demonstration of using tools to do more specialized queries #2738
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
Conversation
Why is it not worth merging? |
I don't actually know that this is a common enough use case to warrant a special tool, I just wanted to make sure folks had an up-to-date example of how to add another tool (it came up in one of the issues). |
@cforce As long as LLM calls are limited to UI input/output you don't need to keep a log of all LLM calls that the backend makes. The backend does not pass data about its tool calls back to the client, hence this detail is not recorded and not preserved in the message history. The client re-generates the list if historic messages every time a new prompt is entered. It does so from the information that is available on the client. Hence the backend will not know what it did in the previous conversation turns with tool calls. (Note: I did not follow the evolution of the code base since April 2025 so if a full state persistence including LLM and tool call parameters is added to the app then my comment may be outdated) I implemented state persistence for the backend-frontend roundtrip when I added optional tool calls. Session_state parameter was helpful but some workaround was needed. |
@gaborvar That's a good assessment, the app does not yet use the standard approach of a tool-calling agent to actually append the tool call result to the conversation, we instead extract results and send a brand new conversation with the formatted results to an LLM with a different system prompt. This made sense at the time, as many LLMs did not support tool calling properly, but now that many (non-local) LLMs do support tool calling, we can consider moving the repo to use an actual tool-calling flow. There are drawbacks to that as well, however:
|
@pamelafox You already removed the biggest hurdle to full message history preservation (incl tool params and results) when you removed openai_messages_token_helper in March. It had blocked the pathway of tool related messages. You don't have to touch your existing message handling code. Instead, you can send tool related log out-of-band: there is a separate Hurdle No 2 is coexistence with a change in app.py in November when the Hurdle No 3: there are a few calls in the call chain that do not pass session_state on to the next call. This breaks the roundtrip of session_state but it is easy to fix. Add session_state as a parameter to e.g. To store the tool related messages I used a list that had a node corresponding to each message in the message list from the frontend.
On the backend you have to merge message history with tool related calls from session_state before you make your calls to the LLM. Code that merges the tools related messages into the message list:
This concept works in my fork. |
Hi Pamela thanks for this just for my understanding this code needs me to upgrade the repo to the new release from 19 sept i think? |
I now have issues with my codebase after merging
any quick suggestions i am missing? thank you |
GPT4VSettings does not exist in the current main, you can delete that file/folder. |
Purpose
This is an example PR, not intended for merging, demonstrating the usage of Chat Completion API function calling in order to perform a more specific search query. In this case, I defined a "search_by_filename" function, and the model knows to call that when I enter a question like "Summarize the document named PerksPlus.pdf". I then pass that along to the search function and turn it into a filter.
This sort of approach could also work for searching by additional fields that are in an index. For example, if a field stores the timestamp of a document, you could search for documents created in a certain time period, by adding an appropriate function and filter condition.
Screenshots: