Feature / Function Calling #43
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feature Function Calling
Deepseek has added a new feature, which is function calling.
Function Calling allows the model to call external tools to enhance its capabilities.[1]
src: https://api-docs.deepseek.com/guides/function_calling
Features In Package
Adding client trait
HasToolsFunctionCalling
and use it toDeepSeekClient
: It has many added functions :-setTools
Passing the list of tools by the client.queryToolCall
Passing the functions called by the form to the query.buildToolCallQuery
Formatting the called functions to pass them to the query.queryTool
Passing the result of the function from its identifier to the query.buildToolQuery
Formatting the result of the function to pass it to the query.Adding static properties to
QueryRoles
:-ASSISTANT
Assigned by default when passing the called functions.TOOL
Assigned by default when passing the result of the executed functions.Adding static properties to
QueryFlags
:-TOOLS
Added by default when passing the tools to the form.Adding test :-
ClientDependency/FakeResponse
fake response to function calling test.FunctionCallingTest
function calling test.Implementation steps
In the example, the basic flow consists of two requests and they are in order:
1. Define the tools used by the model and pass them with each message passed to the model, Receive query messages from the end user and pass them to the model with the defined tools.
get_weather($city)
.The user requests the weather in Cairo.
Output response like.
2. Receive the response and check if it has called one or more tools to execute it in the system ,And execute the tool called by the model.
The deepseek api responds to the system and requests the execution of the tool responsible for fetching the weather status.
3. Coordinate the results and send the previous response with the results of the executed tools.
Formats the response, and sends it back to the form.
Request like
4. Receive the final response from the model and pass it to the end user.
The deepseek api responds with the final response, which is the weather status according to the data passed to it in the example.
Output response like :-