mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-06-24 14:18:05 +02:00
Fix replace strings for JSON (#57)
* Fix replace strings for JSON * Add JSON markdown preamble/postamble in prompts * Remove JSON chicanery in LLM handling * Bump version
This commit is contained in:
parent
3445759598
commit
375b213a54
25 changed files with 277 additions and 276 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 = []
|
||||
|
|
|
|||
|
|
@ -134,10 +134,7 @@ class Processor(ConsumerProducer):
|
|||
|
||||
print("Send response...", flush=True)
|
||||
|
||||
resp = response.replace("```json", "")
|
||||
resp = response.replace("```", "")
|
||||
|
||||
r = TextCompletionResponse(response=resp, error=None)
|
||||
r = TextCompletionResponse(response=response, error=None)
|
||||
self.producer.send(r, properties={"id": id})
|
||||
|
||||
except TooManyRequests:
|
||||
|
|
|
|||
|
|
@ -213,13 +213,10 @@ class Processor(ConsumerProducer):
|
|||
|
||||
print(outputtext, flush=True)
|
||||
|
||||
resp = outputtext.replace("```json", "")
|
||||
resp = resp.replace("```", "")
|
||||
|
||||
print("Send response...", flush=True)
|
||||
r = TextCompletionResponse(
|
||||
error=None,
|
||||
response=resp
|
||||
response=outputtext
|
||||
)
|
||||
|
||||
self.send(r, properties={"id": id})
|
||||
|
|
|
|||
|
|
@ -93,9 +93,6 @@ class Processor(ConsumerProducer):
|
|||
resp = output.text
|
||||
print(resp, flush=True)
|
||||
|
||||
resp = resp.replace("```json", "")
|
||||
resp = resp.replace("```", "")
|
||||
|
||||
print("Send response...", flush=True)
|
||||
r = TextCompletionResponse(response=resp, error=None)
|
||||
self.send(r, properties={"id": id})
|
||||
|
|
|
|||
|
|
@ -87,10 +87,7 @@ class Processor(ConsumerProducer):
|
|||
|
||||
print("Send response...", flush=True)
|
||||
|
||||
resp = response.replace("```json", "")
|
||||
resp = response.replace("```", "")
|
||||
|
||||
r = TextCompletionResponse(response=resp, error=None)
|
||||
r = TextCompletionResponse(response=response, error=None)
|
||||
|
||||
self.send(r, properties={"id": id})
|
||||
|
||||
|
|
|
|||
|
|
@ -148,9 +148,6 @@ class Processor(ConsumerProducer):
|
|||
|
||||
resp = resp.text
|
||||
|
||||
resp = resp.replace("```json", "")
|
||||
resp = resp.replace("```", "")
|
||||
|
||||
print("Send response...", flush=True)
|
||||
|
||||
r = TextCompletionResponse(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue