This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git
commit cae5aeb46f55a967b1652b5d9a1e434a3f0482b4 Author: Alexandre Gallice <[email protected]> AuthorDate: Fri Jan 16 08:34:56 2026 +0100 data-extract: Upgrade to granite 4 --- data-extract-langchain4j/README.adoc | 8 ++++---- .../extraction/CustomPojoExtractionService.java | 3 ++- .../src/main/resources/application.properties | 2 +- .../org/acme/extraction/OllamaTestResource.java | 2 +- ..._chat-3867080e-87d5-40d6-b9a8-b90817d980f9.json | 24 ---------------------- ..._chat-3ac79428-f534-4e6a-aa8f-8e401ac22256.json | 24 ---------------------- ..._chat-4b63856f-cac5-4bc1-b66a-d01255ac40e0.json | 24 ++++++++++++++++++++++ ...chat-be38bae8-7817-4141-8b20-2cff30446e53.json} | 10 ++++----- ..._chat-e8f3defd-bdcb-47f4-8782-687fd3cae6d1.json | 24 ++++++++++++++++++++++ 9 files changed, 61 insertions(+), 60 deletions(-) diff --git a/data-extract-langchain4j/README.adoc b/data-extract-langchain4j/README.adoc index 02721a07..0a642898 100644 --- a/data-extract-langchain4j/README.adoc +++ b/data-extract-langchain4j/README.adoc @@ -15,7 +15,7 @@ In this example, we'll convert those text conversations into Java Objects that c image::schema.png[] In order to achieve this extraction, we'll need a https://en.wikipedia.org/wiki/Large_language_model[Large Language Model (LLM)] and related serving framework that natively supports https://ollama.com/blog/structured-outputs[JSON structured output]. -Here, we choose https://ollama.com/library/granite3.3:2b[granite3.3:2b] served through https://ollama.com/[ollama] as it seems compute friendly and under Apache V2 license. +Here, we choose https://ollama.com/library/granite4:3b-h[granite4:3b-h] served through https://ollama.com/[ollama] as it seems compute friendly and under Apache V2 license. In order to request inference to the served model, we'll use the high-level LangChain4j APIs like https://docs.langchain4j.dev/tutorials/ai-services[AiServices]. === Start the Large Language Model @@ -24,21 +24,21 @@ Let's start a container to serve the LLM with Ollama, in a first shell type: [source,shell] ---- -docker run --rm -it -v cqex-data-extract-ollama:/root/.ollama -p 11434:11434 --name cqex-data-extract-ollama ollama/ollama:0.9.3 +docker run --rm -it -v cqex-data-extract-ollama:/root/.ollama -p 11434:11434 --name cqex-data-extract-ollama ollama/ollama:0.14.1 ---- After a moment, a log like below should be output: [source,shell] ---- -time=2026-01-06T14:21:55.578Z level=INFO source=types.go:130 msg="inference compute" id=0 library=cpu variant="" compute="" driver=0.0 name="" total="62.2 GiB" available="49.9 GiB" +time=2026-01-07T14:28:19.092Z level=INFO source=types.go:60 msg="inference compute" id=cpu library=cpu compute="" name=cpu description=cpu libdirs=ollama driver="" pci_id="" type="" total="62.2 GiB" available="62.2 GiB" ---- Then, download the codellama model, in a second shell type: [source,shell] ---- -docker exec -it cqex-data-extract-ollama ollama pull granite3.3:2b +docker exec -it cqex-data-extract-ollama ollama pull granite4:3b-h ---- After a moment, log like below should be output: diff --git a/data-extract-langchain4j/src/main/java/org/acme/extraction/CustomPojoExtractionService.java b/data-extract-langchain4j/src/main/java/org/acme/extraction/CustomPojoExtractionService.java index 82fad99e..5a8a7994 100644 --- a/data-extract-langchain4j/src/main/java/org/acme/extraction/CustomPojoExtractionService.java +++ b/data-extract-langchain4j/src/main/java/org/acme/extraction/CustomPojoExtractionService.java @@ -53,7 +53,8 @@ public interface CustomPojoExtractionService { String CUSTOM_POJO_EXTRACT_PROMPT = "Extract information about a customer from the transcript delimited by triple backticks: ```{{text}}```." + "The customerBirthday field should be formatted as {{dateFormat}}." + "The summary field should concisely relate the customer main ask." - + "Source any extracted field values from what is explicitly mentioned in the transcript."; + + "Source any extracted field values from what is explicitly mentioned in the transcript." + + "Extracted field values should be as accurate as possible."; /** * The text and dateFormat parameters of this method are automatically injected as {{text}} & {{dateFormat}} in the diff --git a/data-extract-langchain4j/src/main/resources/application.properties b/data-extract-langchain4j/src/main/resources/application.properties index 29386679..0d258925 100644 --- a/data-extract-langchain4j/src/main/resources/application.properties +++ b/data-extract-langchain4j/src/main/resources/application.properties @@ -20,4 +20,4 @@ quarkus.default-locale=en_US # Adjust as per your where your Ollama instance is running langchain4j.ollama.base-url=http://localhost:11434 # The chat model to use -langchain4j.ollama.chat-model.model-id=granite3.3:2b +langchain4j.ollama.chat-model.model-id=granite4:3b-h diff --git a/data-extract-langchain4j/src/test/java/org/acme/extraction/OllamaTestResource.java b/data-extract-langchain4j/src/test/java/org/acme/extraction/OllamaTestResource.java index 7a3ad63a..a1b32a0c 100644 --- a/data-extract-langchain4j/src/test/java/org/acme/extraction/OllamaTestResource.java +++ b/data-extract-langchain4j/src/test/java/org/acme/extraction/OllamaTestResource.java @@ -36,7 +36,7 @@ public class OllamaTestResource implements QuarkusTestResourceLifecycleManager { private static final Logger LOG = LoggerFactory.getLogger(OllamaTestResource.class); - private static final String OLLAMA_IMAGE = "ollama/ollama:0.9.3"; + private static final String OLLAMA_IMAGE = "ollama/ollama:0.14.1"; private static final int OLLAMA_SERVER_PORT = 11434; private static final String MODE_MOCK = "mock"; diff --git a/data-extract-langchain4j/src/test/resources/mappings/api_chat-3867080e-87d5-40d6-b9a8-b90817d980f9.json b/data-extract-langchain4j/src/test/resources/mappings/api_chat-3867080e-87d5-40d6-b9a8-b90817d980f9.json deleted file mode 100644 index deacf720..00000000 --- a/data-extract-langchain4j/src/test/resources/mappings/api_chat-3867080e-87d5-40d6-b9a8-b90817d980f9.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "id" : "3867080e-87d5-40d6-b9a8-b90817d980f9", - "name" : "api_chat", - "request" : { - "url" : "/api/chat", - "method" : "POST", - "bodyPatterns" : [ { - "equalToJson" : "{\n \"model\" : \"granite3.3:2b\",\n \"messages\" : [ {\n \"role\" : \"user\",\n \"content\" : \"Extract information about a customer from the transcript delimited by triple backticks: ```Operator: Hello, how may I help you ?\\nCustomer: Hello, I'm calling because I need to declare an accident on my main vehicle.\\nOperator: Ok, can you please give me your name ?\\nCustomer: My name is Sarah London.\\nOperator: Could you please give me your birth date ?\\nC [...] - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } ] - }, - "response" : { - "status" : 200, - "body" : "{\"model\":\"granite3.3:2b\",\"created_at\":\"2025-12-18T13:25:30.629932212Z\",\"message\":{\"role\":\"assistant\",\"content\":\"{\\n \\\"customerSatisfied\\\": true,\\n \\\"customerName\\\": \\\"Sarah London\\\",\\n \\\"customerBirthday\\\": {\\\"year\\\": 1986, \\\"month\\\": 7, \\\"day\\\": 10},\\n \\\"summary\\\": \\\"The customer, Sarah London, is calling to declare an accident and seek reimbursement for related expenses.\\\"\\n}\"},\"done_reason\":\"stop\",\"done\ [...] - "headers" : { - "Date" : "Thu, 18 Dec 2025 13:25:30 GMT", - "Content-Type" : "application/json; charset=utf-8" - } - }, - "uuid" : "3867080e-87d5-40d6-b9a8-b90817d980f9", - "persistent" : true, - "insertionIndex" : 6 -} \ No newline at end of file diff --git a/data-extract-langchain4j/src/test/resources/mappings/api_chat-3ac79428-f534-4e6a-aa8f-8e401ac22256.json b/data-extract-langchain4j/src/test/resources/mappings/api_chat-3ac79428-f534-4e6a-aa8f-8e401ac22256.json deleted file mode 100644 index 8b687b63..00000000 --- a/data-extract-langchain4j/src/test/resources/mappings/api_chat-3ac79428-f534-4e6a-aa8f-8e401ac22256.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "id" : "3ac79428-f534-4e6a-aa8f-8e401ac22256", - "name" : "api_chat", - "request" : { - "url" : "/api/chat", - "method" : "POST", - "bodyPatterns" : [ { - "equalToJson" : "{\n \"model\" : \"granite3.3:2b\",\n \"messages\" : [ {\n \"role\" : \"user\",\n \"content\" : \"Extract information about a customer from the transcript delimited by triple backticks: ```Operator: Hello, how may I help you?\\nCustomer: Hello, I am currently at the police station because I've got an accident. The police would need a proof that I have an insurance. Could you please help me?\\nOperator: Sure, could you please remind me your name and birth dat [...] - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } ] - }, - "response" : { - "status" : 200, - "body" : "{\"model\":\"granite3.3:2b\",\"created_at\":\"2025-12-18T13:25:52.676173019Z\",\"message\":{\"role\":\"assistant\",\"content\":\"{\\n \\\"customerSatisfied\\\": true,\\n \\\"customerName\\\": \\\"Kate Boss\\\",\\n \\\"customerBirthday\\\": {\\\"year\\\": 1999, \\\"month\\\": 8, \\\"day\\\": 13},\\n \\\"summary\\\": \\\"The customer, Kate Boss, needed to provide proof of insurance at the police station due to an accident. Initially, there was a misunderstanding regarding [...] - "headers" : { - "Date" : "Thu, 18 Dec 2025 13:25:52 GMT", - "Content-Type" : "application/json; charset=utf-8" - } - }, - "uuid" : "3ac79428-f534-4e6a-aa8f-8e401ac22256", - "persistent" : true, - "insertionIndex" : 4 -} \ No newline at end of file diff --git a/data-extract-langchain4j/src/test/resources/mappings/api_chat-4b63856f-cac5-4bc1-b66a-d01255ac40e0.json b/data-extract-langchain4j/src/test/resources/mappings/api_chat-4b63856f-cac5-4bc1-b66a-d01255ac40e0.json new file mode 100644 index 00000000..12285be4 --- /dev/null +++ b/data-extract-langchain4j/src/test/resources/mappings/api_chat-4b63856f-cac5-4bc1-b66a-d01255ac40e0.json @@ -0,0 +1,24 @@ +{ + "id" : "4b63856f-cac5-4bc1-b66a-d01255ac40e0", + "name" : "api_chat", + "request" : { + "url" : "/api/chat", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\n \"model\" : \"granite4:3b-h\",\n \"messages\" : [ {\n \"role\" : \"user\",\n \"content\" : \"Extract information about a customer from the transcript delimited by triple backticks: ```Operator: Hello, how may I help you ?\\nCustomer: Hello, I'm calling because I need to declare an accident on my main vehicle.\\nOperator: Ok, can you please give me your name ?\\nCustomer: My name is Sarah London.\\nOperator: Could you please give me your birth date ?\\nC [...] + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 200, + "body" : "{\"model\":\"granite4:3b-h\",\"created_at\":\"2026-01-15T15:03:26.59496985Z\",\"message\":{\"role\":\"assistant\",\"content\":\"{\\n \\\"customerSatisfied\\\": true,\\n \\\"customerName\\\": \\\"Sarah London\\\",\\n \\\"customerBirthday\\\": {\\\"year\\\": 1986, \\\"month\\\": 7, \\\"day\\\": 10},\\n \\\"summary\\\": \\\"The customer, Sarah London, called to declare an accident on her main vehicle. The operator confirmed that all expenses linked to the accident would be [...] + "headers" : { + "Date" : "Thu, 15 Jan 2026 15:03:26 GMT", + "Content-Type" : "application/json; charset=utf-8" + } + }, + "uuid" : "4b63856f-cac5-4bc1-b66a-d01255ac40e0", + "persistent" : true, + "insertionIndex" : 6 +} \ No newline at end of file diff --git a/data-extract-langchain4j/src/test/resources/mappings/api_chat-4a005fe6-e449-482d-8ce6-8c341fa4cb9f.json b/data-extract-langchain4j/src/test/resources/mappings/api_chat-be38bae8-7817-4141-8b20-2cff30446e53.json similarity index 52% rename from data-extract-langchain4j/src/test/resources/mappings/api_chat-4a005fe6-e449-482d-8ce6-8c341fa4cb9f.json rename to data-extract-langchain4j/src/test/resources/mappings/api_chat-be38bae8-7817-4141-8b20-2cff30446e53.json index 269fdb3b..f72b3e9e 100644 --- a/data-extract-langchain4j/src/test/resources/mappings/api_chat-4a005fe6-e449-482d-8ce6-8c341fa4cb9f.json +++ b/data-extract-langchain4j/src/test/resources/mappings/api_chat-be38bae8-7817-4141-8b20-2cff30446e53.json @@ -1,24 +1,24 @@ { - "id" : "4a005fe6-e449-482d-8ce6-8c341fa4cb9f", + "id" : "be38bae8-7817-4141-8b20-2cff30446e53", "name" : "api_chat", "request" : { "url" : "/api/chat", "method" : "POST", "bodyPatterns" : [ { - "equalToJson" : "{\n \"model\" : \"granite3.3:2b\",\n \"messages\" : [ {\n \"role\" : \"user\",\n \"content\" : \"Extract information about a customer from the transcript delimited by triple backticks: ```Operator: Hello, how may I help you ?\\nCustomer: Hello, I'm John. I need to share a problem with you. Actually, the insurance has reimbursed only half the money I have spent due to the accident.\\nOperator: Hello John, could you please give me your last name so that I can [...] + "equalToJson" : "{\n \"model\" : \"granite4:3b-h\",\n \"messages\" : [ {\n \"role\" : \"user\",\n \"content\" : \"Extract information about a customer from the transcript delimited by triple backticks: ```Operator: Hello, how may I help you ?\\nCustomer: Hello, I'm John. I need to share a problem with you. Actually, the insurance has reimbursed only half the money I have spent due to the accident.\\nOperator: Hello John, could you please give me your last name so that I can [...] "ignoreArrayOrder" : true, "ignoreExtraElements" : true } ] }, "response" : { "status" : 200, - "body" : "{\"model\":\"granite3.3:2b\",\"created_at\":\"2025-12-18T13:25:40.569059754Z\",\"message\":{\"role\":\"assistant\",\"content\":\"{\\n \\\"customerSatisfied\\\": false,\\n \\\"customerName\\\": \\\"John Doe\\\",\\n \\\"customerBirthday\\\": {\\\"year\\\": 2001, \\\"month\\\": 11, \\\"day\\\": 1},\\n \\\"summary\\\": \\\"Customer, John Doe, is dissatisfied with being reimbursed only half the amount due to an accident, as the full reimbursement option was automatically can [...] + "body" : "{\"model\":\"granite4:3b-h\",\"created_at\":\"2026-01-15T15:03:40.273238709Z\",\"message\":{\"role\":\"assistant\",\"content\":\"{\\n \\\"customerSatisfied\\\": false,\\n \\\"customerName\\\": \\\"John Doe\\\",\\n \\\"customerBirthday\\\": {\\n \\\"year\\\": 2001,\\n \\\"month\\\": 11,\\n \\\"day\\\": 1\\n },\\n \\\"summary\\\": \\\"Customer John Doe is dissatisfied with the insurance company's decision to cancel the full reimbursement option automatically. He [...] "headers" : { - "Date" : "Thu, 18 Dec 2025 13:25:40 GMT", + "Date" : "Thu, 15 Jan 2026 15:03:40 GMT", "Content-Type" : "application/json; charset=utf-8" } }, - "uuid" : "4a005fe6-e449-482d-8ce6-8c341fa4cb9f", + "uuid" : "be38bae8-7817-4141-8b20-2cff30446e53", "persistent" : true, "insertionIndex" : 5 } \ No newline at end of file diff --git a/data-extract-langchain4j/src/test/resources/mappings/api_chat-e8f3defd-bdcb-47f4-8782-687fd3cae6d1.json b/data-extract-langchain4j/src/test/resources/mappings/api_chat-e8f3defd-bdcb-47f4-8782-687fd3cae6d1.json new file mode 100644 index 00000000..3c634a2b --- /dev/null +++ b/data-extract-langchain4j/src/test/resources/mappings/api_chat-e8f3defd-bdcb-47f4-8782-687fd3cae6d1.json @@ -0,0 +1,24 @@ +{ + "id" : "e8f3defd-bdcb-47f4-8782-687fd3cae6d1", + "name" : "api_chat", + "request" : { + "url" : "/api/chat", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\n \"model\" : \"granite4:3b-h\",\n \"messages\" : [ {\n \"role\" : \"user\",\n \"content\" : \"Extract information about a customer from the transcript delimited by triple backticks: ```Operator: Hello, how may I help you?\\nCustomer: Hello, I am currently at the police station because I've got an accident. The police would need a proof that I have an insurance. Could you please help me?\\nOperator: Sure, could you please remind me your name and birth dat [...] + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 200, + "body" : "{\"model\":\"granite4:3b-h\",\"created_at\":\"2026-01-15T15:03:54.19103477Z\",\"message\":{\"role\":\"assistant\",\"content\":\"{\\n \\\"customerSatisfied\\\": true,\\n \\\"customerName\\\": \\\"Kate Boss\\\",\\n \\\"customerBirthday\\\": {\\\"year\\\": 1999, \\\"month\\\": 8, \\\"day\\\": 13},\\n \\\"summary\\\": \\\"The customer Kate Boss requested assistance in providing proof of insurance for an accident she was involved in at a police station. The operator helped v [...] + "headers" : { + "Date" : "Thu, 15 Jan 2026 15:03:54 GMT", + "Content-Type" : "application/json; charset=utf-8" + } + }, + "uuid" : "e8f3defd-bdcb-47f4-8782-687fd3cae6d1", + "persistent" : true, + "insertionIndex" : 4 +} \ No newline at end of file
