Merge branch 'master' into release/v0.10. Includes llamafile and

prompt modifications.
This commit is contained in:
Cyber MacGeddon 2024-09-28 11:26:52 +01:00
commit 39cf256f5c
33 changed files with 1234 additions and 95 deletions

View file

@ -10,6 +10,7 @@
import "patterns/llm-bedrock.jsonnet",
import "patterns/llm-claude.jsonnet",
import "patterns/llm-cohere.jsonnet",
import "patterns/llm-llamafile.jsonnet",
import "patterns/llm-ollama.jsonnet",
import "patterns/llm-openai.jsonnet",
import "patterns/llm-vertexai.jsonnet",

View file

@ -10,6 +10,7 @@
"graph-rag": import "components/graph-rag.jsonnet",
"triple-store-cassandra": import "components/cassandra.jsonnet",
"triple-store-neo4j": import "components/neo4j.jsonnet",
"llamafile": import "components/llamafile.jsonnet",
"ollama": import "components/ollama.jsonnet",
"openai": import "components/openai.jsonnet",
"override-recursive-chunker": import "components/chunker-recursive.jsonnet",

View file

@ -68,6 +68,31 @@ local url = import "values/url.jsonnet";
},
"kg-extract-topics" +: {
create:: function(engine)
local container =
engine.container("kg-extract-topics")
.with_image(images.trustgraph)
.with_command([
"kg-extract-topics",
"-p",
url.pulsar,
])
.with_limits("0.5", "128M")
.with_reservations("0.1", "128M");
local containerSet = engine.containers(
"kg-extract-topics", [ container ]
);
engine.resources([
containerSet,
])
},
"graph-rag" +: {
create:: function(engine)

View file

@ -0,0 +1,75 @@
local base = import "base/base.jsonnet";
local images = import "values/images.jsonnet";
local url = import "values/url.jsonnet";
local prompts = import "prompts/slm.jsonnet";
{
"llamafile-model":: "LLaMA_CPP",
"llamafile-url":: "${LLAMAFILE_URL}",
"text-completion" +: {
create:: function(engine)
local container =
engine.container("text-completion")
.with_image(images.trustgraph)
.with_command([
"text-completion-llamafile",
"-p",
url.pulsar,
"-m",
$["llamafile-model"],
"-r",
$["llamafile-url"],
])
.with_limits("0.5", "128M")
.with_reservations("0.1", "128M");
local containerSet = engine.containers(
"text-completion", [ container ]
);
engine.resources([
containerSet,
])
},
"text-completion-rag" +: {
create:: function(engine)
local container =
engine.container("text-completion-rag")
.with_image(images.trustgraph)
.with_command([
"text-completion-llamafile",
"-p",
url.pulsar,
"-m",
$["llamafile-model"],
"-r",
$["llamafile-url"],
"-i",
"non-persistent://tg/request/text-completion-rag",
"-o",
"non-persistent://tg/response/text-completion-rag-response",
])
.with_limits("0.5", "128M")
.with_reservations("0.1", "128M");
local containerSet = engine.containers(
"text-completion-rag", [ container ]
);
engine.resources([
containerSet,
])
}
} + prompts

View file

@ -25,6 +25,8 @@ local default_prompts = import "prompts/default-prompts.jsonnet";
$["prompt-definition-template"],
"--relationship-template",
$["prompt-relationship-template"],
"--topic-template",
$["prompt-topic-template"],
"--knowledge-query-template",
$["prompt-knowledge-query-template"],
"--document-query-template",
@ -73,6 +75,8 @@ local default_prompts = import "prompts/default-prompts.jsonnet";
$["prompt-definition-template"],
"--relationship-template",
$["prompt-relationship-template"],
"--topic-template",
$["prompt-topic-template"],
"--knowledge-query-template",
$["prompt-knowledge-query-template"],
"--document-query-template",

View file

@ -0,0 +1,41 @@
{
pattern: {
name: "llamafile",
icon: "🤖💬",
title: "Add Llamafile-invoked LLMs for text completion",
description: "This pattern integrates a Llamafile service for text completion operations. You need to have a running Llamafile implementation executing the necessary model in order to be able to use this service.",
requires: ["pulsar", "trustgraph"],
features: ["llm"],
args: [
{
name: "llamafile-max-output-tokens",
label: "Maximum output tokens",
type: "integer",
description: "Limit on number tokens to generate",
default: 4096,
required: true,
},
{
name: "llamafile-temperature",
label: "Temperature",
type: "slider",
description: "Controlling predictability / creativity balance",
min: 0,
max: 1,
step: 0.05,
default: 0.5,
},
{
name: "llamafile-url",
label: "URL",
type: "text",
width: 120,
description: "URL of the Llamafile service",
default: "http://llamafile:8080",
required: true,
},
],
category: [ "llm" ],
},
module: "components/llamafile.jsonnet",
}

View file

@ -7,6 +7,8 @@
// "prompt-relationship-template":: "PROMPT GOES HERE",
// "prompt-topic-template":: "PROMPT GOES HERE",
// "prompt-knowledge-query-template":: "PROMPT GOES HERE",
// "prompt-document-query-template":: "PROMPT GOES HERE",

View file

@ -8,6 +8,8 @@
"prompt-relationship-template":: "<instructions>\nStudy the following text and derive entity relationships. For each\nrelationship, derive the subject, predicate and object of the relationship.\nOutput relationships in JSON format as an arary of objects with fields:\n- subject: the subject of the relationship\n- predicate: the predicate\n- object: the object of the relationship\n- object-entity: false if the object is a simple data type: name, value or date. true if it is an entity.\n</instructions>\n\n<text>\n{text}\n</text>\n\n<requirements>\nYou will respond only with raw JSON format data. Do not provide\nexplanations. Do not use special characters in the abstract text. The\nabstract must be written as plain text. Do not add markdown formatting\nor headers or prefixes.\n</requirements>",
"prompt-topic-template":: "You are a helpful assistant that performs information extraction tasks for a provided text.\nRead the provided text. You will identify topics and their definitions in JSON.\n\nReading Instructions:\n- Ignore document formatting in the provided text.\n- Study the provided text carefully.\n\nHere is the text:\n{text}\n\nResponse Instructions: \n- Do not respond with special characters.\n- Return only topics that are concepts and unique to the provided text.\n- Respond only with well-formed JSON.\n- The JSON response shall be an array of objects with keys \"topic\" and \"definition\". \n- The JSON response shall use the following structure:\n\n```json\n[{{\"topic\": string, \"definition\": string}}]\n```\n\n- Do not write any additional text or explanations.",
"prompt-knowledge-query-template":: "Study the following set of knowledge statements. The statements are written in Cypher format that has been extracted from a knowledge graph. Use only the provided set of knowledge statements in your response. Do not speculate if the answer is not found in the provided set of knowledge statements.\n\nHere's the knowledge statements:\n{graph}\n\nUse only the provided knowledge statements to respond to the following:\n{query}\n",
"prompt-document-query-template":: "Study the following context. Use only the information provided in the context in your response. Do not speculate if the answer is not found in the provided set of knowledge statements.\n\nHere is the context:\n{documents}\n\nUse only the provided knowledge statements to respond to the following:\n{query}\n",

View file

@ -6,6 +6,8 @@
// "prompt-relationship-template":: "PROMPT GOES HERE",
// "prompt-topic-template":: "PROMPT GOES HERE",
// "prompt-knowledge-query-template":: "PROMPT GOES HERE",
// "prompt-document-query-template":: "PROMPT GOES HERE",

View file

@ -7,6 +7,8 @@
// "prompt-relationship-template":: "PROMPT GOES HERE",
// "prompt-topic-template":: "PROMPT GOES HERE",
// "prompt-knowledge-query-template":: "PROMPT GOES HERE",
// "prompt-document-query-template":: "PROMPT GOES HERE",

View file

@ -11,6 +11,8 @@ local url = import "values/url.jsonnet";
// "prompt-relationship-template":: "PROMPT GOES HERE",
// "prompt-topic-template":: "PROMPT GOES HERE",
// "prompt-knowledge-query-template":: "PROMPT GOES HERE",
// "prompt-document-query-template":: "PROMPT GOES HERE",