diff --git a/templates/prompts/default-prompts.jsonnet b/templates/prompts/default-prompts.jsonnet index 43de40f3..aa48412b 100644 --- a/templates/prompts/default-prompts.jsonnet +++ b/templates/prompts/default-prompts.jsonnet @@ -12,7 +12,7 @@ "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-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", "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", diff --git a/trustgraph-base/trustgraph/clients/prompt_client.py b/trustgraph-base/trustgraph/clients/prompt_client.py index 4fc8958b..9a41cbf9 100644 --- a/trustgraph-base/trustgraph/clients/prompt_client.py +++ b/trustgraph-base/trustgraph/clients/prompt_client.py @@ -19,6 +19,13 @@ class Definition: name: str definition: str +@dataclasses.dataclass +class Relationship: + s: str + p: str + o: str + o_entity: str + class PromptClient(BaseClient): def __init__( @@ -77,7 +84,7 @@ class PromptClient(BaseClient): def request_relationships(self, chunk, timeout=300): - return self.call( + rels = self.request( id="extract-relationships", terms={ "text": chunk @@ -85,9 +92,19 @@ class PromptClient(BaseClient): timeout=timeout ) + return [ + Relationship( + s=d["subject"], + p=d["predicate"], + o=d["object"], + o_entity=d["object-entity"] + ) + for d in rels + ] + def request_topics(self, chunk, timeout=300): - return self.call( + return self.request( id="extract-topics", terms={ "text": chunk @@ -97,7 +114,7 @@ class PromptClient(BaseClient): def request_rows(self, schema, chunk, timeout=300): - return self.call( + return self.request( id="extract-rows", terms={ "chunk": chunk, @@ -119,11 +136,11 @@ class PromptClient(BaseClient): def request_kg_prompt(self, query, kg, timeout=300): - return self.call( + return self.request( id="kg-prompt", terms={ "query": query, - "kg": [ + "knowledge": [ { "s": v[0], "p": v[1], "o": v[2] } for v in kg ] @@ -133,7 +150,7 @@ class PromptClient(BaseClient): def request_document_prompt(self, query, documents, timeout=300): - return self.call( + return self.request( id="document-prompt", terms={ "query": query, diff --git a/trustgraph-flow/trustgraph/model/prompt/template/service.py b/trustgraph-flow/trustgraph/model/prompt/template/service.py index 5576610a..eea6b8c4 100755 --- a/trustgraph-flow/trustgraph/model/prompt/template/service.py +++ b/trustgraph-flow/trustgraph/model/prompt/template/service.py @@ -166,6 +166,9 @@ class Processor(ConsumerProducer): kind = v.id try: + + print(v.terms) + input = { k: json.loads(v) for k, v in v.terms.items()