applied spring formatter, temp removed gradle to support deployment with buildpacks

This commit is contained in:
Oded Shopen 2024-09-10 21:34:58 +03:00
parent 2371f6af56
commit 6f93676ace
10 changed files with 97 additions and 35 deletions

View file

@ -0,0 +1,25 @@
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: petclinic-route
annotations:
healthcheck.gslb.tanzu.vmware.com/service: spring-petclinic
healthcheck.gslb.tanzu.vmware.com/path: /
healthcheck.gslb.tanzu.vmware.com/port: "80"
spec:
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: default-gateway
sectionName: http-petclinic
rules:
- backendRefs:
- group: ""
kind: Service
name: spring-petclinic
port: 8080
weight: 1
matches:
- path:
type: PathPrefix
value: /

View file

@ -0,0 +1,18 @@
apiVersion: apps.tanzu.vmware.com/v1
kind: ContainerApp
metadata:
creationTimestamp: null
name: spring-petclinic
spec:
nonSecretEnv:
- name: SPRING_PROFILES_ACTIVE
value: postgres-openai
build:
buildpacks: {}
nonSecretEnv:
- name: BP_JVM_VERSION
value: "17"
path: ../..
ports:
- name: main
port: 8080

View file

@ -12,24 +12,32 @@ import org.springframework.samples.petclinic.owner.Pet;
@Configuration
class AIFunctionConfiguration {
@Bean
@Description("List the owners that the pet clinic has")
public Function<OwnerRequest, OwnersResponse> listOwners(PetclinicAiProvider petclinicAiProvider) {
return request -> {
return petclinicAiProvider.getAllOwners();
};
}
@Bean
@Description("List the owners that the pet clinic has")
public Function<OwnerRequest, OwnersResponse> listOwners(PetclinicAiProvider petclinicAiProvider) {
return request -> {
return petclinicAiProvider.getAllOwners();
};
}
@Bean
@Description("Add a pet to an owner identified by the ownerId")
public Function<AddPetRequest, AddedPetResponse> addPetToOwner(PetclinicAiProvider petclinicAiProvider) {
return request -> {
return petclinicAiProvider.addPetToOwner(request);
};
}
@Bean
@Description("Add a pet to an owner identified by the ownerId")
public Function<AddPetRequest, AddedPetResponse> addPetToOwner(PetclinicAiProvider petclinicAiProvider) {
return request -> {
return petclinicAiProvider.addPetToOwner(request);
};
}
}
record AddPetRequest (Pet pet, Integer ownerId) {};
record OwnerRequest (Owner owner) {};
record OwnersResponse(List<Owner> owners) {};
record AddedPetResponse(Owner owner) {};
record AddPetRequest(Pet pet, Integer ownerId) {
};
record OwnerRequest(Owner owner) {
};
record OwnersResponse(List<Owner> owners) {
};
record AddedPetResponse(Owner owner) {
};

View file

@ -12,4 +12,5 @@ public class LoggingAdvisor implements RequestResponseAdvisor {
System.out.println("Request: " + request);
return request;
}
}

View file

@ -8,13 +8,15 @@ import org.springframework.web.client.RestClient;
@Configuration
public class PetclinicAIConfiguration {
@Bean
public RestClient restClient() {
return RestClient.create();
}
@Bean
public ChatMemory chatMemory() {
return new InMemoryChatMemory();
}
}

View file

@ -9,18 +9,19 @@ import org.springframework.stereotype.Service;
@Service
public class PetclinicAiProvider {
OwnerRepository ownerRepository;
public PetclinicAiProvider(OwnerRepository ownerRepository) {
this.ownerRepository = ownerRepository;
this.ownerRepository = ownerRepository;
}
public OwnersResponse getAllOwners() {
Pageable pageable = PageRequest.of(0, Integer.MAX_VALUE);
Page<Owner> ownerPage = ownerRepository.findAll(pageable);
return new OwnersResponse(ownerPage.getContent());
Pageable pageable = PageRequest.of(0, Integer.MAX_VALUE);
Page<Owner> ownerPage = ownerRepository.findAll(pageable);
return new OwnersResponse(ownerPage.getContent());
}
public AddedPetResponse addPetToOwner(AddPetRequest request) {
Owner owner = ownerRepository.findById(request.ownerId());
owner.addPet(request.pet());

View file

@ -9,24 +9,25 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/")
public class PetclinicChatClient {
// ChatModel is the primary interfaces for interacting with an LLM
// it is a request/response interface that implements the ModelModel
// interface. Make suer to visit the source code of the ChatModel and
// checkout the interfaces in the core spring ai package.
private final ChatClient chatClient;
// ChatModel is the primary interfaces for interacting with an LLM
// it is a request/response interface that implements the ModelModel
// interface. Make suer to visit the source code of the ChatModel and
// checkout the interfaces in the core spring ai package.
private final ChatClient chatClient;
public PetclinicChatClient(ChatClient.Builder builder, ChatMemory chatMemory) {
public PetclinicChatClient(ChatClient.Builder builder, ChatMemory chatMemory) {
// @formatter:off
this.chatClient = builder
.defaultSystem("""
You are a friendly AI assistant designed to help with the management of a veterinarian pet clinic called Spring Petclinic.
Your job is to answer questions about the existing veterinarians and to perform actions on the customer's behalf, mainly around
You are a friendly AI assistant designed to help with the management of a veterinarian pet clinic called Spring Petclinic.
Your job is to answer questions about the existing veterinarians and to perform actions on the customer's behalf, mainly around
pet owners, their pets and their visits.
You are required to answer an a professional manner. If you don't know the answer, politely tell the customer
You are required to answer an a professional manner. If you don't know the answer, politely tell the customer
you don't know the answer, then ask the customer a followup qusetion to try and clarify the question they are asking.
If you do know the answer, provide the answer but do not provide any additional helpful followup questions.
""")

6
tanzu.yml Normal file
View file

@ -0,0 +1,6 @@
apiVersion: config.tanzu.vmware.com/v1
configuration:
dev:
paths:
- .tanzu/config/
kind: TanzuConfig