Hey! First contribution, so open for suggestions!
The main reason I found myself drawn to this project is in my quest for making a super discord bot, being able to parse natural language to function calls in spring would be pretty cool. So while kind of basic I think it gives something to build on or get the conversation started on supporting functions. I saw #7 and figured I could take a crack at it.
I liked the idea of it being annotation based so I added @SpringAIFunction
as a generic annotation. I don't personally know the extent that azure supports functions but I figured it might be useful to live there as spring AI supports different APIs.
There might be a way to not need to specify the class directly in the annotation, but my reflection skills are not there 😆
This annotation is used with OpenAiFunctionManager
to look for any Function
annotated with the new annotation, and return them to whoever needs them as a FunctionExecutor
. I wasn't sure how to make sure that my functions as beans are created before the manager, but if thats not guaranteed, I can always make the executor a singleton after the first time getFunctionExecutor()
is run.
After things get a little bit finalized I can add some documentation around this.
I also updated open-ai-client.version
to 0.16.0
for function support
Comment From: markpollack
Thanks so much, I'm a bit behind reviewing PRs, but will get to it this week. Thanks again!
Comment From: smaldd14
Great job @Kirbstomper! Looking forward to seeing this PR accepted and being able to start function calling with Spring AI
Comment From: markpollack
I haven't forgotten, thanks for your patience.
Comment From: tzolov
Hi @Kirbstomper,
I has taken a while, but now with https://github.com/spring-projects/spring-ai/pull/299 we are close to start providing tool functions integration. The goal of #299 is to provide a (generic) foundation for the function calling capability that hopefully will be implemented for all LLM models that support this concept. Initial implementation comes with OpenAI support.
Would do you think about it?
Also I like your @SpringAIFunction
annotation idea. Perhaps you will be able to implement it on top of the 299 functionality?
Cheers, Christian
Comment From: Kirbstomper
Let me take a look at that!
Comment From: tzolov
Let me take a look at that!
Mind that the PR apparently has just been merged. You should check the main branch. Here is the related docs: https://docs.spring.io/spring-ai/reference/api/clients/functions/openai-chat-functions.html
I would still appreciate your feedback and improvements such as the SpringAIFunction annotation ;)
Comment From: Kirbstomper
Hey @tzolov worked the new interfaces from #299 into my stuff.
Not 100% on where stuff should logically live (or named) to be honest, but other than that it seems to do what we want.
Comment From: tzolov
Thanks @Kirbstomper ,
Indeed the packaging was a bit problematic. So for the time being I've moved everything inside the auto-configuration project under the /common/function package. This would limit the usage only to users that enable the auto-configuration. This a temporal solution until we figure out where this stuff should live. Also added a short docs in https://docs.spring.io/spring-ai/reference/api/clients/functions/openai-chat-functions.html#_registering_functions_as_beans
Btw, if you have an experience implementing function calling for other (non OpenAI) models feel free to contribute ;)
Refactored, Squashed, rebased and merged at: b2a4f0176110de6935ef8e8a7a858e638dc7d347
Comment From: tzolov
@Kirbstomper , fyi I did another refactoring cycle, removed in the @SpringAiFunction in favour of plain bean with optional @Description annotation or explicit property set ... You can find more in the the updated docs.