Skip to content

Commit 06f9a46

Browse files
committed
add ollama model options:llama-vision,qwen2.5
1 parent 6261ce0 commit 06f9a46

File tree

3 files changed

+103
-22
lines changed

3 files changed

+103
-22
lines changed

models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/api/OllamaModel.java

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,118 +30,159 @@ public enum OllamaModel implements ChatModelDescription {
3030
/**
3131
* Llama 2 is a collection of language models ranging from 7B to 70B parameters.
3232
*/
33-
LLAMA2("llama2"),
33+
LLAMA2("llama2", null),
3434

3535
/**
3636
* Llama 3 is a collection of language models ranging from 8B and 70B parameters.
3737
*/
38-
LLAMA3("llama3"),
38+
LLAMA3("llama3", null),
3939

4040
/**
4141
* The 8B language model from Meta.
4242
*/
43-
LLAMA3_1("llama3.1"),
43+
LLAMA3_1("llama3.1", null),
4444

4545
/**
4646
* The Llama 3.2 3B language model from Meta.
4747
*/
48-
LLAMA3_2("llama3.2"),
48+
LLAMA3_2("llama3.2", null),
4949

5050
/**
5151
* The Llama 3.2 1B language model from Meta.
5252
*/
53-
LLAMA3_2_1B("llama3.2:1b"),
53+
LLAMA3_2_1B("llama3.2", "1b"),
5454

5555
/**
5656
* The 7B parameters model
5757
*/
58-
MISTRAL("mistral"),
58+
MISTRAL("mistral", null),
5959

6060
/**
6161
* A 12B model with 128k context length, built by Mistral AI in collaboration with
6262
* NVIDIA.
6363
*/
64-
MISTRAL_NEMO("mistral-nemo"),
64+
MISTRAL_NEMO("mistral-nemo", null),
6565

6666
/**
6767
* A small vision language model designed to run efficiently on edge devices.
6868
*/
69-
MOONDREAM("moondream"),
69+
MOONDREAM("moondream", null),
7070

7171
/**
7272
* The 2.7B uncensored Dolphin model
7373
*/
74-
DOLPHIN_PHI("dolphin-phi"),
74+
DOLPHIN_PHI("dolphin-phi", null),
7575

7676
/**
7777
* The Phi-2 2.7B language model
7878
*/
79-
PHI("phi"),
79+
PHI("phi", null),
8080

8181
/**
8282
* The Phi-3 3.8B language model
8383
*/
84-
PHI3("phi3"),
84+
PHI3("phi3", null),
8585

8686
/**
8787
* A fine-tuned Mistral model
8888
*/
89-
NEURAL_CHAT("neural-chat"),
89+
NEURAL_CHAT("neural-chat", null),
9090

9191
/**
9292
* Starling-7B model
9393
*/
94-
STARLING_LM("starling-lm"),
94+
STARLING_LM("starling-lm", null),
9595

9696
/**
9797
* Code Llama is based on Llama 2 model
9898
*/
99-
CODELLAMA("codellama"),
99+
CODELLAMA("codellama", null),
100100

101101
/**
102102
* Orca Mini is based on Llama and Llama 2 ranging from 3 billion parameters to 70
103103
* billion
104104
*/
105-
ORCA_MINI("orca-mini"),
105+
ORCA_MINI("orca-mini", null),
106106

107107
/**
108108
* Llava is a Large Language and Vision Assistant model
109109
*/
110-
LLAVA("llava"),
110+
LLAVA("llava", null),
111111

112112
/**
113113
* Gemma is a lightweight model with 2 billion and 7 billion
114114
*/
115-
GEMMA("gemma"),
115+
GEMMA("gemma", null),
116116

117117
/**
118118
* Uncensored Llama 2 model
119119
*/
120-
LLAMA2_UNCENSORED("llama2-uncensored"),
120+
LLAMA2_UNCENSORED("llama2-uncensored", null),
121121

122122
/**
123123
* A high-performing open embedding model with a large token context window.
124124
*/
125-
NOMIC_EMBED_TEXT("nomic-embed-text"),
125+
NOMIC_EMBED_TEXT("nomic-embed-text", null),
126126

127127
/**
128128
* State-of-the-art large embedding model from mixedbread.ai
129129
*/
130-
MXBAI_EMBED_LARGE("mxbai-embed-large");
130+
MXBAI_EMBED_LARGE("mxbai-embed-large", null),
131+
/**
132+
* Qwen2.5 models are pretrained on Alibaba's latest large-scale dataset, encompassing
133+
* up to 18 trillion tokens. The model supports up to 128K tokens and has multilingual
134+
* support.
135+
*/
136+
QWEN2_5("qwen2.5", null), QWEN2_5_7b("qwen2.5", "7b"), QWEN2_5_14b("qwen2.5", "14b"), QWEN2_5_32b("qwen2.5", "32b"),
137+
QWEN2_5_72b("qwen2.5", "72b"),
138+
/**
139+
* The latest series of Code-Specific Qwen models, with significant improvements in
140+
* code generation, code reasoning, and code fixing.
141+
*/
142+
QWEN2_5_CODER("qwen2.5-coder", null), QWEN2_5_CODER_3b("qwen2.5-coder", "3b"),
143+
QWEN2_5_CODER_7b("qwen2.5-coder", "7b"), QWEN2_5_CODER_14b("qwen2.5-coder", "14b"),
144+
QWEN2_5_CODER_32b("qwen2.5-coder", "32b"),
145+
/**
146+
* Llama 3.2 Vision is a collection of instruction-tuned image reasoning generative
147+
* models in 11B and 90B sizes.
148+
*/
149+
LLAMA3_2_VISION("llama3.2-vision", null), LLAMA3_2_VISION_11b("llama3.2-vision", "11b"),
150+
LLAMA3_2_VISION_90b("llama3.2-vision", "90b");
131151

152+
/**
153+
* model id
154+
*/
132155
private final String id;
133156

134-
OllamaModel(String id) {
157+
/**
158+
* model size
159+
*/
160+
private final String size;
161+
162+
OllamaModel(String id, String size) {
135163
this.id = id;
164+
this.size = size;
136165
}
137166

138167
public String id() {
139168
return this.id;
140169
}
141170

171+
/**
172+
* for example: qwen2.5:7b,llama3.2:1b
173+
* @return model id with size
174+
*/
142175
@Override
143176
public String getName() {
144-
return this.id;
177+
return this.id + (null == this.size ? "" : ":" + this.size);
178+
}
179+
180+
/**
181+
* @return model size
182+
*/
183+
@Override
184+
public String getModelSize() {
185+
return this.size;
145186
}
146187

147188
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2023-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.ollama;
18+
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
21+
import org.springframework.ai.ollama.api.OllamaModel;
22+
23+
class OllamaModelTests extends BaseOllamaIT {
24+
25+
@Test
26+
void autoPullModelTest() {
27+
Assertions.assertEquals(OllamaModel.LLAMA3_2_VISION.getName(), "llama3.2-vision");
28+
Assertions.assertEquals(OllamaModel.LLAMA3_2_VISION_11b.getName(), "llama3.2-vision:11b");
29+
30+
}
31+
32+
}

spring-ai-core/src/main/java/org/springframework/ai/model/ModelDescription.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ default String getVersion() {
4747
return "";
4848
}
4949

50+
/**
51+
* Returns the size of the model
52+
* @return
53+
*/
54+
default String getModelSize() {
55+
return null;
56+
}
57+
5058
}

0 commit comments

Comments
 (0)