-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Get all metadata of AiService & Tool when the Spring Boot s…
…tarts langchain4j/langchain4j#2112
- Loading branch information
1 parent
c6c183b
commit c7a57e7
Showing
4 changed files
with
85 additions
and
5 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
26 changes: 26 additions & 0 deletions
26
...-starter/src/main/java/dev/langchain4j/service/spring/event/AiServiceRegisteredEvent.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 dev.langchain4j.service.spring.event; | ||
|
||
import dev.langchain4j.agent.tool.ToolSpecification; | ||
import org.springframework.context.ApplicationEvent; | ||
|
||
import java.util.List; | ||
|
||
public class AiServiceRegisteredEvent extends ApplicationEvent { | ||
|
||
private final Class<?> aiServiceClass; | ||
private final List<ToolSpecification> toolSpecifications; | ||
|
||
public AiServiceRegisteredEvent(Object source, Class<?> aiServiceClass, List<ToolSpecification> toolSpecifications) { | ||
super(source); | ||
this.aiServiceClass = aiServiceClass; | ||
this.toolSpecifications = toolSpecifications; | ||
} | ||
|
||
public Class<?> getAiServiceClass() { | ||
return aiServiceClass; | ||
} | ||
|
||
public List<ToolSpecification> getToolSpecifications() { | ||
return toolSpecifications; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
.../src/main/java/dev/langchain4j/service/spring/event/AiServiceRegisteredEventListener.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 dev.langchain4j.service.spring.event; | ||
|
||
import org.springframework.context.ApplicationListener; | ||
|
||
public interface AiServiceRegisteredEventListener extends ApplicationListener<AiServiceRegisteredEvent> { | ||
} |
16 changes: 15 additions & 1 deletion
16
...ev/langchain4j/service/spring/mode/automatic/withTools/AiServiceWithToolsApplication.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 |
---|---|---|
@@ -1,12 +1,26 @@ | ||
package dev.langchain4j.service.spring.mode.automatic.withTools; | ||
|
||
import dev.langchain4j.agent.tool.ToolSpecification; | ||
import dev.langchain4j.service.spring.event.AiServiceRegisteredEvent; | ||
import dev.langchain4j.service.spring.event.AiServiceRegisteredEventListener; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
import java.util.List; | ||
|
||
@SpringBootApplication | ||
class AiServiceWithToolsApplication { | ||
class AiServiceWithToolsApplication implements AiServiceRegisteredEventListener { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AiServiceWithToolsApplication.class, args); | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(AiServiceRegisteredEvent event) { | ||
Class<?> aiServiceClass = event.getAiServiceClass(); | ||
List<ToolSpecification> toolSpecifications = event.getToolSpecifications(); | ||
for (int i = 0; i < toolSpecifications.size(); i++) { | ||
System.out.printf("[%s]: [Tool-%s]: %s%n", aiServiceClass.getSimpleName(), i + 1, toolSpecifications.get(i)); | ||
} | ||
} | ||
} |