Updated templates to for prompt-template update

This commit is contained in:
Cyber MacGeddon 2024-10-26 15:35:22 +01:00
parent 99067cb6c0
commit 8f1a44c06e
4 changed files with 108 additions and 50 deletions

View file

@ -13,7 +13,7 @@ local prompts = import "prompts/mixtral.jsonnet";
create:: function(engine)
local envSecrets = engine.envSecrets("bedrock-credentials")
.with_env_var("GOOGLEAISTUDIO_KEY", "googleaistudio-key");
.with_env_var("GOOGLE_AI_STUDIO_KEY", "googleaistudio-key");
local container =
engine.container("text-completion")

View file

@ -17,22 +17,38 @@ local default_prompts = import "prompts/default-prompts.jsonnet";
"prompt-template",
"-p",
url.pulsar,
"--text-completion-request-queue",
"non-persistent://tg/request/text-completion",
"--text-completion-response-queue",
"non-persistent://tg/response/text-completion-response",
"--definition-template",
"--system-prompt",
$["system-template"],
"--prompt",
"question={{question}}",
"extract-definitions=" +
$["prompt-definition-template"],
"--relationship-template",
"extract-relationships=" +
$["prompt-relationship-template"],
"--topic-template",
"extract-topics=" +
$["prompt-topic-template"],
"--knowledge-query-template",
"kg-prompt=" +
$["prompt-knowledge-query-template"],
"--document-query-template",
"document-prompt=" +
$["prompt-document-query-template"],
"--rows-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",
])
.with_limits("0.5", "128M")
.with_reservations("0.1", "128M");
@ -71,18 +87,33 @@ local default_prompts = import "prompts/default-prompts.jsonnet";
"non-persistent://tg/request/text-completion-rag",
"--text-completion-response-queue",
"non-persistent://tg/response/text-completion-rag-response",
"--definition-template",
"--system-prompt",
$["system-template"],
"--prompt",
"question={{question}}",
"extract-definitions=" +
$["prompt-definition-template"],
"--relationship-template",
"extract-relationships=" +
$["prompt-relationship-template"],
"--topic-template",
"extract-topics=" +
$["prompt-topic-template"],
"--knowledge-query-template",
"kg-prompt=" +
$["prompt-knowledge-query-template"],
"--document-query-template",
"document-prompt=" +
$["prompt-document-query-template"],
"--rows-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",
])
.with_limits("0.5", "128M")
.with_reservations("0.1", "128M");

View file

@ -4,16 +4,18 @@
{
"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>",
"system-template":: "You are a helpful assistant.",
"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-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>",
"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-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-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-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-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",
"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-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>",
"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",
"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>",
}

View file

@ -53,57 +53,82 @@ class PromptClient(BaseClient):
if resp.text: return resp.text
return json.loads(resp.object)
def request_topics(self, chunk, timeout=300):
return self.call(
kind="extract-topics", chunk=chunk,
def request_definitions(self, chunk, timeout=300):
return self.request(
id="extract-definitions",
terms={
"chunk": chunk
},
timeout=timeout
).topics
)
def request_relationships(self, chunk, timeout=300):
return self.call(
kind="extract-relationships", chunk=chunk,
id="extract-relationships",
terms={
"chunk": chunk
},
timeout=timeout
).relationships
)
def request_topics(self, chunk, timeout=300):
return self.call(
id="extract-topics",
terms={
"chunk": chunk
},
timeout=timeout
)
def request_rows(self, schema, chunk, timeout=300):
return self.call(
kind="extract-rows", chunk=chunk,
row_schema=RowSchema(
name=schema.name,
description=schema.description,
fields=[
Field(
name=f.name, type=str(f.type), size=f.size,
primary=f.primary, description=f.description,
)
for f in schema.fields
]
),
id="extract-rows",
terms={
"chunk": chunk,
"row-schema": {
"name": schema.name,
"description": schema.description,
"fields": [
{
"name": f.name, "type": str(f.type),
"size": f.size, "primary": f.primary,
"description": f.description,
}
for f in schema.fields
]
}
},
timeout=timeout
).rows
)
def request_kg_prompt(self, query, kg, timeout=300):
return self.call(
kind="kg-prompt",
query=query,
kg=[
Fact(s=v[0], p=v[1], o=v[2])
for v in kg
],
id="kg-prompt",
terms={
"query": query,
"kg": [
{ "s": v[0], "p": v[1], "o": v[2] }
for v in kg
]
},
timeout=timeout
).answer
)
def request_document_prompt(self, query, documents, timeout=300):
return self.call(
kind="document-prompt",
query=query,
documents=documents,
id="document-prompt",
terms={
"query": query,
"documents": documents,
},
timeout=timeout
).answer
)