- Updated newly supported Ollama models

- Added `ConsoleOutputStreamHandler`
This commit is contained in:
Amith Koujalgi 2024-05-13 21:05:20 +05:30
parent 2df878c953
commit 899fa38805
3 changed files with 166 additions and 116 deletions

View File

@ -41,6 +41,7 @@ public class Main {
}
```
You will get a response similar to:
> First answer: Should be Paris!
@ -50,23 +51,28 @@ You will get a response similar to:
> Chat History:
```json
[ {
[
{
"role": "user",
"content": "What is the capital of France?",
"images": []
}, {
},
{
"role": "assistant",
"content": "Should be Paris!",
"images": []
}, {
},
{
"role": "user",
"content": "And what is the second largest city?",
"images": []
}, {
},
{
"role": "assistant",
"content": "Marseille.",
"images": []
} ]
}
]
```
## Create a conversation where the answer is streamed
@ -93,6 +99,7 @@ public class Main {
}
}
```
You will get a response similar to:
> The
@ -103,8 +110,27 @@ You will get a response similar to:
> The capital of France is Paris
> The capital of France is Paris.
## Use a simple Console Output Stream Handler
```
import io.github.amithkoujalgi.ollama4j.core.impl.ConsoleOutputStreamHandler;
public class Main {
public static void main(String[] args) throws Exception {
String host = "http://localhost:11434/";
OllamaAPI ollamaAPI = new OllamaAPI(host);
OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(OllamaModelType.LLAMA2);
OllamaChatRequestModel requestModel = builder.withMessage(OllamaChatMessageRole.USER, "List all cricket world cup teams of 2019. Name the teams!")
.build();
OllamaStreamHandler streamHandler = new ConsoleOutputStreamHandler();
ollamaAPI.chat(requestModel, streamHandler);
}
}
```
## Create a new conversation with individual system prompt
```java
public class Main {
@ -128,6 +154,7 @@ public class Main {
}
```
You will get a response similar to:
> NI.
@ -167,6 +194,12 @@ public class Main {
You will get a response similar to:
> First Answer: The image shows a dog sitting on the bow of a boat that is docked in calm water. The boat has two levels, with the lower level containing seating and what appears to be an engine cover. The dog seems relaxed and comfortable on the boat, looking out over the water. The background suggests it might be late afternoon or early evening, given the warm lighting and the low position of the sun in the sky.
> First Answer: The image shows a dog sitting on the bow of a boat that is docked in calm water. The boat has two
> levels, with the lower level containing seating and what appears to be an engine cover. The dog seems relaxed and
> comfortable on the boat, looking out over the water. The background suggests it might be late afternoon or early
> evening, given the warm lighting and the low position of the sun in the sky.
>
> Second Answer: Based on the image, it's difficult to definitively determine the breed of the dog. However, the dog appears to be medium-sized with a short coat and a brown coloration, which might suggest that it is a Golden Retriever or a similar breed. Without more details like ear shape and tail length, it's not possible to identify the exact breed confidently.
> Second Answer: Based on the image, it's difficult to definitively determine the breed of the dog. However, the dog
> appears to be medium-sized with a short coat and a brown coloration, which might suggest that it is a Golden Retriever
> or a similar breed. Without more details like ear shape and tail length, it's not possible to identify the exact breed
> confidently.

View File

@ -0,0 +1,14 @@
package io.github.amithkoujalgi.ollama4j.core.impl;
import io.github.amithkoujalgi.ollama4j.core.OllamaStreamHandler;
public class ConsoleOutputStreamHandler implements OllamaStreamHandler {
private final StringBuffer response = new StringBuffer();
@Override
public void accept(String message) {
String substr = message.substring(response.length());
response.append(substr);
System.out.print(substr);
}
}

View File

@ -10,15 +10,18 @@ package io.github.amithkoujalgi.ollama4j.core.types;
public class OllamaModelType {
public static final String GEMMA = "gemma";
public static final String LLAMA2 = "llama2";
public static final String LLAMA3 = "llama3";
public static final String MISTRAL = "mistral";
public static final String MIXTRAL = "mixtral";
public static final String LLAVA = "llava";
public static final String LLAVA_PHI3 = "llava-phi3";
public static final String NEURAL_CHAT = "neural-chat";
public static final String CODELLAMA = "codellama";
public static final String DOLPHIN_MIXTRAL = "dolphin-mixtral";
public static final String MISTRAL_OPENORCA = "mistral-openorca";
public static final String LLAMA2_UNCENSORED = "llama2-uncensored";
public static final String PHI = "phi";
public static final String PHI3 = "phi3";
public static final String ORCA_MINI = "orca-mini";
public static final String DEEPSEEK_CODER = "deepseek-coder";
public static final String DOLPHIN_MISTRAL = "dolphin-mistral";