Maint/neater prompt jsonnet (#127)

* Changed the JSONNET for prompt-template so that prompt templates are
simpler.  This tidies default-prompts.jsonnet so it's easier to see
where the prompts are.

* Updated prompt override templates to match new structure
This commit is contained in:
cybermaggedon 2024-10-27 09:06:09 +00:00 committed by GitHub
parent b07d539802
commit 2942c4dcf0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 303 additions and 99 deletions

View file

@ -6,6 +6,8 @@ local default_prompts = import "prompts/default-prompts.jsonnet";
{
prompts:: default_prompts,
"prompt" +: {
create:: function(engine)
@ -24,36 +26,28 @@ local default_prompts = import "prompts/default-prompts.jsonnet";
"non-persistent://tg/response/text-completion-response",
"--system-prompt",
$["system-template"],
$["prompts"]["system-template"],
"--prompt",
"question={{question}}",
"extract-definitions=" +
$["prompt-definition-template"],
"extract-relationships=" +
$["prompt-relationship-template"],
"extract-topics=" +
$["prompt-topic-template"],
"kg-prompt=" +
$["prompt-knowledge-query-template"],
"document-prompt=" +
$["prompt-document-query-template"],
"extract-rows=" +
$["prompt-rows-template"],
"--prompt-response-type",
"extract-definitions=json",
"extract-relationships=json",
"extract-topics=json",
"kg-prompt=text",
"document-prompt=text",
"extract-rows=json",
"--prompt-schema",
'extract-definitions={ "type": "array", "items": { "type": "object", "properties": { "entity": { "type": "string" }, "definition": { "type": "string" } }, "required": [ "entity", "definition" ] } }',
'extract-relationships={ "type": "array", "items": { "type": "object", "properties": { "subject": { "type": "string" }, "predicate": { "type": "string" }, "object": { "type": "string" }, "object-entity": { "type": "boolean" } }, "required": [ "subject", "predicate", "object", "object-entity" ] } }',
'extract-topics={ "type": "array", "items": { "type": "object", "properties": { "topic": { "type": "string" }, "definition": { "type": "string" } }, "required": [ "topic", "definition" ] } }',
] + [
p.key + "=" + p.value.prompt,
for p in std.objectKeysValuesAll($.prompts.templates)
] + [
"--prompt-response-type"
] + [
p.key + "=" + p.value["response-type"],
for p in std.objectKeysValuesAll($.prompts.templates)
if std.objectHas(p.value, "response-type")
] + [
"--prompt-schema"
] + [
(
p.key + "=" +
std.manifestJsonMinified(p.value["schema"])
)
for p in std.objectKeysValuesAll($.prompts.templates)
if std.objectHas(p.value, "schema")
])
.with_limits("0.5", "128M")
.with_reservations("0.1", "128M");
@ -94,36 +88,28 @@ local default_prompts = import "prompts/default-prompts.jsonnet";
"non-persistent://tg/response/text-completion-rag-response",
"--system-prompt",
$["system-template"],
$["prompts"]["system-template"],
"--prompt",
"question={{question}}",
"extract-definitions=" +
$["prompt-definition-template"],
"extract-relationships=" +
$["prompt-relationship-template"],
"extract-topics=" +
$["prompt-topic-template"],
"kg-prompt=" +
$["prompt-knowledge-query-template"],
"document-prompt=" +
$["prompt-document-query-template"],
"extract-rows=" +
$["prompt-rows-template"],
"--prompt-response-type",
"extract-definitions=json",
"extract-relationships=json",
"extract-topics=json",
"kg-prompt=text",
"document-prompt=text",
"extract-rows=json",
"--prompt-schema",
'extract-definitions={ "type": "array", "items": { "type": "object", "properties": { "entity": { "type": "string" }, "definition": { "type": "string" } }, "required": [ "entity", "definition" ] } }',
'extract-relationships={ "type": "array", "items": { "type": "object", "properties": { "subject": { "type": "string" }, "predicate": { "type": "string" }, "object": { "type": "string" }, "object-entity": { "type": "boolean" } }, "required": [ "subject", "predicate", "object", "object-entity" ] } }',
'extract-topics={ "type": "array", "items": { "type": "object", "properties": { "topic": { "type": "string" }, "definition": { "type": "string" } }, "required": [ "topic", "definition" ] } }',
] + [
p.key + "=" + p.value.prompt,
for p in std.objectKeysValuesAll($.prompts.templates)
] + [
"--prompt-response-type"
] + [
p.key + "=" + p.value["response-type"],
for p in std.objectKeysValuesAll($.prompts.templates)
if std.objectHas(p.value, "response-type")
] + [
"--prompt-schema"
] + [
(
p.key + "=" +
std.manifestJsonMinified(p.value["schema"])
)
for p in std.objectKeysValuesAll($.prompts.templates)
if std.objectHas(p.value, "schema")
])
.with_limits("0.5", "128M")
.with_reservations("0.1", "128M");

