-
Notifications
You must be signed in to change notification settings - Fork 844
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
80 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
26 changes: 26 additions & 0 deletions
26
.../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,26 @@ | ||
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]; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...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,6 @@ | ||
package org.springframework.ai.chat.client.resolver; | ||
|
||
public interface BeanNameResolver { | ||
|
||
<T> String resolveName(Class<T> beanType); | ||
} |
9 changes: 9 additions & 0 deletions
9
...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,9 @@ | ||
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