"place_short_info": "Beautiful Shinto shrine in the heart of Tokyo", "place_short_info": "Famous fish market where you can eat fresh sushi", Once you created the prompt ( ChatCompletionRequest) providing both the system and user messages as well as other parameters, you can send it via the OpenAiService instance: Each item of the array is another JSON object that includes 'place_name' as a text, 'place_short_info' as a text, and 'place_visit_cost' as a number.ĭon't add anything else after you respond with the JSON.Īlthough wordy and in need of optimization, this system message conveys the desired action: to suggest multiple points of interest with maximal budget utilization and to provide the response in JSON format, which is essential for the rest of the application. Respond in a JSON format, including an array named 'places'. Remember, the user must spend 90-100% of the budget. Dedicate the remainder of the budget to shopping. Allocate another 30% to shows, amusement parks, and other sightseeing. While considering that budget, you must suggest a list of places to visit.Īllocate 30% of the budget to restaurants and bars. The user will provide you with a city name and available budget. You are an API server that responds in a JSON format. The SYSTEM_TASK_MESSAGE of the BudgetJourney app looks as follows: There are “system” messages that instruct the model to behave a certain way, “assistant” messages that store previous responses, and “user” messages that carry user requests with asks. messages(.) are the actual instructions or prompts to the model.For instance, higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more deterministic. temperature(.) controls how much randomness and creativity to expect in a model’s response.model(“gpt-3.5-turbo”) is an optimized version of the GPT-3.5 model.New ChatMessage("user", String.format("I want to visit %s and have a budget of %d dollars", city, budget)))) New ChatMessage("system", SYSTEM_TASK_MESSAGE), Add the latest OpenAI Java artifact to your pom.xml file.ĬhatCompletionRequest chatCompletionRequest = ChatCompletionRequest.Here’s how you get started with the library: The open-source OpenAI Java library implements the GPT-3.5 HTTP APIs, making it easy to communicate with the service via well-defined Java abstractions. The model then returns the suggestions in a JSON format. The app asks the model to suggest several points of interest within a city while considering budget constraints. Our BudgetJourney app uses the GPT-3.5 model which understands and generates natural language or code. Presently, the service supports several models that can understand and generate natural language, code, images, or convert audio into text. You need to create an account, get your token (i.e., API key) and use that token while sending requests to one of the OpenAI models.Ī model in the context of OpenAI is a computational construct trained on a large dataset to recognize patterns, make predictions, or perform specific tasks based on input data. The OpenAI engine can be queried via the HTTP API. Now, let’s see how the app communicates with the Open AI engine (step 4) and how using the database (step 3) makes the solution scalable and cost-effective. The response is stored in YugabyteDB for future reference and sent back to the user. Otherwise, Spring Boot connects to the OpenAI APIs to get recommendations from the neural network.If the data is already in the database, the response is sent back to the user. Spring Boot connects to a YugabyteDB database instance to check if there are already any suggestions for the requested city and budget.Vaadin connects to a Spring Boot backend when users want to get recommendations for a specific city and budget.The users open a BudgetJourney web UI that runs on Vaadin.The architecture of the BudgetJourney app looks as follows: The app can suggest multiple points of interest within a city, tailored to fit specific budget constraints. Let’s help users get the most out of their trips by building a simple Java application called BudgetJourney. How should you spend the money and make your trip memorable? This is an excellent question to delegate to the OpenAI engine. Imagine you want to visit a city and have a specific budget in mind. Whether you prefer reading or watching, let’s review how to start using the OpenAI GPT engine in your Java projects in a scalable way, by sending prompts to the engine only when necessary: One of the more notable aspects of ChatGPT is its engine, which not only powers the web-based chatbot but can also be integrated into your Java applications.
0 Comments
Leave a Reply. |