View file

@ -1,18 +1,42 @@
// For Cohere. Not currently overriding prompts
{
local prompts = import "default-prompts.jsonnet";
// "prompt-definition-template": "PROMPT GOES HERE",
prompts + {
// "prompt-relationship-template":: "PROMPT GOES HERE",
// "system-template":: "PROMPT GOES HERE.",
// "prompt-topic-template":: "PROMPT GOES HERE",
"templates" +:: {
// "prompt-knowledge-query-template":: "PROMPT GOES HERE",
"question" +:: {
// "prompt": "PROMPT GOES HERE",
},
// "prompt-document-query-template":: "PROMPT GOES HERE",
"extract-definitions" +:: {
// "prompt": "PROMPT GOES HERE",
},
// "prompt-rows-template":: "PROMPT GOES HERE",
"extract-relationships" +:: {
// "prompt": "PROMPT GOES HERE",
},
"extract-topics" +:: {
// "prompt": "PROMPT GOES HERE",
},
"extract-rows" +:: {
// "prompt": "PROMPT GOES HERE",
},
"kg-prompt" +:: {
// "prompt": "PROMPT GOES HERE",
},
"document-prompt" +:: {
// "prompt": "PROMPT GOES HERE",
},
}
}

View file

@ -6,16 +6,105 @@
"system-template":: "You are a helpful assistant.",
"prompt-definition-template":: "<instructions>\nStudy the following text and derive definitions for any discovered entities.\nDo not provide definitions for entities whose definitions are incomplete\nor unknown.\nOutput relationships in JSON format as an arary of objects with fields:\n- entity: the name of the entity\n- definition: English text which defines the 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 will be written as plain text. Do not add markdown formatting\nor headers or prefixes. Do not include null or unknown definitions.\n</requirements>",
"templates":: {
"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>",
"question":: {
"prompt": "{{question}}",
},
"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.",
"extract-definitions":: {
"prompt": "<instructions>\nStudy the following text and derive definitions for any discovered entities.\nDo not provide definitions for entities whose definitions are incomplete\nor unknown.\nOutput relationships in JSON format as an arary of objects with fields:\n- entity: the name of the entity\n- definition: English text which defines the 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 will be written as plain text. Do not add markdown formatting\nor headers or prefixes. Do not include null or unknown definitions.\n</requirements>",
"response-type": "json",
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"entity": {
"type": "string"
},
"definition": {
"type": "string"
}
},
"required": [
"entity",
"definition"
]
}
}
},
"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{% for edge in knowledge %}({{edge.s}})-[{{edge.p}}]->({{edge.o}})\n{%endfor%}\n\nUse only the provided knowledge statements to respond to the following:\n{{query}}\n",
"extract-relationships":: {
"prompt": "<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>",
"response-type": "json",
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"subject": {
"type": "string"
},
"predicate": {
"type": "string"
},
"object": {
"type": "string"
},
"object-entity": {
"type": "boolean"
},
},
"required": [
"subject",
"predicate",
"object",
"object-entity"
]
}
}
},
"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",
"extract-topics":: {
"prompt": "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.",
"response-type": "json",
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"topic": {
"type": "string"
},
"definition": {
"type": "string"
}
},
"required": [
"topic",
"definition"
]
}
}
},
"prompt-rows-template":: "<instructions>\nStudy the following text and derive objects which match the schema provided.\n\nYou must output an array of JSON objects for each object you discover\nwhich matches the schema. For each object, output a JSON object whose fields\ncarry the name field specified in the schema.\n</instructions>\n\n<schema>\n{{schema}}\n</schema>\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 add markdown formatting or headers or prefixes.\n</requirements>",
"extract-rows":: {
"prompt": "<instructions>\nStudy the following text and derive objects which match the schema provided.\n\nYou must output an array of JSON objects for each object you discover\nwhich matches the schema. For each object, output a JSON object whose fields\ncarry the name field specified in the schema.\n</instructions>\n\n<schema>\n{{schema}}\n</schema>\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 add markdown formatting or headers or prefixes.\n</requirements>",
"response-type": "json",
},
"kg-prompt":: {
"prompt": "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{% for edge in knowledge %}({{edge.s}})-[{{edge.p}}]->({{edge.o}})\n{%endfor%}\n\nUse only the provided knowledge statements to respond to the following:\n{{query}}\n",
"response-type": "text",
},
"document-prompt":: {
"prompt": "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",
"response-type": "text",
},
}
}
}

View file

