mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 06:45:50 +00:00
support for function calling on vets
This commit is contained in:
parent
6f93676ace
commit
a382e8f721
3 changed files with 29 additions and 2 deletions
|
@ -8,6 +8,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.context.annotation.Description;
|
||||
import org.springframework.samples.petclinic.owner.Owner;
|
||||
import org.springframework.samples.petclinic.owner.Pet;
|
||||
import org.springframework.samples.petclinic.vet.Vet;
|
||||
|
||||
@Configuration
|
||||
class AIFunctionConfiguration {
|
||||
|
@ -20,6 +21,14 @@ class AIFunctionConfiguration {
|
|||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Description("List the veterinarians that the pet clinic has")
|
||||
public Function<VetRequest, VetResponse> listVets(PetclinicAiProvider petclinicAiProvider) {
|
||||
return request -> {
|
||||
return petclinicAiProvider.getAllVets();
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Description("Add a pet to an owner identified by the ownerId")
|
||||
public Function<AddPetRequest, AddedPetResponse> addPetToOwner(PetclinicAiProvider petclinicAiProvider) {
|
||||
|
@ -41,3 +50,10 @@ record OwnersResponse(List<Owner> owners) {
|
|||
|
||||
record AddedPetResponse(Owner owner) {
|
||||
};
|
||||
|
||||
record VetResponse(List<Vet> vet) {
|
||||
};
|
||||
|
||||
record VetRequest(Vet vet) {
|
||||
|
||||
}
|
|
@ -5,6 +5,8 @@ import org.springframework.data.domain.PageRequest;
|
|||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.samples.petclinic.owner.Owner;
|
||||
import org.springframework.samples.petclinic.owner.OwnerRepository;
|
||||
import org.springframework.samples.petclinic.vet.Vet;
|
||||
import org.springframework.samples.petclinic.vet.VetRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
|
@ -12,8 +14,11 @@ public class PetclinicAiProvider {
|
|||
|
||||
OwnerRepository ownerRepository;
|
||||
|
||||
public PetclinicAiProvider(OwnerRepository ownerRepository) {
|
||||
VetRepository vetRepository;
|
||||
|
||||
public PetclinicAiProvider(OwnerRepository ownerRepository, VetRepository vetRepository) {
|
||||
this.ownerRepository = ownerRepository;
|
||||
this.vetRepository = vetRepository;
|
||||
}
|
||||
|
||||
public OwnersResponse getAllOwners() {
|
||||
|
@ -22,6 +27,12 @@ public class PetclinicAiProvider {
|
|||
return new OwnersResponse(ownerPage.getContent());
|
||||
}
|
||||
|
||||
public VetResponse getAllVets() {
|
||||
Pageable pageable = PageRequest.of(0, Integer.MAX_VALUE);
|
||||
Page<Vet> vetsPage = vetRepository.findAll(pageable);
|
||||
return new VetResponse(vetsPage.getContent());
|
||||
}
|
||||
|
||||
public AddedPetResponse addPetToOwner(AddPetRequest request) {
|
||||
Owner owner = ownerRepository.findById(request.ownerId());
|
||||
owner.addPet(request.pet());
|
||||
|
|
|
@ -5,5 +5,5 @@ spring.datasource.username=${POSTGRES_USER:petclinic}
|
|||
spring.datasource.password=${POSTGRES_PASS:petclinic}
|
||||
# SQL is written to be idempotent so this is safe
|
||||
spring.sql.init.mode=always
|
||||
spring.ai.azure.openai.chat.options.functions=listOwners,addPetToOwner
|
||||
spring.ai.azure.openai.chat.options.functions=listOwners,listVets,addPetToOwner
|
||||
spring.ai.azure.openai.chat.options.temperature: 0.7
|
||||
|
|
Loading…
Reference in a new issue