mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-16 16:51:02 +02:00
All tests working
This commit is contained in:
parent
5e86a3c3ae
commit
629ab0d3ea
3 changed files with 27 additions and 7 deletions
|
|
@ -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",
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue