|
13 | 13 | from typing import Any, Dict, List, Optional, Tuple |
14 | 14 |
|
15 | 15 | import httpx |
| 16 | +import json_repair |
16 | 17 | import requests |
17 | 18 | from anthropic import Anthropic, AsyncAnthropic |
18 | 19 | from anthropic.types.message import Message |
19 | 20 | from mistralai import Mistral |
20 | 21 | from openai import AsyncOpenAI, OpenAI |
21 | 22 | from openai.types.chat import ChatCompletion |
22 | 23 |
|
23 | | -from ..models.generator_info import (HUGGINGFACE_ACTIVATED, GeneratorCompletionParameters, GeneratorInfo, |
24 | | - pretty_messages, torch) |
| 24 | +from ..models.generator_info import (HUGGINGFACE_ACTIVATED, |
| 25 | + GeneratorCompletionParameters, |
| 26 | + GeneratorInfo, pretty_messages, torch) |
25 | 27 | from ..utils.json_utils import extract_json_from_completion, to_dict |
26 | 28 | from ..utils.logging_utils import get_logger |
27 | | -from ..utils.message_utils import (AudioData, ImageData, VideoData, NodeCompletionParameters, |
| 29 | +from ..utils.message_utils import (AudioData, ImageData, |
| 30 | + NodeCompletionParameters, VideoData, |
28 | 31 | base64_to_wav, format_prompt, get_payload, |
29 | 32 | hf_process_messages, |
30 | 33 | merge_contiguous_messages, |
@@ -1345,6 +1348,7 @@ async def collapse_thread(self, |
1345 | 1348 | def from_thread(cls, |
1346 | 1349 | path: str | List[str] | None = None, |
1347 | 1350 | messages: List[Dict[str, str]] | None = None, |
| 1351 | + fix_json: bool = False, |
1348 | 1352 | ) -> ChatNode: |
1349 | 1353 | """Load a thread from a JSON file or multiple JSON files, or directly from messages. |
1350 | 1354 |
|
@@ -1401,7 +1405,7 @@ def from_thread(cls, |
1401 | 1405 | return parent |
1402 | 1406 |
|
1403 | 1407 | # Single path logic |
1404 | | - data = json.load(open(path, "r", encoding="utf-8")) |
| 1408 | + data = (json_repair if fix_json else json).load(open(path, "r", encoding="utf-8")) |
1405 | 1409 | if "required_kwargs" not in data: |
1406 | 1410 | data["required_kwargs"] = {} |
1407 | 1411 |
|
|
0 commit comments