Coder Social home page Coder Social logo

amithkoujalgi / ollama4j Goto Github PK

View Code? Open in Web Editor NEW
179.0 3.0 27.0 1.19 MB

Java library for interacting with Ollama server.

Home Page: https://ollama4j.github.io/ollama4j

License: MIT License

Java 99.43% Makefile 0.57%
gpt java llm ollama llama llama2 gen-ai genai generative-ai language-model large-language-models llama3

ollama4j's Introduction

Ollama4j

ollama4j-icon

A Java library (wrapper/binding) for Ollama server.

Find more details on the website.

GitHub stars GitHub forks GitHub watchers Contributors GitHub License

GitHub last commit codecov Build Status

Table of Contents

How does it work?

  flowchart LR
    o4j[Ollama4j]
    o[Ollama Server]
    o4j -->|Communicates with| o;
    m[Models]
    subgraph Ollama Deployment
        direction TB
        o -->|Manages| m
    end
Loading

Requirements

Java

Local Installation

Docker Installation

Download for macOS

Download for Windows

Install on Linux

curl -fsSL https://ollama.com/install.sh | sh

CPU only

docker run -d -p 11434:11434 \
  -v ollama:/root/.ollama \
  --name ollama \
  ollama/ollama

NVIDIA GPU

docker run -d -p 11434:11434 \
  --gpus=all \
  -v ollama:/root/.ollama \
  --name ollama \
  ollama/ollama

Installation

Note

We are now publishing the artifacts to both Maven Central and GitHub package repositories.

Track the releases here and update the dependency version according to your requirements.

For Maven

In your Maven project, add this dependency:

<dependency>
    <groupId>io.github.ollama4j</groupId>
    <artifactId>ollama4j</artifactId>
    <version>1.0.79</version>
</dependency>

Using GitHub's Maven Package Repository

  1. Add GitHub Maven Packages repository to your project's pom.xml or your settings.xml:
<repositories>
    <repository>
        <id>github</id>
        <name>GitHub Apache Maven Packages</name>
        <url>https://maven.pkg.github.com/ollama4j/ollama4j</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
  1. Add GitHub server to settings.xml. (Usually available at ~/.m2/settings.xml)
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <servers>
        <server>
            <id>github</id>
            <username>YOUR-USERNAME</username>
            <password>YOUR-TOKEN</password>
        </server>
    </servers>
</settings>
  1. In your Maven project, add this dependency:
<dependency>
    <groupId>io.github.ollama4j</groupId>
    <artifactId>ollama4j</artifactId>
    <version>1.0.79</version>
</dependency>

For Gradle

  1. Add the dependency
dependencies {
    implementation 'io.github.ollama4j:ollama4j:1.0.79'
}

API Spec

Tip

Find the full API specifications on the website.

Development

Build:

make build

Run unit tests:

make unit-tests

Run integration tests:

make integration-tests

Releases

Newer artifacts are published via GitHub Actions CI workflow when a new release is created from main branch.

Who's using Ollama4j?

Traction

Star History Chart

Get Involved

Open Issues Closed Issues Open PRs Closed PRs Discussions

Contributions are most welcome! Whether it's reporting a bug, proposing an enhancement, or helping with code - any sort of contribution is much appreciated.

References

Credits

The nomenclature and the icon have been adopted from the incredible Ollama project.

Thanks to the amazing contributors

Appreciate my work?

Buy Me A Coffee

ollama4j's People

Contributors

agentschmecker avatar ajt001 avatar amithkoujalgi avatar anjeongkyun avatar kelvinwatson avatar mgmacleod avatar michaelwechner avatar omcodedthis avatar peaster avatar reckart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ollama4j's Issues

Basic Auth or Authorization Header Bearer Token

Do you have plans to support

  • Either Basic Auth
  • Or an Authorization Header Bearer Token

?

I understand Ollama does not support this, but when using a ReverseProxy in front of Ollama, then this would help a lot re security :-)

