Skip to content

Conversation

@Kirbstomper
Copy link
Contributor

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

@markpollack
Copy link
Member

Thanks so much, I'm a bit behind reviewing PRs, but will get to it this week. Thanks again!

@smaldd14
Copy link

Great job @Kirbstomper! Looking forward to seeing this PR accepted and being able to start function calling with Spring AI

@markpollack
Copy link
Member

I haven't forgotten, thanks for your patience.

@tzolov tzolov self-assigned this Oct 5, 2023
@tzolov tzolov added the enhancement New feature or request label Oct 5, 2023
@markpollack markpollack assigned markpollack and unassigned tzolov Nov 15, 2023
@markpollack markpollack added this to the 0.9.0 milestone Dec 19, 2023
@tzolov
Copy link
Contributor

tzolov commented Feb 11, 2024

Hi @Kirbstomper,

I has taken a while, but now with #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

@Kirbstomper
Copy link
Contributor Author

Let me take a look at that!

@tzolov
Copy link
Contributor

tzolov commented Feb 12, 2024

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 ;)

Adds the ability to register functions to be used in the even the LLM cannot answer something.
This is useful for something like realtime data or if you want
your LLM to execute code based on user input and return a response. (ULTRA_CHATBOT)
@Kirbstomper
Copy link
Contributor Author

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.

@Kirbstomper Kirbstomper changed the title Basic Function support when using OpenAI Add annotation for turning Functions into SpringAIFunctions Feb 13, 2024
@Kirbstomper Kirbstomper changed the title Add annotation for turning Functions into SpringAIFunctions Add SpringAIFunctions annotation to turn Functions into ToolFunctionCallbacks Feb 13, 2024
@tzolov
Copy link
Contributor

tzolov commented Feb 14, 2024

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: b2a4f01

@tzolov tzolov closed this Feb 14, 2024
@tzolov
Copy link
Contributor

tzolov commented Feb 15, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants