mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-16 16:51:02 +02:00
Add JSON markdown preamble/postamble in prompts
This commit is contained in:
parent
a50efe901e
commit
8819bbc467
2 changed files with 22 additions and 6 deletions
|
|
@ -55,6 +55,14 @@ class Processor(ConsumerProducer):
|
|||
pulsar_host = self.pulsar_host
|
||||
)
|
||||
|
||||
def parse_json(self, text):
|
||||
|
||||
# Hacky, workaround temperamental JSON markdown
|
||||
text = text.replace("```json", "")
|
||||
text = text.replace("```", "")
|
||||
|
||||
return json.loads(text)
|
||||
|
||||
def handle(self, msg):
|
||||
|
||||
v = msg.value()
|
||||
|
|
@ -107,7 +115,7 @@ class Processor(ConsumerProducer):
|
|||
|
||||
# Silently ignore JSON parse error
|
||||
try:
|
||||
defs = json.loads(ans)
|
||||
defs = self.parse_json(ans)
|
||||
except:
|
||||
print("JSON parse error, ignored", flush=True)
|
||||
defs = []
|
||||
|
|
@ -166,7 +174,7 @@ class Processor(ConsumerProducer):
|
|||
|
||||
# Silently ignore JSON parse error
|
||||
try:
|
||||
defs = json.loads(ans)
|
||||
defs = self.parse_json(ans)
|
||||
except:
|
||||
print("JSON parse error, ignored", flush=True)
|
||||
defs = []
|
||||
|
|
@ -244,7 +252,7 @@ class Processor(ConsumerProducer):
|
|||
|
||||
# Silently ignore JSON parse error
|
||||
try:
|
||||
objs = json.loads(ans)
|
||||
objs = self.parse_json(ans)
|
||||
except:
|
||||
print("JSON parse error, ignored", flush=True)
|
||||
objs = []
|
||||
|
|
|
|||
|
|
@ -67,6 +67,14 @@ class Processor(ConsumerProducer):
|
|||
self.knowledge_query_template = knowledge_query_template
|
||||
self.document_query_template = document_query_template
|
||||
|
||||
def parse_json(self, text):
|
||||
|
||||
# Hacky, workaround temperamental JSON markdown
|
||||
text = text.replace("```json", "")
|
||||
text = text.replace("```", "")
|
||||
|
||||
return json.loads(text)
|
||||
|
||||
def handle(self, msg):
|
||||
|
||||
v = msg.value()
|
||||
|
|
@ -119,7 +127,7 @@ class Processor(ConsumerProducer):
|
|||
|
||||
# Silently ignore JSON parse error
|
||||
try:
|
||||
defs = json.loads(ans)
|
||||
defs = self.parse_json(ans)
|
||||
except:
|
||||
print("JSON parse error, ignored", flush=True)
|
||||
defs = []
|
||||
|
|
@ -178,7 +186,7 @@ class Processor(ConsumerProducer):
|
|||
|
||||
# Silently ignore JSON parse error
|
||||
try:
|
||||
defs = json.loads(ans)
|
||||
defs = self.parse_json(ans)
|
||||
except:
|
||||
print("JSON parse error, ignored", flush=True)
|
||||
defs = []
|
||||
|
|
@ -256,7 +264,7 @@ class Processor(ConsumerProducer):
|
|||
|
||||
# Silently ignore JSON parse error
|
||||
try:
|
||||
objs = json.loads(ans)
|
||||
objs = self.parse_json(ans)
|
||||
except:
|
||||
print("JSON parse error, ignored", flush=True)
|
||||
objs = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue