-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Python: New Feature: Python: Isn’t there an option to turn off only the final response generation in FunctionCallBehavior? #6998
Comments
There are currently 3 FunctionCallBehaviors Supported :
I think you are looking for Option 2 here with auto_invoke=False and then you can invoke the functions yourself for step 1 and 2. To invoke the function manually you can use Hopefully i've got the question right and could help you. Probably someone from the SK team will take a look later on this issue aswell. Also another comment, there is an Update coming to FunctionCallBehavior, it will be FunctionChoiceBehavior soon with the following options :
|
Hi @yuichiromukaiyama, if I understand your request properly, it seems you'd be able to use filters to help achieve your goal. The filters can give you an "early out" after function calling that will not call the model for a final answer. Here is a sample of that. If I misunderstood your request then please help clarify. |
Thank you! By using the example you provided, I was able to reproduce the ideal processing. (The code I wrote is almost the same as the sample you shared.) @kernel.filter(FilterTypes.AUTO_FUNCTION_INVOCATION)
async def auto_function_invocation_filter(context: AutoFunctionInvocationContext, next):
"""A filter that will be called for each function call in the response."""
print("\nAuto function invocation filter")
print(f"Function: {context.function.name}")
print(f"Request sequence: {context.request_sequence_index}")
print(f"Function sequence: {context.function_sequence_index}")
# as an example
function_calls = context.chat_history.messages[-1].items
print(f"Number of function calls: {len(function_calls)}")
# if we don't call next, it will skip this function, and go to the next one
await next(context)
result = context.function_result
for fc in function_calls:
if fc.plugin_name == "math":
context.function_result = FunctionResult(
function=result.function, value="Stop trying to ask me to do math, I don't like it!"
)
context.terminate = True Alternatively, would it be appropriate to parse the obtained plugin name and argument strings yourself and execute them as follows? For example, the code would look like this: kernel.invoke(plugin_name="${tool call plugin name}", arguments=json.loads("${tool call arguments}")) @nmoeller |
@yuichiromukaiyama you can find the function here. |
Hi @yuichiromukaiyama, @nmoeller is correct -- we have added this new kernel As a side note: we've updated our function calling abstractions from |
Hi @yuichiromukaiyama is there more action needed on this issue? If so, please feel free to re-open. Closing for now. |
I’m using function calling in the following way. This implementation is very simple and currently helps me a lot.
However, in cases where I want to achieve the following use case, the generative AI ends up generating the final response each time, which significantly increases the processing time.
This is an extreme example, but the point is that the current approach is sufficient for generating responses at step 3. However, for more complex workflows, at steps 1 and 2, response generation is not necessary; only the external data obtained through function calls is needed.
In these cases, is it possible with the current functionality to use function calls at steps 1 and 2 without generating the final response, and at step 3, use function calls while also generating the final response with the generative AI?
(Should I use OpenAIChatCompletionBase._process_function_call?)
environment
The text was updated successfully, but these errors were encountered: