All tests working

This commit is contained in:
Cyber MacGeddon 2024-10-26 16:20:59 +01:00
parent 5e86a3c3ae
commit 629ab0d3ea
3 changed files with 27 additions and 7 deletions

View file

@ -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-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", "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

@ -19,6 +19,13 @@ class Definition:
name: str name: str
definition: str definition: str
@dataclasses.dataclass
class Relationship:
s: str
p: str
o: str
o_entity: str
class PromptClient(BaseClient): class PromptClient(BaseClient):
def __init__( def __init__(
@ -77,7 +84,7 @@ class PromptClient(BaseClient):
def request_relationships(self, chunk, timeout=300): def request_relationships(self, chunk, timeout=300):
return self.call( rels = self.request(
id="extract-relationships", id="extract-relationships",
terms={ terms={
"text": chunk "text": chunk
@ -85,9 +92,19 @@ class PromptClient(BaseClient):
timeout=timeout 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): def request_topics(self, chunk, timeout=300):
return self.call( return self.request(
id="extract-topics", id="extract-topics",
terms={ terms={
"text": chunk "text": chunk
@ -97,7 +114,7 @@ class PromptClient(BaseClient):
def request_rows(self, schema, chunk, timeout=300): def request_rows(self, schema, chunk, timeout=300):
return self.call( return self.request(
id="extract-rows", id="extract-rows",
terms={ terms={
"chunk": chunk, "chunk": chunk,
@ -119,11 +136,11 @@ class PromptClient(BaseClient):
def request_kg_prompt(self, query, kg, timeout=300): def request_kg_prompt(self, query, kg, timeout=300):
return self.call( return self.request(
id="kg-prompt", id="kg-prompt",
terms={ terms={
"query": query, "query": query,
"kg": [ "knowledge": [
{ "s": v[0], "p": v[1], "o": v[2] } { "s": v[0], "p": v[1], "o": v[2] }
for v in kg for v in kg
] ]
@ -133,7 +150,7 @@ class PromptClient(BaseClient):
def request_document_prompt(self, query, documents, timeout=300): def request_document_prompt(self, query, documents, timeout=300):
return self.call( return self.request(
id="document-prompt", id="document-prompt",
terms={ terms={
"query": query, "query": query,

View file

@ -166,6 +166,9 @@ class Processor(ConsumerProducer):
kind = v.id kind = v.id
try: try:
print(v.terms)
input = { input = {
k: json.loads(v) k: json.loads(v)
for k, v in v.terms.items() for k, v in v.terms.items()