Skip to content

Commit

Permalink
update spring-boot-integration.md for [add AiServiceRegisteredEvent] (l…
Browse files Browse the repository at this point in the history
…angchain4j#2203)

PR: langchain4j/langchain4j-spring#89

## Issue
original PR link:
langchain4j/langchain4j-spring#77
Issues link: langchain4j#2112

## Change
update spring-boot-integration.md for [add AiServiceRegisteredEvent]
  • Loading branch information
catofdestruction authored and edeandrea committed Jan 21, 2025
1 parent 5764a7a commit e372e34
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/docs/tutorials/spring-boot-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,29 @@ In this case, you must explicitly specify **all** components.

More details can be found [here](https://github.com/langchain4j/langchain4j-spring/blob/main/langchain4j-spring-boot-starter/src/main/java/dev/langchain4j/service/spring/AiService.java).

### Listening for AI Service Registration Events

After you have completed the development of the AI Service in a declarative manner, you can listen for the
`AiServiceRegisteredEvent` by implementing the `ApplicationListener<AiServiceRegisteredEvent>` interface.
This event is triggered when AI Service is registered in the Spring context,
allowing you to obtain information about all registered AI services and their tools at runtime.
Here is an example:
```java
@Component
class AiServiceRegisteredEventListener implements ApplicationListener<AiServiceRegisteredEvent> {


@Override
public void onApplicationEvent(AiServiceRegisteredEvent event) {
Class<?> aiServiceClass = event.aiServiceClass();
List<ToolSpecification> toolSpecifications = event.toolSpecifications();
for (int i = 0; i < toolSpecifications.size(); i++) {
System.out.printf("[%s]: [Tool-%s]: %s%n", aiServiceClass.getSimpleName(), i + 1, toolSpecifications.get(i));
}
}
}
```

## Flux

When streaming, you can use `Flux<String>` as a return type of AI Service:
Expand Down

0 comments on commit e372e34

Please sign in to comment.