@ -1,17 +1,42 @@
// For VertexAI Gemini. Not currently overriding prompts
{
// "prompt-definition-template": "PROMPT GOES HERE",
local prompts = import "default-prompts.jsonnet";
// "prompt-relationship-template":: "PROMPT GOES HERE",
prompts + {
// "prompt-topic-template":: "PROMPT GOES HERE",
// "system-template":: "PROMPT GOES HERE.",
// "prompt-knowledge-query-template":: "PROMPT GOES HERE",
"templates" +:: {
// "prompt-document-query-template":: "PROMPT GOES HERE",
"question" +:: {
// "prompt": "PROMPT GOES HERE",
},
// "prompt-rows-template":: "PROMPT GOES HERE",
"extract-definitions" +:: {
// "prompt": "PROMPT GOES HERE",
},
"extract-relationships" +:: {
// "prompt": "PROMPT GOES HERE",
},
"extract-topics" +:: {
// "prompt": "PROMPT GOES HERE",
},
"extract-rows" +:: {
// "prompt": "PROMPT GOES HERE",
},
"kg-prompt" +:: {
// "prompt": "PROMPT GOES HERE",
},
"document-prompt" +:: {
// "prompt": "PROMPT GOES HERE",
},
}
}

View file

@ -1,18 +1,42 @@
// For Mixtral. Not currently overriding prompts
{
local prompts = import "default-prompts.jsonnet";
// "prompt-definition-template": "PROMPT GOES HERE",
prompts + {
// "prompt-relationship-template":: "PROMPT GOES HERE",
// "system-template":: "PROMPT GOES HERE.",
// "prompt-topic-template":: "PROMPT GOES HERE",
"templates" +:: {
// "prompt-knowledge-query-template":: "PROMPT GOES HERE",
"question" +:: {
// "prompt": "PROMPT GOES HERE",
},
// "prompt-document-query-template":: "PROMPT GOES HERE",
"extract-definitions" +:: {
// "prompt": "PROMPT GOES HERE",
},
// "prompt-rows-template":: "PROMPT GOES HERE",
"extract-relationships" +:: {
// "prompt": "PROMPT GOES HERE",
},
"extract-topics" +:: {
// "prompt": "PROMPT GOES HERE",
},
"extract-rows" +:: {
// "prompt": "PROMPT GOES HERE",
},
"kg-prompt" +:: {
// "prompt": "PROMPT GOES HERE",
},
"document-prompt" +:: {
// "prompt": "PROMPT GOES HERE",
},
}
}

View file

@ -1,23 +1,42 @@
// For OpenAI LLMs. Not currently overriding prompts
// For OpenAI LLMs
local prompts = import "default-prompts.jsonnet";
local base = import "base/base.jsonnet";
local images = import "values/images.jsonnet";
local url = import "values/url.jsonnet";
prompts + {
{
// "system-template":: "PROMPT GOES HERE.",
// "prompt-definition-template": "PROMPT GOES HERE",
"templates" +:: {
// "prompt-relationship-template":: "PROMPT GOES HERE",
"question" +:: {
// "prompt": "PROMPT GOES HERE",
},
// "prompt-topic-template":: "PROMPT GOES HERE",
"extract-definitions" +:: {
// "prompt": "PROMPT GOES HERE",
},
// "prompt-knowledge-query-template":: "PROMPT GOES HERE",
"extract-relationships" +:: {
// "prompt": "PROMPT GOES HERE",
},
// "prompt-document-query-template":: "PROMPT GOES HERE",
"extract-topics" +:: {
// "prompt": "PROMPT GOES HERE",
},
// "prompt-rows-template":: "PROMPT GOES HERE",
"extract-rows" +:: {
// "prompt": "PROMPT GOES HERE",
},
"kg-prompt" +:: {
// "prompt": "PROMPT GOES HERE",
},
"document-prompt" +:: {
// "prompt": "PROMPT GOES HERE",
},
}
}

View file

@ -1,7 +1,44 @@
// For SLM. Not currently overriding prompts
// For basic SLMs, use prompt-generic
local prompts = import "default-prompts.jsonnet";
prompts + {
// "system-template":: "PROMPT GOES HERE.",
"templates" +:: {
"question" +:: {
// "prompt": "PROMPT GOES HERE",
},
"extract-definitions" +:: {
// "prompt": "PROMPT GOES HERE",
},
"extract-relationships" +:: {
// "prompt": "PROMPT GOES HERE",
},
"extract-topics" +:: {
// "prompt": "PROMPT GOES HERE",
},
"extract-rows" +:: {
// "prompt": "PROMPT GOES HERE",
},
"kg-prompt" +:: {
// "prompt": "PROMPT GOES HERE",
},
"document-prompt" +:: {
// "prompt": "PROMPT GOES HERE",
},
}
}
local prompts = import "components/prompt-generic.jsonnet";
prompts