-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../java/org/springframework/ai/chat/client/resolver/ApplicationContextBeanNameResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.springframework.ai.chat.client.resolver; | ||
|
||
import org.springframework.beans.factory.config.BeanDefinition; | ||
import org.springframework.context.support.GenericApplicationContext; | ||
import org.springframework.util.Assert; | ||
|
||
public class ApplicationContextBeanNameResolver implements BeanNameResolver { | ||
|
||
private final GenericApplicationContext context; | ||
|
||
public ApplicationContextBeanNameResolver(GenericApplicationContext context) { | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public <T> String resolveName(Class<T> beanType) { | ||
String[] namesForType = context.getBeanNamesForType(beanType); | ||
Assert.isTrue(namesForType.length == 1, "A bean must have a unique definiton"); | ||
|
||
/* | ||
* The following snippet could be used in other places to resolve the description | ||
* from a function registered as a bean BeanDefinition beanDefinition = | ||
* context.getBeanDefinition(namesForType[0]); String description = | ||
* beanDefinition.getDescription(); | ||
*/ | ||
|
||
return namesForType[0]; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...g-ai-core/src/main/java/org/springframework/ai/chat/client/resolver/BeanNameResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.springframework.ai.chat.client.resolver; | ||
|
||
public interface BeanNameResolver { | ||
|
||
<T> String resolveName(Class<T> beanType); | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...ai-core/src/main/java/org/springframework/ai/chat/client/resolver/SimpleNameResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.springframework.ai.chat.client.resolver; | ||
|
||
public class SimpleNameResolver implements BeanNameResolver { | ||
|
||
@Override | ||
public <T> String resolveName(Class<T> beanType) { | ||
return beanType.getSimpleName().substring(0, 1).toLowerCase() + beanType.getSimpleName().substring(1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters