mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-04-25 11:18:22 +00:00
* feat: implement backend logic * feat: implement api/config endpoint * rename the symbol * feat: re-implement configuration at client-side * feat: add client-side of deep thinking * fix backend bug * feat: add reasoning block * docs: update readme * fix: translate into English * fix: change icon to lightbulb * feat: ignore more bad cases * feat: adjust thinking layout, and implement auto scrolling * docs: add comments --------- Co-authored-by: Henry Li <henry1943@163.com>
21 lines
475 B
TypeScript
21 lines
475 B
TypeScript
import { parse } from "best-effort-json-parser";
|
|
|
|
export function parseJSON<T>(json: string | null | undefined, fallback: T) {
|
|
if (!json) {
|
|
return fallback;
|
|
}
|
|
try {
|
|
const raw = json
|
|
.trim()
|
|
.replace(/^```js\s*/, "")
|
|
.replace(/^```json\s*/, "")
|
|
.replace(/^```ts\s*/, "")
|
|
.replace(/^```plaintext\s*/, "")
|
|
.replace(/^```\s*/, "")
|
|
.replace(/\s*```$/, "");
|
|
return parse(raw) as T;
|
|
} catch {
|
|
return fallback;
|
|
}
|
|
}
|