mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Automatic repair of json for langchains agent (#444)
* Added json_repair to Pipfile * Automatic repair of json for langchains agent
This commit is contained in:
parent
0e3c86ad59
commit
4404b9af24
1
Pipfile
1
Pipfile
@ -25,6 +25,7 @@ llama-index-embeddings-azure-openai = "*"
|
||||
llama-index-embeddings-ollama = "*"
|
||||
google-generativeai = "*"
|
||||
toml = "*"
|
||||
json_repair = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import json
|
||||
from json_repair import repair_json
|
||||
|
||||
def my_encoder(obj):
|
||||
if hasattr(obj, "to_dict"):
|
||||
@ -8,5 +9,11 @@ def dumps(obj, **kwargs):
|
||||
return json.dumps(obj, default=my_encoder, **kwargs)
|
||||
|
||||
def loads(s, **kwargs):
|
||||
return json.loads(s, **kwargs)
|
||||
s_repaired = repair_json(s)
|
||||
|
||||
if s_repaired != s:
|
||||
print(f"Repaired JSON: {s_repaired}")
|
||||
print(f"Original JSON: {s}")
|
||||
|
||||
return json.loads(s_repaired, **kwargs)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user