Thanks

Michael

Inconsistency in Versioning Number for ollama4j Maven Repository

Based on the Maven repository ollama4j, there is an inconsistency in the versioning format. The latest version is listed as "v1.0.82" with an additional "v" prefix, whereas the older versions do not include this prefix.

io/github/ollama4j/ollama4j
../
1.0.78/ 2024-07-26 19:19 -
1.0.79/ 2024-07-27 11:12 -
1.0.80/ 2024-07-27 18:43 -
1.0.81/ 2024-08-06 05:43 -
test001.2/ 2024-07-26 18:53 -
v1.0.82/ 2024-08-06 05:56 -
maven-metadata.xml 2024-08-06 05:56 339

Empty Response when ollama is very slow

Issue

I get an empty response from the library, but my tcpflow logs show that the response does come later.

{
    "role" : "assistant",
    "content" : "",
    "images" : null
  }

Details

I have an old laptop with only Dual-Core i5 2.7Ghz and am running llama3 on Ollama.
I created a simple app to test ollama4j with llama3, but getting empty responses back, even though I set a huge request timeout.

Here is my code

String host = "http://localhost:11434/";
      String model = "llama3";
      OllamaAPI ollamaAPI = new OllamaAPI(host);
      ollamaAPI.setRequestTimeoutSeconds(600000);
      ollamaAPI.setVerbose(true);
      OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(model);
      Options options =
          new OptionsBuilder()
              .setTemperature(0.2f)
              .setNumCtx(example.getModel().getCompletionLength())
              .setTopK(1)
              .setTopP(0.9F)
              .build();
      OllamaChatRequestModel requestModel = builder.withMessage(OllamaChatMessageRole.SYSTEM, example.getSystemPrompt())
          .withMessage(OllamaChatMessageRole.USER, "What can you help me with?")
          .withOptions(options)
          .build();
      System.out.println("Ollama request: " + requestModel.toString());
      OllamaChatResult chatResult = ollamaAPI.chat(requestModel);
      System.out.println("Ollama answer: " + chatResult.getHttpStatusCode() + " in seconds: " + chatResult.getResponseTime() + ":\n" + chatResult.getResponse());

And my logs show this:

Ollama request: {
  "model" : "llama3",
  "options" : {
    "top_p" : 0.9,
    "top_k" : 1,
    "temperature" : 0.2,
    "num_ctx" : 1024
  },
  "stream" : false,
  "messages" : [ {
    "role" : "system",
    "content" : "You are a helpful customer service representative for a credit card company who helps answer customer questions about their past transactions and spending history. Today's date is January 18th, 2024. You provide precise answers and use functions to look up information...",
    "images" : null
  }, {
    "role" : "user",
    "content" : "What can you help me with?",
    "images" : null
  } ]
}
Ollama answer: 200 in seconds: 108372:

If I look into the message history, I basically see

{
    "role" : "assistant",
    "content" : "",
    "images" : null
  }

But if I check my tcpflow logs, I can see a Response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Tue, 14 May 2024 10:29:15 GMT
Content-Length: 801

{
   "model":"llama3",
   "created_at":"2024-05-14T10:29:15.284946Z",
   "message":{
      "role":"assistant",
      "content":"I'm happy to assist you with any questions or concerns you may have about your credit card account. I can help you:\n\n* Review your transaction history and spending habits\n* Check your available credit limit and current balance\n* Provide information on rewards and benefits associated with your card\n* Help you track your spending by category (e.g., groceries, entertainment, etc.)\n* Offer suggestions for managing your debt or improving your financial situation\n\nWhat specific area would you like me to help you with today?"
   },
   "done_reason":"stop",
   "done":true,
   "total_duration":54914791839,
   "load_duration":15113419,
   "prompt_eval_duration":804784000,
   "eval_count":101,
   "eval_duration":54082687000
}

