Skip to content

Commit b571b0b

Browse files
authored
data-extract: Upgrade to granite 4
1 parent c45f6ff commit b571b0b

9 files changed

+61
-60
lines changed

data-extract-langchain4j/README.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ In this example, we'll convert those text conversations into Java Objects that c
1515
image::schema.png[]
1616

1717
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].
18-
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.
18+
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.
1919
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].
2020

2121
=== 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:
2424

2525
[source,shell]
2626
----
27-
docker run --rm -it -v cqex-data-extract-ollama:/root/.ollama -p 11434:11434 --name cqex-data-extract-ollama ollama/ollama:0.9.3
27+
docker run --rm -it -v cqex-data-extract-ollama:/root/.ollama -p 11434:11434 --name cqex-data-extract-ollama ollama/ollama:0.14.1
2828
----
2929

3030
After a moment, a log like below should be output:
3131

3232
[source,shell]
3333
----
34-
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"
34+
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"
3535
----
3636

3737
Then, download the codellama model, in a second shell type:
3838

3939
[source,shell]
4040
----
41-
docker exec -it cqex-data-extract-ollama ollama pull granite3.3:2b
41+
docker exec -it cqex-data-extract-ollama ollama pull granite4:3b-h
4242
----
4343

4444
After a moment, log like below should be output:

data-extract-langchain4j/src/main/java/org/acme/extraction/CustomPojoExtractionService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public String toString() {
5353
String CUSTOM_POJO_EXTRACT_PROMPT = "Extract information about a customer from the transcript delimited by triple backticks: ```{{text}}```."
5454
+ "The customerBirthday field should be formatted as {{dateFormat}}."
5555
+ "The summary field should concisely relate the customer main ask."
56-
+ "Source any extracted field values from what is explicitly mentioned in the transcript.";
56+
+ "Source any extracted field values from what is explicitly mentioned in the transcript."
57+
+ "Extracted field values should be as accurate as possible.";
5758

5859
/**
5960
* The text and dateFormat parameters of this method are automatically injected as {{text}} & {{dateFormat}} in the

data-extract-langchain4j/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ quarkus.default-locale=en_US
2020
# Adjust as per your where your Ollama instance is running
2121
langchain4j.ollama.base-url=http://localhost:11434
2222
# The chat model to use
23-
langchain4j.ollama.chat-model.model-id=granite3.3:2b
23+
langchain4j.ollama.chat-model.model-id=granite4:3b-h

data-extract-langchain4j/src/test/java/org/acme/extraction/OllamaTestResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class OllamaTestResource implements QuarkusTestResourceLifecycleManager {
3636

3737
private static final Logger LOG = LoggerFactory.getLogger(OllamaTestResource.class);
3838

39-
private static final String OLLAMA_IMAGE = "ollama/ollama:0.9.3";
39+
private static final String OLLAMA_IMAGE = "ollama/ollama:0.14.1";
4040
private static final int OLLAMA_SERVER_PORT = 11434;
4141

4242
private static final String MODE_MOCK = "mock";

data-extract-langchain4j/src/test/resources/mappings/api_chat-3867080e-87d5-40d6-b9a8-b90817d980f9.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

data-extract-langchain4j/src/test/resources/mappings/api_chat-3ac79428-f534-4e6a-aa8f-8e401ac22256.json

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"id" : "4b63856f-cac5-4bc1-b66a-d01255ac40e0",
3+
"name" : "api_chat",
4+
"request" : {
5+
"url" : "/api/chat",
6+
"method" : "POST",
7+
"bodyPatterns" : [ {
8+
"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 ?\\nCustomer: 1986, July the 10th.\\nOperator: Ok, I've got your contract and I'm happy to share with you that we'll be able to reimburse all expenses linked to this accident.\\nCustomer: Oh great, many thanks.```.The customerBirthday field should be formatted as YYYY-MM-DD.The summary field should concisely relate the customer main ask.Source any extracted field values from what is explicitly mentioned in the transcript.Extracted field values should be as accurate as possible.\"\n } ],\n \"options\" : {\n \"temperature\" : 0.0,\n \"top_k\" : 1,\n \"top_p\" : 0.1,\n \"stop\" : [ ]\n },\n \"format\" : {\n \"type\" : \"object\",\n \"properties\" : {\n \"customerSatisfied\" : {\n \"type\" : \"boolean\"\n },\n \"customerName\" : {\n \"type\" : \"string\"\n },\n \"customerBirthday\" : {\n \"type\" : \"object\",\n \"properties\" : {\n \"year\" : {\n \"type\" : \"integer\"\n },\n \"month\" : {\n \"type\" : \"integer\"\n },\n \"day\" : {\n \"type\" : \"integer\"\n }\n },\n \"required\" : [ ]\n },\n \"summary\" : {\n \"type\" : \"string\"\n }\n },\n \"required\" : [ \"customerSatisfied\", \"customerName\", \"customerBirthday\", \"summary\" ]\n},\n \"stream\" : false,\n \"tools\" : [ ]\n}",
9+
"ignoreArrayOrder" : true,
10+
"ignoreExtraElements" : true
11+
} ]
12+
},
13+
"response" : {
14+
"status" : 200,
15+
"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 reimbursed.\\\"\\n}\"},\"done\":true,\"done_reason\":\"stop\",\"total_duration\":10290825797,\"load_duration\":1189765918,\"prompt_eval_count\":205,\"prompt_eval_duration\":3886962278,\"eval_count\":81,\"eval_duration\":4312366938}",
16+
"headers" : {
17+
"Date" : "Thu, 15 Jan 2026 15:03:26 GMT",
18+
"Content-Type" : "application/json; charset=utf-8"
19+
}
20+
},
21+
"uuid" : "4b63856f-cac5-4bc1-b66a-d01255ac40e0",
22+
"persistent" : true,
23+
"insertionIndex" : 6
24+
}

0 commit comments

Comments
 (0)