LangChain for Java: Supercharge your Java application with the power of LLMs
Prerequisite
public class ApiKeys {public static final String MY_OPENAI_API_KEY ="<YOU MUST HERE PUT YOUR API KEY>";}
Assistant Mode
@Testpublic void testChatWithHRAI() throws Exception {Random r = new Random();int userNo = r.nextInt(100);// PlanChatLanguageModel model = OpenAiChatModel.builder().apiKey(ApiKeys.MY_OPENAI_API_KEY).modelName(OpenAiModelName.GPT_3_5_TURBO).timeout(ofSeconds(900)).temperature(0.9).build();
- OpenAiChatModel.builder(): This creates a new builder for the OpenAiChatModel class.
- .apiKey(ApiKeys.MY_OPENAI_API_KEY): Sets the API key for the OpenAI model. You need to replace ApiKeys.MY_OPENAI_API_KEY with your actual OpenAI API key.
- .modelName(OpenAiModelName.GPT_3_5_TURBO): Sets the model name to GPT-3.5 Turbo. This specifies the version of the OpenAI language model you want to use.
- .timeout(ofSeconds(900)): Sets the timeout for the API call to 900 seconds (15 minutes). This means that if the API call takes longer than 15 minutes, it will be aborted.
- .temperature(0.9): Sets the temperature parameter for sampling. A higher temperature (e.g., 0.9) makes the output more random, while a lower temperature (e.g., 0.2) makes the output more focused and deterministic.
- .build(): Builds the ChatLanguageModel instance with the specified configurations.
Assistant assistant = AiServices.builder(Assistant.class).chatLanguageModel(model).chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10)).build();
- AiServices.builder(Assistant.class): This creates a builder for the Assistant class within the AiServices utility.
- .chatLanguageModel(model): Sets the ChatLanguageModel for the assistant. The model here is the ChatLanguageModel instance that you created in the previous code block.
- .chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10)): Sets the chat memory provider for the assistant. It uses a lambda expression to create a MessageWindowChatMemory with a maximum of 10 messages. This means that the assistant will keep track of the conversation history, and in this case, it will retain the last 10 messages.
- .build(): Builds the Assistant instance with the specified configurations.
// a) create types for retrieving skills objects from responsesSkillExtractor skillExtractor = AiServices.create(SkillExtractor.class, model);
static class SkillReference {@Description("the name of this skill")private String name;@Description("description of this skill. please make it selling and not more than 10 lines of text")private String description;//...}
- AiServices.create(SkillExtractor.class, model): This creates an instance of the SkillExtractor class using the AiServices utility. It takes the SkillExtractor class as a parameter and the model (presumably the ChatLanguageModel instance) as another parameter.
- static class SkillReference: This declares a static nested class named SkillReference. This class has two fields (name and description) with corresponding @Description annotations. These annotations might be used for documentation or metadata purposes.
// b) simulate a chatString appendPrompt = "Answer acting as a friendly HR Consultant helping the user with his/her competence mapping, focussing on skills and projects."+"Structure the answer friendly and selling with bullets for discovered or suggested supporting skills and potential typical projects"+"where the user may have used those skills. " +"Limit answer to the most relevant 5 skills and top 8 projects";
String q1 = "Yes, I do work with Java and java microservices on the backend ";
System.out.println("me: " + q1);
String res1 = assistant.chat(userNo, q1 + appendPrompt);
System.out.println(res1);
Skill extractedSkills1 = skillExtractor.extractSkillFrom(res1);
System.out.println("\n\n1. Skill mapped:" + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(extractedSkills1) + "\n\n");
The assistant is defined this way:
interface Assistant {
String chat(@MemoryId int memoryId, @UserMessage String userMessage);
}
me: Yes, I do work with Java and java microservices on the backendSkills:- Java programming: Experience in Java programming is essential for working with Java microservices on the backend. This includes a deep understanding of object-oriented programming concepts, data structures, and algorithms.- Spring Framework: Knowledge of the Spring Framework is vital for developing Java microservices. This includes proficiency in Spring Boot, Spring Data, and Spring Cloud.- RESTful API development: Understanding how to design and develop RESTful APIs is necessary for creating microservices. This involves knowledge of HTTP, JSON, and API documentation tools like Swagger.- Containerization and orchestration: Proficiency in containerization technologies like Docker and container orchestration platforms like Kubernetes is crucial for scaling and managing microservices in a distributed environment.- Database management: Having experience with relational databases like MySQL or PostgreSQL, as well as NoSQL databases like MongoDB or Redis, is important for storing and retrieving data in microservices.Projects:1. Building a microservices-based e-commerce platform: Developing a scalable and fault-tolerant e-commerce platform using Java microservices, Spring Boot, and containerization technologies like Docker. Implementing RESTful APIs for product catalog management, order processing, and payment integration.2. Creating a social media analytics system: Designing a system to analyze and process large volumes of social media data using Java microservices, Spring Cloud, and Apache Kafka for stream processing. Implementing sentiment analysis, trend detection, and user engagement metrics.3. Developing a microservices-based banking application: Building a secure and highly available banking application using Java microservices, Spring Boot, and container orchestration with Kubernetes. Creating APIs for account management, transaction processing, and fraud detection.4. Building a document management system: Creating a system to store and manage documents using Java microservices, Spring Data, and Elasticsearch for full-text search capabilities. Implementing features like document versioning, access control, and document tagging.5. Designing a real-time chat application: Developing a real-time messaging application using Java microservices, Spring Boot, and WebSocket technology. Implementing features like chat rooms, private messaging, and message history.6. Building a microservices-based healthcare platform: Designing a platform for managing patient records, appointments, and healthcare providers using Java microservices, Spring Cloud, and a combination of relational and NoSQL databases. Implementing secure authentication, data encryption, and integration with external healthcare systems.7. Creating a recommendation system: Developing a recommendation engine using Java microservices, Spring Boot, and machine learning algorithms. Implementing personalized recommendations based on user preferences, purchase history, and browsing behavior.8. Building a microservices-based travel booking system: Designing a system for managing travel bookings, flight reservations, and hotel accommodations using Java microservices, Spring Cloud, and messaging queues like RabbitMQ. Implementing features like real-time availability updates, payment processing, and itinerary generation.Note: These suggested projects are not exhaustive but provide a range of examples where the mentioned skills could be utilized.1. Skill mapped:{"name" : "Java programming","description" : "Java programming is a crucial skill for working with Java microservices on the backend. With a deep understanding of object-oriented programming concepts, data structures, and algorithms, you'll be able to develop robust and efficient microservices. Java's versatility and extensive libraries make it a popular choice among developers worldwide, ensuring ample resources and community support.","listOfCandidateSkillDefinitions" : [ {"name" : null,"description" : null}, {"name" : null,"description" : null}, {"name" : null,"description" : null} ]}
Translator Mode
Hovedutvikler, Teknisk arkitekt: Utviklet flere kjernekomponenter i PasientSky-plattformen, inkludert kommunikasjonsmodul mot norske helsemyndigheter, topologimodul for klinisk diagnose (ICPC2, CDC10 og SNOWMED), produktmodul (medisiner og reseptvarer) m.m. Teknisk arkitekt, Kvalitetssikrer.
Parse PDF Resume and get skills
@Testpublic void testParseOSDResumeWithAIProducingSkillDefinitions() throws Exception {helper = new SkillDefinitionHelper();Map<String, List<SimplifiedSkill>> resultMap = new HashMap<>();// PLanChatLanguageModel model = OpenAiChatModel.builder().apiKey(ApiKeys.MY_OPENAI_API_KEY).modelName(OpenAiModelName.GPT_4).timeout(ofSeconds(900)).temperature(0.6).build();Assistant assistant = AiServices.builder(Assistant.class).chatLanguageModel(model).chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10)).build();// a) Get list of PDF ResumesList<Resource> resourceList = getPDFResources();String appendPrompt = "Extract the users skills from this resume. Present the result as structured " +"json data in the following json format " + jsonSkillDefinition + " keep the name of the skill short";int n = 0;boolean RUN_FULL_REGRESSON = true;int found_and_swapped = 0;int not_found = 0;if (RUN_FULL_REGRESSON) {for (Resource resource : resourceList) {try {File file = resource.getFile();PDDocument document = Loader.loadPDF(file);PDFTextStripper stripper = new PDFTextStripper();String text = stripper.getText(document);//System.out.println(n + " Input data extracted from pdf resume:\n" + text + "\n\n");String res0 = assistant.chat(n, text + appendPrompt);//System.out.println(n + " Generated JSON SkillDefinitions:" + n++ + "\n\n" + res0 + "\n\n");List<SimplifiedSkill> simplifiedSkills = mapper.readValue(res0, new TypeReference<List<SimplifiedSkill>>() {});System.out.println("Mapped skill definitions:" + simplifiedSkills.size() + " for pdf:" + resource.getFilename() + "\n\n\n");List<SimplifiedSkill> enhancedSkillList = helper.getEnhancedSkillDefinitions(simplifiedSkills);resultMap.put(resource.getFilename(), simplifiedSkills);resultMap.put(resource.getFilename() + "-enhanced", enhancedSkillList);} catch (Exception e) {System.out.println("Exception handling " + resource.getFilename() + " - Stacktrace:" + Arrays.toString(e.getStackTrace()));}}}System.out.println(resultMap);}
[{"name": "C language","description": "Proficiency in C language, a popular programming language in software development.","isPublic": false,"currentVersion": 1,"additionaljsonproperties": null,"public": false},{"name": "Javascript","description": "Knowledge in Javascript, a programming language used primarily for web development.","isPublic": false,"currentVersion": 1,"additionaljsonproperties": null,"public": false},{"name": "HTML","description": "Proficiency in HTML, a standard language for designing and creating websites.","isPublic": false,"currentVersion": 1,"additionaljsonproperties": null,"public": false},{"name": "CSS","description": "Knowledge in CSS, a style sheet language used for describing the look and formatting of a document written in HTML.","isPublic": false,"currentVersion": 1,"additionaljsonproperties": null,"public": false},{"name": "Microsoft Excel","description": "Skills in Microsoft Excel, a spreadsheet program used to store and process data.","isPublic": false,"currentVersion": 1,"additionaljsonproperties": null,"public": false},{"name": "Microsoft Word","description": "Proficiency in Microsoft Word, a word processing software used to create, edit, and print documents.","isPublic": false,"currentVersion": 1,"additionaljsonproperties": null,"public": false},{"name": "PowerPoint","description": "Skills in PowerPoint, a presentation program used for creating slideshow presentations.","isPublic": false,"currentVersion": 1,"additionaljsonproperties": null,"public": false},{"name": "Graphic Design","description": "Experience in freelance graphic design, including creating social media, logos, and image editing.","isPublic": false,"currentVersion": 1,"additionaljsonproperties": null,"public": false},{"name": "Customer Service","description": "Experience in customer service roles, including working as a waiter, cashier, and attendant.","isPublic": false,"currentVersion": 1,"additionaljsonproperties": null,"public": false}]