diff --git a/templates/components/prompt-template.jsonnet b/templates/components/prompt-template.jsonnet index dbf2514f..25982eb3 100644 --- a/templates/components/prompt-template.jsonnet +++ b/templates/components/prompt-template.jsonnet @@ -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"); diff --git a/templates/prompts/cohere.jsonnet b/templates/prompts/cohere.jsonnet index 2335084b..9541e4c2 100644 --- a/templates/prompts/cohere.jsonnet +++ b/templates/prompts/cohere.jsonnet @@ -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", + }, + + } } + diff --git a/templates/prompts/default-prompts.jsonnet b/templates/prompts/default-prompts.jsonnet index aa48412b..6affd39d 100644 --- a/templates/prompts/default-prompts.jsonnet +++ b/templates/prompts/default-prompts.jsonnet @@ -6,16 +6,105 @@ "system-template":: "You are a helpful assistant.", - "prompt-definition-template":: "\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\n\n\n{{text}}\n\n\n\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", + "templates":: { - "prompt-relationship-template":: "\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\n\n\n{{text}}\n\n\n\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", + "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": "\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\n\n\n{{text}}\n\n\n\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", + "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": "\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\n\n\n{{text}}\n\n\n\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", + "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":: "\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\n\n\n{{schema}}\n\n\n\n{{text}}\n\n\n\nYou will respond only with raw JSON format data. Do not provide\nexplanations. Do not add markdown formatting or headers or prefixes.\n", + "extract-rows":: { + "prompt": "\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\n\n\n{{schema}}\n\n\n\n{{text}}\n\n\n\nYou will respond only with raw JSON format data. Do not provide\nexplanations. Do not add markdown formatting or headers or prefixes.\n", + "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", + }, + + } + +} -} \ No newline at end of file diff --git a/templates/prompts/gemini.jsonnet b/templates/prompts/gemini.jsonnet index 12905c7a..b9a1e0c0 100644 --- a/templates/prompts/gemini.jsonnet +++ b/templates/prompts/gemini.jsonnet @@ -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", + }, + + } } + diff --git a/templates/prompts/mixtral.jsonnet b/templates/prompts/mixtral.jsonnet index c5e70477..cd56e7ef 100644 --- a/templates/prompts/mixtral.jsonnet +++ b/templates/prompts/mixtral.jsonnet @@ -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", + }, + + } } + diff --git a/templates/prompts/openai.jsonnet b/templates/prompts/openai.jsonnet index 0715525e..5d232337 100644 --- a/templates/prompts/openai.jsonnet +++ b/templates/prompts/openai.jsonnet @@ -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", + }, + + } } diff --git a/templates/prompts/slm.jsonnet b/templates/prompts/slm.jsonnet index bd0cbff3..48eb96d0 100644 --- a/templates/prompts/slm.jsonnet +++ b/templates/prompts/slm.jsonnet @@ -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