Trying the streaming API works, but not the synchronous one.
Do you have any idea what the problem is?

`evalCount` in response from ollama cannot be parsed

I sometimes get the error

UnrecognizedPropertyException: Unrecognized field "eval_count" (class io.github.amithkoujalgi.ollama4j.core.models.OllamaResponseModel), not marked as ignorable (11 known properties: "response", "done", "evalCount", "eval_duration", "model", "created_at", "prompt_eval_duration", "load_duration", "context", "prompt_eval_count", "total_duration"])

:package: Deliver as Jitpack :sloth:

❔ About

Currently, the setup is pretty complex for end-users :

image

Wihtout having to push to maven central repos and with minimal effort, this could be enhanced with jitpack :

image

🎯 Action

  • Consider document it this way
  • Add the markdown badge so people are aware it is available as a jitpack dependency

Certain requests fail with a 400 Bad Request

It appears that certain requests generated by the ask() method trigger a 400 - Bad request on the side of ollama.

Trying the same request manually works though (i.e. copying the JSON generated by ollamaRequestModel.toString() and posting it manually).

Update Code Due to Changes in generate Method of PromptBuilder

Description

The generate method of PromptBuilder has undergone changes due to recent updates. Consequently, the code provided in the example no longer functions correctly.

Previously, the method was called as follows:

OllamaResult response = ollamaAPI.generate(model, promptBuilder.build());

However, in the latest version, additional options need to be passed to the generate method. Therefore, the code needs to be modified as follows:

OllamaResult response = ollamaAPI.generate(model, promptBuilder.build(), new Options());

Updating the code to reflect this change should prevent any further compatibility issues.

com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.LocalDateTime` from String "2024-05-08T20:06:14.620804598-07:00": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2024-05-08T20:06:14.620804598-07:00' could not be parsed, unparsed text found at index 29

Looks like there's a regression with the latest version. See the deserialization exception that occurs when OllamaAPI.listModels is called in version 1.0.70. Note, this exception isn't thrown in 1.0.65

Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.LocalDateTime` from String "2024-05-08T20:06:14.620804598-07:00": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2024-05-08T20:06:14.620804598-07:00' could not be parsed, unparsed text found at index 29
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 74] (through reference chain: io.github.amithkoujalgi.ollama4j.core.models.ListModelsResponse["models"]->java.util.ArrayList[0]->io.github.amithkoujalgi.ollama4j.core.models.Model["modified_at"])
	at com.fasterxml.jackson.databind.exc.InvalidFormatException.from(InvalidFormatException.java:67)
	at com.fasterxml.jackson.databind.DeserializationContext.weirdStringException(DeserializationContext.java:1958)
	at com.fasterxml.jackson.databind.DeserializationContext.handleWeirdStringValue(DeserializationContext.java:1245)
	at com.fasterxml.jackson.datatype.jsr310.deser.JSR310DeserializerBase._handleDateTimeException(JSR310DeserializerBase.java:176)
	at com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer._fromString(LocalDateTimeDeserializer.java:216)
	at com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer.deserialize(LocalDateTimeDeserializer.java:114)
	at com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer.deserialize(LocalDateTimeDeserializer.java:41)
	at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:310)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer._deserializeFromArray(CollectionDeserializer.java:361)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:246)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:30)
	at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:310)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
	at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4905)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3848)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3816)
	at io.github.amithkoujalgi.ollama4j.core.OllamaAPI.listModels(OllamaAPI.java:137)

Unrecognized field "done_reason"

After the latest update of the Ollama client (version: 6.2.2, May 12, 2024), I encounter the following exceptions:

ERROR io.github.amithkoujalgi.ollama4j.core.models.request.OllamaChatEndpointCaller - Error parsing the Ollama chat response!
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "done_reason" (class io.github.amithkoujalgi.ollama4j.core.models.chat.OllamaChatResponseModel), not marked as ignorable (12 known properties: "done", "message", "error", "model", "created_at", "prompt_eval_duration", "load_duration", "context", "eval_duration", "eval_count", "total_duration", "prompt_eval_count"])
at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 142] (through reference chain: io.github.amithkoujalgi.ollama4j.core.models.chat.OllamaChatResponseModel["done_reason"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:1153)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:2241)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1793)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1771)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:316)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4905)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3848)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3816)
at io.github.amithkoujalgi.ollama4j.core.models.request.OllamaChatEndpointCaller.parseResponseAndAddToBuffer(OllamaChatEndpointCaller.java:40)
at io.github.amithkoujalgi.ollama4j.core.models.request.OllamaEndpointCaller.callSync(OllamaEndpointCaller.java:99)
at io.github.amithkoujalgi.ollama4j.core.OllamaAPI.chat(OllamaAPI.java:521)
at io.github.amithkoujalgi.ollama4j.core.OllamaAPI.chat(OllamaAPI.java:498)

NegativeArraySizeException after repeated calls to chat function

With the following code, where I repeatedly call the chat function with an initial ChatResult (for the prompt where I tell the model that I want text translated), I get a NegativeArraySizeException:

builder = OllamaChatRequestBuilder.getInstance(model);
OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER, prompt).build();
initialChatResult = ollamaAPI.chat(requestModel);
// ...
// in a loop:
OllamaChatRequest requestModel = 
   builder.withMessages(initialChatResult.getChatHistory()).withMessage(OllamaChatMessageRole.USER, text).build();
OllamaChatResult chatResult = ollamaAPI.chat(requestModel);   // this is where the exception gets thrown

Maybe, this is caused by some kind of internal int overflow?

The negative number keeps (see exception) changing every time. I use ollama 0.3.2 with llama3.1:70b. It happens at around the 20th call.

Here comes the exception:
Exception in thread "main" java.lang.NegativeArraySizeException: -1854670873
at java.base/java.lang.String.encodeUTF8_UTF16(String.java:1326)
at java.base/java.lang.String.encodeUTF8(String.java:1299)
at java.base/java.lang.String.encode(String.java:867)
at java.base/java.lang.String.getBytes(String.java:1818)
at java.net.http/jdk.internal.net.http.RequestPublishers$StringPublisher.(RequestPublishers.java:211)
at java.net.http/java.net.http.HttpRequest$BodyPublishers.ofString(HttpRequest.java:666)
at java.net.http/java.net.http.HttpRequest$BodyPublishers.ofString(HttpRequest.java:654)
at io.github.ollama4j.utils.OllamaRequestBody.getBodyPublisher(OllamaRequestBody.java:22)
at io.github.ollama4j.models.request.OllamaEndpointCaller.callSync(OllamaEndpointCaller.java:65)
at io.github.ollama4j.OllamaAPI.chat(OllamaAPI.java:588)
at io.github.ollama4j.OllamaAPI.chat(OllamaAPI.java:566)
at ollama.MyOllamaApi.translate(MyOllamaApi.java:33)

Logging backend should not be a transitive dependency

Ollama4j uses logback as a logging backend and has a transitive dependency on it.

Libraries should not have transitive dependencies on logging backends.

If you need the backend during testing, best use the test scope on the dependency.

In general, the application which uses the ollama4j library should define a logging backend for ollama4j to use.

Change your logo with Duke instead

Friendly suggestion that it would be better to use the Java Duke logo instead of the TM Java logo. I speak out of experience :) Otherwise very interesting project, keep it up!
IMG_5744

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException

Hi,
I talk to Ollama 0.3.0 using ollama4j 1.0.80.

I receive an UnrecognizedPropertyException when I am doing

        OllamaAPI ollamaAPI = new OllamaAPI("...");
        ModelsProcessResponse mpr = ollamaAPI.ps();

I have llama3.1:latest running.

Here is the stacktrace:
------><---------------------------------------------
Unrecognized field "parent_model" (class io.github.ollama4j.models.ps.ModelsProcessResponse$ModelDetails), not marked as ignorable (6 known properties: "families", "quantizationLevel", "family", "format", "parameterSize", "parentModel"])
at [Source: (String)"{"models":[{"name":"llama3.1:latest","model":"llama3.1:latest","size":6654289920,"digest":"62757c860e01d552d4e46b09c6b8d5396ef9015210105427e05a8b27d7727ed2","details":{"parent_model":"","format":"gguf","family":"llama","families":["llama"],"parameter_size":"8.0B","quantization_level":"Q4_0"},"expires_at":"2024-07-31T17:07:58.581961212+02:00","size_vram":6654289920}]}"; line: 1, column: 185] (through reference chain: io.github.ollama4j.models.ps.ModelsProcessResponse["models"]->java.util.ArrayList[0]->io.github.ollama4j.models.ps.ModelsProcessResponse$ModelProcess["details"]->io.github.ollama4j.models.ps.ModelsProcessResponse$ModelDetails["parent_model"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:1138)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:2224)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1709)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1687)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:320)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:314)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer._deserializeFromArray(CollectionDeserializer.java:359)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:244)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:28)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:314)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4825)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3772)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3740)
at io.github.ollama4j.OllamaAPI.ps(OllamaAPI.java:139)
....

Hope that helps.

Best regards,
Joco

Unrecognized field "expires_at"

Ran into this error when using Ollama4j 1.0.63 against an Ollama 0.1.38 calling listModels():

Exception: Unrecognized field "expires_at" (class io.github.amithkoujalgi.ollama4j.core.models.Model), not marked as ignorable (6 known properties: "size", "details", "digest", "model", "name", "modified_at"])
at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 370] (through reference chain: io.github.amithkoujalgi.ollama4j.core.models.ListModelsResponse["models"]->java.util.ArrayList[0]->io.github.amithkoujalgi.ollama4j.core.models.Model["expires_at"])

Worked fine against 0.1.34 and bumping ollama4j to 1.0.72 resolved the issue.
Perhaps improve error message if Ollama changes the format repeatedly in the future.
Closing and just adding for reference.

Thanks for an excellent wrapper library btw :)

Set options / temperature

According to the Ollama documentation one can set the temperature using options

https://github.com/jmorganca/ollama/blob/main/docs/api.md#parameters
https://github.com/jmorganca/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values

{ "model": "mistral", "stream":false, "prompt":"How many moons does earth have?", "options":{"temperature":0} }

IIUC one cannot set the temperature / options yet using ollama4j.

I would like to suggest to introduce another "ask" method, where one can set options as well

Options options = new Options();
options.setTemperature(0.7);
ollamaAPI.ask(String, String, Options)

WDYT?

Thanks

Michael

Extend generate API Requests by advanced parameters

In addition to the /api/chat endpoint, the system prompt parameter (and other parameters that override model behaviours) can also be provided to requests at /api/generate.

Thus these should also be made available for the ollama4j API.

See:
Advanced parameters (optional):

format: the format to return a response in. Currently the only accepted value is json

system: system message to (overrides what is defined in the Modelfile)

template: the prompt template to use (overrides what is defined in the Modelfile)

context: the context parameter returned from a previous request to /generate, this can be used to keep a short conversational memory

raw: if true no formatting will be applied to the prompt. You may choose to use the raw parameter if you are specifying a full templated prompt in your request to the API

keep_alive: controls how long the model will stay loaded into memory following the request (default: 5m)

Originally posted by @AgentSchmecker in #20 (comment)

Raw prompt mode

Is it possible to send raw prompt to the models through Ollama4j? (I would like to use function calling provided by Mistral 7B v0.3 which require Ollama's raw mode in order to send special tokens in the prompt; see: https://ollama.com/library/mistral ).

Currently, I can see that JSONs send to Ollama have raw field set to false, and I don't know how to change it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.