Skip to content

Commit 71b15f4

Browse files
committed
llama3.java
1 parent 2172d70 commit 71b15f4

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

adoc/articles/javaspektrum-llama3-java.adoc

+5-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Jetzt können wir das gerade heruntergeladene Modell ausführen und eine Frage s
6464
Das kleine Modell ist wie gesagt, nicht besonders gut, oft kommen sehr fragwürdige Antworten.
6565
Daher sollte auch in kritischen, praktischen Anwendungen nur die Sprachfähigkeiten der LLMs, aber möglichst nicht ihr "Wissen" benutzt werden, sondern dieses aus vertrauenswürdigen Quellen, wie Datenbanken beziehen (mittels Retrieval Augmented Generation - RAG).
6666

67-
.Listing {listing}
67+
.Listing {listing} - Test mit jbang, erste Frage
6868
[source,shell]
6969
----
7070
jbang Llama3.java --model ../$MODEL --prompt "Kurz: Wie funktioniert physikalisch ein Induktionsherd?"
@@ -231,13 +231,14 @@ Zum Glück ist bei GGUF/GGMF das Token-Vokabular direkt in das Modelldatei integ
231231

232232
Die Hauptprobleme für Tokenizierung treten bei asiatischen Sprachen z.b. mit Kanji und interessanterweise mit Emoji auf.
233233

234-
Die `Tokenizer` Klasse kümmert sich um die Konvertierung zwischen Text und den Token-Ids:
234+
Die `Tokenizer` Klasse (Listing {counter:listing}) kümmert sich um die Konvertierung zwischen Text und den Token-Ids:
235235

236236
* Implementiert den "Byte Pair Encoding" (BPE) Algorithmus
237237
* Behandlung spezieller Tokens
238238
* Effiziente Textaufteilung mittels regulärer Ausdrücke
239239

240-
[source,java]
240+
.Listing {listing} - Tokenizer Implementierung
241+
[source,java]
241242
----
242243
class Tokenizer {
243244
private final Pattern compiledPattern;
@@ -397,7 +398,7 @@ Model
397398

398399
Konfigurierbare Auswahl des nächsten Token aus dem Vektor der Wahrscheinlichkeitsverteilung (Logits) abhänging von Temperatur, Top-P aber auch Grammatik- oder Funktionssignatur-getriebene Auswahl.
399400

400-
Es gibt verschiedene Sampling-Strategien:
401+
Es gibt verschiedene Sampling-Strategien, siehe Listing {counter:listing}:
401402

402403
* `Sampler`: Basis Sampler Strategie Interface
403404
* `CategoricalSampler`: Global nach Wahrscheinlichkeitsverteilung

adoc/mcp-neo4j.adoc

+27-17
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ MCP follows a https://modelcontextprotocol.io/docs/concepts/architecture[client-
394394
The protocol layer handles message framing, request/response linking, notificaitons and high-level communication patterns.
395395

396396
The MCP allows for different transport protocols, currently supported are HTTPS (with Server-Sent-Events (SSE) for server->client messages and HTTP POST for client->server) and STDIO for local servers where the server is started by the client and can communicate via stdin/stdout.
397+
The protocol has a lifecycle of initialization, message exchange and termination.
397398

398399
All transport messages exchanges are based on a https://spec.modelcontextprotocol.io/specification/[specification^] using JSON-RPC 2.0.
399400
So it encourages to implement the protocol in other languages or transport layers.
@@ -407,6 +408,15 @@ The based message types are:
407408

408409
With additional relevant aspects being configuration, progress tracking, cancellation, error reporting, logging.
409410

411+
Message types are:
412+
413+
* Client->Server: Requests (expect response) and Notifications with method name and parameters.
414+
* Server->Client: Notifications, Results (Dictionary), and Errors (code, message, data) with some error codes from the JSON RPC spec and others from the application/SDKs.
415+
416+
The MCP site also documents sample client and server implementations in Python and TypeScript to enable implementers to get started quickly.
417+
Additionally it provides a list of good practices to adhere to for security, error handling and request processing.
418+
419+
410420
The protocol spec is also considering *security and trust*, which is an important aspect when allowing LLMs to access external data sources, because especially with write access to databases and filesystems and servers running locally and the potential for malicious code execution, security is a top priority.
411421
The foundation models are known to be vulnerable to adversarial attacks and hallucinations.
412422
Often LLM users are non-technical and might not be aware of the risks involved in allowing an AI model to access their data.
@@ -491,23 +501,23 @@ There is a small check that we only allow read statements in the read tool and v
491501

492502
[source,python]
493503
----
494-
@server.call_tool()
495-
async def handle_call_tool(
496-
name: str, arguments: dict[str, Any] | None
497-
) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
498-
"""Handle tool execution requests"""
499-
try:
500-
if name == "get-neo4j-schema":
501-
results = db._execute_query(
502-
"""
503-
CALL apoc.meta.data() yield label, property, type, other, unique, index, elementType
504-
WHERE elementType = 'node'
505-
RETURN label,
506-
collect(case when type <> 'RELATIONSHIP' then [property, type] end) as attributes,
507-
collect(case when type = 'RELATIONSHIP' then [property, head(other)] end) as relationships
508-
"""
509-
)
510-
return [types.TextContent(type="text", text=str(results))]
504+
@server.call_tool()
505+
async def handle_call_tool(
506+
name: str, arguments: dict[str, Any] | None
507+
) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
508+
"""Handle tool execution requests"""
509+
try:
510+
if name == "get-neo4j-schema":
511+
results = db._execute_query(
512+
"""
513+
CALL apoc.meta.data() yield label, property, type, other, unique, index, elementType
514+
WHERE elementType = 'node'
515+
RETURN label,
516+
collect(case when type <> 'RELATIONSHIP' then [property, type] end) as attributes,
517+
collect(case when type = 'RELATIONSHIP' then [property, head(other)] end) as relationships
518+
"""
519+
)
520+
return [types.TextContent(type="text", text=str(results))]
511521
----
512522

513523
== Conversational Memory as a Graph

0 commit comments

Comments
 (0)