Giter VIP home page Giter VIP logo

spring-petclinic-langchain4j's Introduction

Spring PetClinic Sample Application With OpenAI and Langchain4j

Understanding the Spring Petclinic application with a few diagrams

See the presentation here

Run Petclinic locally

Spring Petclinic is a Spring Boot application built using Maven. You can build a jar file and run it from the command line (it should work just as well with Java 17 or newer), Before you build the application, you need to setup some openai properties in src/main/resources/application.properties:

git clone https://github.com/showpune/spring-petclinic-langchain4j.git
cd spring-petclinic-langchain4j
mv src/main/resources/application.properties.example src/main/resources/application.properties

edit the src/main/resources/application.properties file and add the following properties:

langchain4j.azure.open-ai.chat-model.endpoint=https://*****.openai.azure.com/
langchain4j.azure.open-ai.chat-model.deployment-name=gpt-4
langchain4j.azure.open-ai.chat-model.api-key=**

You can build the application by running the following command:

./mvnw package
java -jar target/*.jar

You can then access the Petclinic at http://localhost:8080/ petclinic-screenshot

And the OpenAI chatbot at http://localhost:8080/chat.html. petclinic-screenshot

The Sequence workflow of langchain4j

image

Workthrough of the chat agent

You can talk with the agent, it can help to recommend the vet according to the symptoms of the pet. The agent can also help to book an appointment with the vet. image Go to the owner page, you can see you are registered as an owner with the help of the agent image

LLM Progamming

Normally a LLM application contains 5 parts: Prompt, Model, Memory, Native Functions( tools )and RAG (content retriever)

Prompt

The prompt is defined in agent

Model

The model is is defined in model, the model can be used for chat, or can be used for content augmentor

Memory

Memory Store: The demo still use the local memory defined in memory store, it means it can not share memory between instances, you can enhance it use memory on Redis

Memory ID: It use the username as memory id Memory ID

Interact with natives functions

The Demo provided two local tools to interactive with native functions

  1. Vets and their specialist: The agent will know the system can return list of Vets, include their specialist, it can be used to recommend a vet
  2. Owner and Pets: he agent will know the system register new owner and their pets

Content Retriever

It still use the local file as content retriever, it provided the guideline how the agent should work, which is in Term of Use, the content is ingest when the store in initialized here. If you have lots of content, tried to use the AI Search to create the RAG

Talk with Other language

You can also talk with the agent with your own language, like Chinese image

The problem is that your Term of Use is in English, the traditional way is that provide a localized term of use for each language, but you can use openAI to make it easier

We can define a Retrieval Augmentor, and translate your ask into English before you retrieve the content

License

The Spring PetClinic sample application is released under version 2.0 of the Apache License.

spring-petclinic-langchain4j's People

Contributors

renovate[bot] avatar showpune avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

spring-petclinic-langchain4j's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

html
src/main/resources/templates/chat/chat.html
  • sockjs-client 1.6.1
  • stomp.js 2.3.3
maven
pom.xml
  • org.springframework.boot:spring-boot-starter-parent 3.2.5
  • org.webjars.npm:bootstrap 5.3.3
  • org.webjars.npm:font-awesome 4.7.0
  • dev.langchain4j:langchain4j-azure-open-ai 0.30.0
  • dev.langchain4j:langchain4j-open-ai 0.30.0
  • dev.langchain4j:langchain4j 0.30.0
  • dev.langchain4j:langchain4j-embeddings-all-minilm-l6-v2 0.30.0
  • com.azure.spring:spring-cloud-azure-starter-keyvault 5.11.0
  • io.spring.javaformat:spring-javaformat-maven-plugin 0.0.41
  • org.apache.maven.plugins:maven-checkstyle-plugin 3.3.1
  • com.puppycrawl.tools:checkstyle 10.16.0
  • io.spring.nohttp:nohttp-checkstyle 0.0.11
  • org.jacoco:jacoco-maven-plugin 0.8.12
  • org.webjars.npm:bootstrap 5.3.3
  • com.gitlab.haynes:libsass-maven-plugin 0.3.1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.