Skip to content
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

[WIP] Add possibility to register functions in a type-safe manner #787

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pgerhard
Copy link
Contributor

@pgerhard pgerhard commented May 29, 2024

Goal: The goal of this PR is to extend the existing function registration methods to also accept types of beans. The advantage would be that this is type-safe. A type-safe interface improves intelli-sense and refactoring

Things to Do:

  • Testing, before implementing any tests I would be interest in receiving feedback the approach in general

Discussion Points for this PR:

Should there be multiple factory methods for the ChatClient.Builder? So far I've overloaded the existing factory method and provided a SimpleNameResolver for use in existing calls

General Design Question:

At a higher level I am also wondering about how to register functions in general. The existing model make heavy use of annotations and conventions (e.g. a function must be a java.util.Function). This clearly works, however issues non-obvious issues (e.g. missing @Description annotation) are discovered at runtime. Personally I feel that this is not a great developer experience, especially for people new to the using spring-ai. My preference would be to surface this kind of errors as quickly as possible. A way to address this could be to provide an interface that has to be implemented by beans that should be available as functions for the LLM

@pgerhard pgerhard force-pushed the typesafe-functions branch 2 times, most recently from 6fa6f9f to fe827f9 Compare May 29, 2024 13:58
…hatClient

The advantage of this annotation over the existing approach is that it forces the definition of a description. Thereby reducing surprising errors at runtime and shortening feedback cycles for developers. This works with the existing code base
Created a new factory class that centralises the creation of Tools. It provides and API for creating Tools by
- name
- lambda
- bean type
@pgerhard
Copy link
Contributor Author

pgerhard commented Jun 5, 2024

Hi Christian (@tzolov),

As discussed i've updated the PR with a way to define functions via a factory class. Compared to my initial implementation using the BeanNameResolver this feels like a more consistent approach.
However, as I mentioned in my comment (see Tools) the different ways that functions are currently handled by the ChatClient makes this more difficult to do. I think a discussion around how we can have a more consistent approach to adding functions to the ChatClient might be helpful
If you have some time to discuss this just let me know (also open to jumping on a call)

@tzolov tzolov self-assigned this Jun 21, 2024
@csterwa csterwa mentioned this pull request Sep 12, 2024
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants