Skip to content

Commit 080d492

Browse files
committed
📦️ Create a release: 0.0.7
1 parent 9a3acfa commit 080d492

File tree

13 files changed

+199
-33
lines changed

13 files changed

+199
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Add this section to your `pom.xml` file:
102102
<dependency>
103103
<groupId>org.parakeetnest.parakeet4j</groupId>
104104
<artifactId>parakeet4j</artifactId>
105-
<version>0.0.6</version>
105+
<version>0.0.7</version>
106106
</dependency>
107107
</dependencies>
108108
```

RELEASE.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,12 @@
44
> - create a tag on GitHub
55
> - pull
66
7-
### What's new (v0.0.6)
7+
### What's new (v0.0.7)
88

9-
#### Completion
9+
#### Protected endpoint
1010

11-
Verbose mode:
12-
```java
13-
Options options = new Options()
14-
.setTemperature(0.0)
15-
.setRepeatLastN(2)
16-
.setVerbose(true);
17-
```
11+
If your Ollama endpoint is protected with a header token, you can specify the token like this:
1812

19-
#### Memory Persistent Vector Store
20-
21-
Add additional data to a vector record:
2213
```java
23-
vectorRecord.setText("THIS IS THE CHUNK NUM "+Integer.toString(index.get()));
24-
vectorRecord.setReference("THIS IS THE CHUNK DOC REF");
25-
vectorRecord.setMetaData("THIS IS THE CHUNK META DATA");
14+
query.setTokenHeaderName("X-TOKEN").setTokenHeaderValue("john doe");
2615
```
27-

docs/01-generate.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,10 @@ output:
234234
}
235235
```
236236

237+
## Protected endpoint
237238

239+
If your Ollama endpoint is protected with a header token, you can specify the token like this:
240+
241+
```java
242+
query.setTokenHeaderName("X-TOKEN").setTokenHeaderValue("john doe");
243+
```

docs/02-chat.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,11 @@ output:
285285
"evalDuration" : 499293000
286286
}
287287
```
288+
289+
## Protected endpoint
290+
291+
If your Ollama endpoint is protected with a header token, you can specify the token like this:
292+
293+
```java
294+
queryChat.setTokenHeaderName("X-TOKEN").setTokenHeaderValue("john doe");
295+
```

docs/03-embeddings-rag.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,12 @@ making him the crew's unsung guardian in the cosmos. His best friend is Spiderma
299299
vectorRecord.setText("THIS IS THE CHUNK NUM "+Integer.toString(index.get()));
300300
vectorRecord.setReference("THIS IS THE CHUNK DOC REF");
301301
vectorRecord.setMetaData("THIS IS THE CHUNK META DATA");
302+
```
303+
304+
## Protected endpoint
305+
306+
If your Ollama endpoint is protected with a header token, you can specify the token like this:
307+
308+
```java
309+
query4Embedding.setTokenHeaderName("X-TOKEN").setTokenHeaderValue("john snow");
302310
```

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.parakeetnest.parakeet4j</groupId>
88
<artifactId>parakeet4j</artifactId>
9-
<version>0.0.6</version>
9+
<version>0.0.7</version>
1010
<!--
1111
<version>1.0-SNAPSHOT</version>
1212
-->
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package examples.chat;
2+
3+
import org.parakeetnest.parakeet4j.llm.Message;
4+
import org.parakeetnest.parakeet4j.llm.Options;
5+
import org.parakeetnest.parakeet4j.llm.Query;
6+
7+
import java.util.List;
8+
9+
import static org.parakeetnest.parakeet4j.completion.Completion.ChatStream;
10+
11+
public class DemoChatStreamToken
12+
{
13+
public static void main( String[] args )
14+
{
15+
Options options = new Options()
16+
.setTemperature(0.0)
17+
.setRepeatLastN(2)
18+
.setVerbose(true);
19+
20+
var systemContent = "You are a useful AI agent, expert with the Star Trek franchise.";
21+
var userContent = "Who is Jean-Luc Picard?";
22+
23+
List<Message> messages = List.of(
24+
new Message("system", systemContent),
25+
new Message("user", userContent)
26+
);
27+
28+
Query queryChat = new Query("tinyllama", options).setMessages(messages);
29+
30+
queryChat.setTokenHeaderName("X-TOKEN").setTokenHeaderValue("john doe");
31+
32+
ChatStream("https://ollamak33g.eu.loclx.io", queryChat,
33+
chunk -> {
34+
System.out.print(chunk.getMessage().getContent());
35+
//return new Exception("😡"); //=> it stops the stream
36+
return null;
37+
},
38+
answer -> {
39+
System.out.println();
40+
System.out.println("--------------------------------------");
41+
System.out.println("😛: " + answer.getMessage().getContent());
42+
},
43+
err -> {
44+
System.out.println("😡: " + err.getMessage());
45+
});
46+
}
47+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package examples.embeddings;
2+
3+
import org.parakeetnest.parakeet4j.llm.Query4Embedding;
4+
5+
import static org.parakeetnest.parakeet4j.embeddings.Embeddings.CreateEmbedding;
6+
7+
public class DemoEmbeddingsCreationToken
8+
{
9+
public static void main( String[] args )
10+
{
11+
var content = "The best Pizza of the world is the pineapple pizza.";
12+
Query4Embedding query4Embedding = new Query4Embedding("all-minilm",content);
13+
14+
query4Embedding.setTokenHeaderName("X-TOKEN").setTokenHeaderValue("john snow");
15+
16+
CreateEmbedding("https://ollamak33g.eu.loclx.io", query4Embedding, "pineapple-pizza",
17+
vectorRecord -> {
18+
System.out.println(vectorRecord.getId() + ": " + vectorRecord.getPrompt());
19+
20+
for (double item : vectorRecord.getEmbedding()) {
21+
System.out.print(item);
22+
System.out.print(" ");
23+
}
24+
},
25+
err -> {
26+
System.out.println("😡: " + err.getMessage());
27+
});
28+
}
29+
}

src/main/java/org/parakeetnest/parakeet4j/completion/Completion.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,24 @@ private static ResultAnswer completion(String ollamaUrl, String kindOfCompletion
5151
//System.out.println("🔴🟥:" + jsonOllamaPayload.getJsonArray("tools").encodePrettily());
5252

5353
// Create HTTP request
54-
HttpRequest request = HttpRequest.newBuilder()
55-
.uri(new URI(ollamaUrl+"/api/"+kindOfCompletion))
56-
.header("Content-Type", "application/json; charset=utf-8")
57-
.POST(HttpRequest.BodyPublishers.ofString(jsonOllamaPayload.toString()))
58-
.build();
54+
HttpRequest request;
55+
56+
57+
if (query.getTokenHeaderName() != null && query.getTokenHeaderValue() != null) {
58+
request = HttpRequest.newBuilder()
59+
.uri(new URI(ollamaUrl+"/api/"+kindOfCompletion))
60+
.header("Content-Type", "application/json; charset=utf-8")
61+
.header(query.getTokenHeaderName(), query.getTokenHeaderValue())
62+
.POST(HttpRequest.BodyPublishers.ofString(jsonOllamaPayload.toString()))
63+
.build();
64+
} else {
65+
request = HttpRequest.newBuilder()
66+
.uri(new URI(ollamaUrl+"/api/"+kindOfCompletion))
67+
.header("Content-Type", "application/json; charset=utf-8")
68+
.POST(HttpRequest.BodyPublishers.ofString(jsonOllamaPayload.toString()))
69+
.build();
70+
}
71+
5972

6073
// Send the request and get the answer
6174
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
@@ -309,11 +322,22 @@ private static ResultAnswer completionStream(String ollamaUrl, String kindOfComp
309322
JsonObject jsonOllamaPayload = new JsonObject(Json.encode(query));
310323

311324
// Create HTTP request
312-
HttpRequest request = HttpRequest.newBuilder()
313-
.uri(new URI(ollamaUrl+"/api/"+kindOfCompletion))
314-
.header("Content-Type", "application/json; charset=utf-8")
315-
.POST(HttpRequest.BodyPublishers.ofString(jsonOllamaPayload.toString()))
316-
.build();
325+
HttpRequest request;
326+
327+
if (query.getTokenHeaderName() != null && query.getTokenHeaderValue() != null) {
328+
request = HttpRequest.newBuilder()
329+
.uri(new URI(ollamaUrl+"/api/"+kindOfCompletion))
330+
.header("Content-Type", "application/json; charset=utf-8")
331+
.header(query.getTokenHeaderName(), query.getTokenHeaderValue())
332+
.POST(HttpRequest.BodyPublishers.ofString(jsonOllamaPayload.toString()))
333+
.build();
334+
} else {
335+
request = HttpRequest.newBuilder()
336+
.uri(new URI(ollamaUrl+"/api/"+kindOfCompletion))
337+
.header("Content-Type", "application/json; charset=utf-8")
338+
.POST(HttpRequest.BodyPublishers.ofString(jsonOllamaPayload.toString()))
339+
.build();
340+
}
317341

318342
// Send the request and get the stream answer
319343
//HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

src/main/java/org/parakeetnest/parakeet4j/embeddings/Embeddings.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,22 @@ private static ResultVectorRecord createEmbedding(String ollamaUrl, Query4Embedd
6060
JsonObject jsonOllamaPayload = new JsonObject(Json.encode(query));
6161

6262
// Create HTTP request
63-
HttpRequest request = HttpRequest.newBuilder()
64-
.uri(new URI(ollamaUrl+"/api/embeddings"))
65-
.header("Content-Type", "application/json; charset=utf-8")
66-
.POST(HttpRequest.BodyPublishers.ofString(jsonOllamaPayload.toString()))
67-
.build();
63+
HttpRequest request;
64+
65+
if (query.getTokenHeaderName() != null && query.getTokenHeaderValue() != null) {
66+
request = HttpRequest.newBuilder()
67+
.uri(new URI(ollamaUrl+"/api/embeddings"))
68+
.header("Content-Type", "application/json; charset=utf-8")
69+
.header(query.getTokenHeaderName(), query.getTokenHeaderValue())
70+
.POST(HttpRequest.BodyPublishers.ofString(jsonOllamaPayload.toString()))
71+
.build();
72+
} else {
73+
request = HttpRequest.newBuilder()
74+
.uri(new URI(ollamaUrl+"/api/embeddings"))
75+
.header("Content-Type", "application/json; charset=utf-8")
76+
.POST(HttpRequest.BodyPublishers.ofString(jsonOllamaPayload.toString()))
77+
.build();
78+
}
6879

6980
// Send the request and get the answer
7081
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

0 commit comments

Comments
 (0)