Feat/add json process tool (#5555)

This commit is contained in:
scotlandowl 2024-06-28 11:57:32 +08:00 committed by GitHub
parent d37ee498cd
commit 73ce945d40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 971 additions and 3 deletions

View File

@ -23,7 +23,6 @@ RUN apt-get update \
COPY pyproject.toml poetry.lock ./
RUN poetry install --sync --no-cache --no-root
# production stage
FROM base AS production

View File

@ -0,0 +1,358 @@
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="800px" height="800px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
<path fill="#000000" opacity="1.000000" stroke="none"
d="
M440.000000,513.000000
C318.311890,513.000000 196.623810,513.000000 74.361206,512.639771
C64.559074,509.683868 57.815937,503.042450 57.833218,492.112061
C58.078167,337.217957 58.013832,182.323349 57.973289,27.428858
C57.970104,15.265683 62.303032,5.957079 74.000000,1.000000
C163.021439,1.000000 252.042862,1.000000 341.625610,1.348149
C345.142975,3.645721 348.528595,5.163025 350.990173,7.609907
C383.608673,40.033493 416.110992,72.574051 448.602142,105.125519
C452.926758,109.458168 456.021118,114.420891 456.019745,120.909180
C455.993103,245.722153 456.014618,370.535126 455.897339,495.348022
C455.894958,497.899719 454.591217,500.555237 453.492096,502.979889
C450.875824,508.751221 444.846985,510.119446 440.000000,513.000000
M366.978119,199.901535
C369.117279,207.612961 366.369415,211.534317 358.493073,213.066147
C347.313721,215.240341 341.474335,220.552567 341.074768,233.635300
C340.718811,245.290588 341.031738,256.965515 340.962433,268.631287
C340.953094,270.204163 340.549042,271.804688 340.135101,273.340454
C336.846710,285.540741 327.903870,291.009766 316.258209,292.941132
C311.229645,293.775116 305.727173,289.384583 305.007721,284.516754
C304.352203,280.081848 308.674255,274.864807 313.719055,274.001587
C320.467743,272.846802 322.964508,270.011108 322.988403,263.233551
C323.030060,251.400864 322.963043,239.567703 323.040649,227.735382
C323.052002,226.000977 323.275970,224.122147 323.970245,222.563431
C326.870880,216.051224 329.988434,209.635635 333.192719,202.831619
C326.426208,195.915558 322.583832,186.895432 322.930969,175.984161
C323.254089,165.828217 323.237183,155.646591 322.923828,145.490036
C322.679443,137.569260 320.212494,134.596237 313.449707,133.900467
C307.694611,133.308395 303.831635,127.815491 305.026062,122.888168
C306.393799,117.246071 311.519958,114.295715 317.603271,115.914719
C322.316040,117.168953 326.941986,118.749199 331.715271,120.217987
C331.715271,86.963776 331.715271,53.124226 331.715271,19.000000
C329.691101,19.000000 327.888062,19.000000 326.085052,19.000000
C245.588547,19.000000 165.091934,19.051859 84.595734,18.897024
C78.460266,18.885223 76.980110,20.178017 76.981697,26.607189
C77.007530,131.269318 76.999062,235.931442 77.009834,340.593567
C77.009979,342.021515 77.157974,343.449432 77.225998,344.679138
C197.379150,344.679138 317.114136,344.679138 436.678070,344.679138
C436.678070,271.288025 436.678070,198.218109 436.678070,125.119888
C402.751251,125.119888 369.146515,125.119888 334.952972,125.119888
C340.186554,130.577667 341.144653,136.947769 341.041077,143.752930
C340.883881,154.083420 340.893738,164.419510 341.032501,174.750519
C341.150604,183.545593 345.705109,192.539749 356.132355,194.157852
C359.932648,194.747604 364.410126,194.923218 366.978119,199.901535
M99.500328,495.000000
C209.807632,495.000000 320.114929,495.000885 430.422241,494.997711
C436.530823,494.997528 436.996490,494.537018 436.997253,488.477234
C437.002533,448.153442 437.002380,407.829620 436.990417,367.505829
C436.989990,366.069763 436.847900,364.633728 436.775208,363.260925
C316.708221,363.260925 196.989700,363.260925 77.000443,363.260925
C77.000443,405.815277 77.005440,448.109253 76.991074,490.403229
C76.989914,493.829926 78.785522,495.063477 82.004829,495.020294
C87.502541,494.946472 93.001953,494.999969 99.500328,495.000000
M414.501068,98.000717
C393.237640,76.730530 371.974243,55.460354 350.350098,33.829334
C350.350098,58.274117 350.350098,82.091644 350.350098,105.614235
C374.367645,105.614235 398.034149,105.614235 422.273895,105.614235
C419.523987,102.924950 417.262665,100.713478 414.501068,98.000717
z"/>
<path fill="#FFFFFF" opacity="1.000000" stroke="none"
d="
M440.468658,513.000000
C444.846985,510.119446 450.875824,508.751221 453.492096,502.979889
C454.591217,500.555237 455.894958,497.899719 455.897339,495.348022
C456.014618,370.535126 455.993103,245.722153 456.019745,120.909180
C456.021118,114.420891 452.926758,109.458168 448.602142,105.125519
C416.110992,72.574051 383.608673,40.033493 350.990173,7.609907
C348.528595,5.163025 345.142975,3.645721 342.093445,1.348149
C398.967010,1.000000 455.934052,1.000000 512.947754,1.000000
C512.947754,171.666672 512.947754,342.333344 512.947754,513.000000
C488.909485,513.000000 464.923401,513.000000 440.468658,513.000000
z"/>
<path fill="#FFFFFF" opacity="1.000000" stroke="none"
d="
M73.531342,1.000000
C62.303032,5.957079 57.970104,15.265683 57.973289,27.428858
C58.013832,182.323349 58.078167,337.217957 57.833218,492.112061
C57.815937,503.042450 64.559074,509.683868 73.893349,512.639771
C49.682854,513.000000 25.365705,513.000000 1.051913,513.000000
C1.055266,342.333313 1.055266,171.666656 1.055266,1.000000
C25.094584,1.000000 49.078632,1.000000 73.531342,1.000000
z"/>
<path fill="#FFFFFF" opacity="1.000000" stroke="none"
d="
M366.836029,199.531494
C364.410126,194.923218 359.932648,194.747604 356.132355,194.157852
C345.705109,192.539749 341.150604,183.545593 341.032501,174.750519
C340.893738,164.419510 340.883881,154.083420 341.041077,143.752930
C341.144653,136.947769 340.186554,130.577667 334.952972,125.119888
C369.146515,125.119888 402.751251,125.119888 436.678070,125.119888
C436.678070,198.218109 436.678070,271.288025 436.678070,344.679138
C317.114136,344.679138 197.379150,344.679138 77.225998,344.679138
C77.157974,343.449432 77.009979,342.021515 77.009834,340.593567
C76.999062,235.931442 77.007530,131.269318 76.981697,26.607189
C76.980110,20.178017 78.460266,18.885223 84.595734,18.897024
C165.091934,19.051859 245.588547,19.000000 326.085052,19.000000
C327.888062,19.000000 329.691101,19.000000 331.715271,19.000000
C331.715271,53.124226 331.715271,86.963776 331.715271,120.217987
C326.941986,118.749199 322.316040,117.168953 317.603271,115.914719
C311.519958,114.295715 306.393799,117.246071 305.026062,122.888168
C303.831635,127.815491 307.694611,133.308395 313.449707,133.900467
C320.212494,134.596237 322.679443,137.569260 322.923828,145.490036
C323.237183,155.646591 323.254089,165.828217 322.930969,175.984161
C322.583832,186.895432 326.426208,195.915558 333.192719,202.831619
C329.988434,209.635635 326.870880,216.051224 323.970245,222.563431
C323.275970,224.122147 323.052002,226.000977 323.040649,227.735382
C322.963043,239.567703 323.030060,251.400864 322.988403,263.233551
C322.964508,270.011108 320.467743,272.846802 313.719055,274.001587
C308.674255,274.864807 304.352203,280.081848 305.007721,284.516754
C305.727173,289.384583 311.229645,293.775116 316.258209,292.941132
C327.903870,291.009766 336.846710,285.540741 340.135101,273.340454
C340.549042,271.804688 340.953094,270.204163 340.962433,268.631287
C341.031738,256.965515 340.718811,245.290588 341.074768,233.635300
C341.474335,220.552567 347.313721,215.240341 358.493073,213.066147
C366.369415,211.534317 369.117279,207.612961 366.836029,199.531494
M182.000000,177.422882
C182.000015,166.766098 181.941956,156.108887 182.020081,145.452682
C182.073685,138.140335 184.514847,135.351959 191.688156,133.986618
C197.498215,132.880768 200.738052,128.511368 199.997711,122.779953
C199.465897,118.662819 194.211258,114.500763 189.642517,115.047340
C175.145996,116.781601 163.832031,126.721329 163.979736,142.462234
C164.084396,153.617599 164.175415,164.778244 163.950836,175.930069
C163.724686,187.160156 157.235809,193.880295 146.197006,194.981110
C140.909790,195.508377 137.208603,198.986603 137.041122,203.851685
C136.879623,208.543121 140.441101,212.170456 145.901154,213.009750
C158.178909,214.897079 164.129654,221.464417 164.021164,233.790421
C163.921539,245.112396 163.965256,256.436188 164.040192,267.758514
C164.050552,269.324982 164.561020,270.897400 164.911804,272.450867
C167.741211,284.981628 176.707840,290.578583 188.364777,292.951080
C193.486618,293.993530 199.171814,290.232880 199.990570,285.607758
C200.977966,280.029877 197.746597,275.301605 192.075760,274.026489
C183.972946,272.204498 182.011292,269.768707 182.002945,261.436707
C181.991257,249.780838 182.028961,238.124786 181.965988,226.469238
C181.957428,224.883957 181.834717,223.136993 181.173981,221.745468
C178.250565,215.588577 175.111282,209.534180 171.780624,202.906372
C177.713211,196.714767 182.694809,188.772705 182.000000,177.422882
M250.383209,221.958359
C244.307816,222.434525 243.355164,227.209244 243.121643,231.654785
C242.695038,239.776031 242.898300,247.937424 243.032745,256.078857
C243.137711,262.435181 246.908463,266.015350 253.081116,265.999969
C258.225464,265.987183 261.884125,262.037903 261.970093,256.032257
C262.089050,247.724091 262.331055,239.395462 261.893921,231.108658
C261.551788,224.623245 258.907257,221.480042 250.383209,221.958359
M251.699158,186.999924
C252.363052,186.999741 253.035309,187.068237 253.689529,186.988602
C259.431183,186.289719 265.228912,181.317688 265.992828,176.467712
C267.144592,169.155426 264.488861,163.874557 258.411652,160.865662
C252.236679,157.808365 245.765503,159.888138 242.033386,164.450058
C236.731155,170.931274 237.230164,183.378647 251.699158,186.999924
z"/>
<path fill="#FFFFFF" opacity="1.000000" stroke="none"
d="
M99.000488,495.000000
C93.001953,494.999969 87.502541,494.946472 82.004829,495.020294
C78.785522,495.063477 76.989914,493.829926 76.991074,490.403229
C77.005440,448.109253 77.000443,405.815277 77.000443,363.260925
C196.989700,363.260925 316.708221,363.260925 436.775208,363.260925
C436.847900,364.633728 436.989990,366.069763 436.990417,367.505829
C437.002380,407.829620 437.002533,448.153442 436.997253,488.477234
C436.996490,494.537018 436.530823,494.997528 430.422241,494.997711
C320.114929,495.000885 209.807632,495.000000 99.000488,495.000000
M405.000000,404.501648
C405.000000,399.070221 405.000000,393.638794 405.000000,388.289429
C399.350769,388.289429 394.279053,388.289429 388.808350,388.289429
C388.808350,407.889954 388.808350,427.203949 388.808350,447.411774
C384.211212,439.340485 380.118225,432.115601 375.988220,424.911987
C369.350128,413.333679 362.725952,401.746857 355.969238,390.238007
C355.367493,389.213013 353.868408,388.164062 352.731995,388.101074
C348.291229,387.854828 343.828735,388.000519 339.198486,388.000519
C339.198486,418.138733 339.198486,447.871521 339.198486,477.799072
C344.467834,477.799072 349.538574,477.799072 355.228302,477.799072
C355.228302,458.220612 355.228302,438.834808 355.228302,418.395264
C362.098145,430.695770 368.300354,441.952332 374.653351,453.123108
C378.945007,460.669250 383.399170,468.124969 387.914764,475.539459
C388.558258,476.596008 389.924377,477.825470 391.018158,477.888062
C395.601654,478.150238 400.208801,477.998657 405.000000,477.998657
C405.000000,453.445496 405.000000,429.473358 405.000000,404.501648
M249.029984,409.674683
C244.443970,422.396851 244.099213,435.159607 246.816910,448.492706
C250.405960,466.100769 265.181366,481.234924 287.536591,478.135254
C303.050751,475.984131 312.179932,467.197815 316.983734,453.058441
C320.799469,441.827393 320.893433,430.226501 318.740967,418.734650
C317.785858,413.635254 316.032288,408.318268 313.247284,403.998749
C305.424744,391.865997 294.190857,386.060760 279.351105,386.874664
C267.074921,387.547974 253.106033,397.334015 249.029984,409.674683
M221.546494,432.959717
C215.483154,429.650574 209.455063,426.274536 203.345032,423.053955
C198.664124,420.586670 195.198013,416.460022 195.565277,411.658569
C195.823029,408.288879 199.076233,403.748199 202.178314,402.335052
C206.477051,400.376770 212.050064,399.818909 216.787628,400.547089
C223.952087,401.648376 223.847519,402.339783 226.997971,396.016388
C227.709503,394.588226 228.405746,393.152435 229.211212,391.512054
C228.268005,390.957336 227.507462,390.190887 226.647095,390.054565
C219.794693,388.968933 212.952759,387.622345 206.050934,387.089020
C195.661774,386.286224 183.521027,394.612457 181.726105,404.903015
C179.537735,417.449280 180.249863,423.735474 192.618317,432.078583
C198.589371,436.106415 205.157074,439.238434 211.266983,443.074890
C217.277954,446.849182 219.199615,451.604858 217.396255,457.108582
C214.714783,465.292175 207.826859,467.238220 198.130508,465.516632
C192.827927,464.575104 187.711472,462.585236 182.383682,461.030945
C181.843887,463.553223 181.725784,466.262970 180.664871,468.531799
C179.246613,471.564819 180.257889,472.684326 182.914948,474.064758
C193.024017,479.316986 203.623688,480.203674 214.252014,476.886292
C226.684174,473.005859 231.700348,465.366669 232.693680,453.904785
C233.412491,445.610474 229.602097,438.072449 221.546494,432.959717
M161.000000,403.501251
C161.000000,397.742493 161.000000,391.983734 161.000000,386.273438
C155.372482,386.273438 150.305389,386.273438 145.000000,386.273438
C145.000000,408.317474 144.790802,430.092010 145.100967,451.859131
C145.228500,460.810181 140.277298,465.677521 131.822754,464.862946
C124.911293,464.197052 118.116318,462.322052 110.791100,460.889465
C109.158188,463.512695 107.050209,466.899139 104.834747,470.458221
C116.388779,476.730621 128.261826,480.706543 141.458939,477.962372
C147.681381,476.668518 153.237366,474.416382 157.177109,468.673157
C160.686386,463.557404 160.676559,457.864136 160.834900,452.416595
C161.298798,436.456482 161.000000,420.474213 161.000000,403.501251
z"/>
<path fill="#FFFFFF" opacity="1.000000" stroke="none"
d="
M414.751221,98.251358
C417.262665,100.713478 419.523987,102.924950 422.273895,105.614235
C398.034149,105.614235 374.367645,105.614235 350.350098,105.614235
C350.350098,82.091644 350.350098,58.274117 350.350098,33.829334
C371.974243,55.460354 393.237640,76.730530 414.751221,98.251358
z"/>
<path fill="#000000" opacity="1.000000" stroke="none"
d="
M182.000000,177.908478
C182.694809,188.772705 177.713211,196.714767 171.780624,202.906372
C175.111282,209.534180 178.250565,215.588577 181.173981,221.745468
C181.834717,223.136993 181.957428,224.883957 181.965988,226.469238
C182.028961,238.124786 181.991257,249.780838 182.002945,261.436707
C182.011292,269.768707 183.972946,272.204498 192.075760,274.026489
C197.746597,275.301605 200.977966,280.029877 199.990570,285.607758
C199.171814,290.232880 193.486618,293.993530 188.364777,292.951080
C176.707840,290.578583 167.741211,284.981628 164.911804,272.450867
C164.561020,270.897400 164.050552,269.324982 164.040192,267.758514
C163.965256,256.436188 163.921539,245.112396 164.021164,233.790421
C164.129654,221.464417 158.178909,214.897079 145.901154,213.009750
C140.441101,212.170456 136.879623,208.543121 137.041122,203.851685
C137.208603,198.986603 140.909790,195.508377 146.197006,194.981110
C157.235809,193.880295 163.724686,187.160156 163.950836,175.930069
C164.175415,164.778244 164.084396,153.617599 163.979736,142.462234
C163.832031,126.721329 175.145996,116.781601 189.642517,115.047340
C194.211258,114.500763 199.465897,118.662819 199.997711,122.779953
C200.738052,128.511368 197.498215,132.880768 191.688156,133.986618
C184.514847,135.351959 182.073685,138.140335 182.020081,145.452682
C181.941956,156.108887 182.000015,166.766098 182.000000,177.908478
z"/>
<path fill="#000000" opacity="1.000000" stroke="none"
d="
M250.701447,221.715332
C258.907257,221.480042 261.551788,224.623245 261.893921,231.108658
C262.331055,239.395462 262.089050,247.724091 261.970093,256.032257
C261.884125,262.037903 258.225464,265.987183 253.081116,265.999969
C246.908463,266.015350 243.137711,262.435181 243.032745,256.078857
C242.898300,247.937424 242.695038,239.776031 243.121643,231.654785
C243.355164,227.209244 244.307816,222.434525 250.701447,221.715332
z"/>
<path fill="#000000" opacity="1.000000" stroke="none"
d="
M251.279205,186.999359
C237.230164,183.378647 236.731155,170.931274 242.033386,164.450058
C245.765503,159.888138 252.236679,157.808365 258.411652,160.865662
C264.488861,163.874557 267.144592,169.155426 265.992828,176.467712
C265.228912,181.317688 259.431183,186.289719 253.689529,186.988602
C253.035309,187.068237 252.363052,186.999741 251.279205,186.999359
z"/>
<path fill="#000000" opacity="1.000000" stroke="none"
d="
M405.000000,405.001465
C405.000000,429.473358 405.000000,453.445496 405.000000,477.998657
C400.208801,477.998657 395.601654,478.150238 391.018158,477.888062
C389.924377,477.825470 388.558258,476.596008 387.914764,475.539459
C383.399170,468.124969 378.945007,460.669250 374.653351,453.123108
C368.300354,441.952332 362.098145,430.695770 355.228302,418.395264
C355.228302,438.834808 355.228302,458.220612 355.228302,477.799072
C349.538574,477.799072 344.467834,477.799072 339.198486,477.799072
C339.198486,447.871521 339.198486,418.138733 339.198486,388.000519
C343.828735,388.000519 348.291229,387.854828 352.731995,388.101074
C353.868408,388.164062 355.367493,389.213013 355.969238,390.238007
C362.725952,401.746857 369.350128,413.333679 375.988220,424.911987
C380.118225,432.115601 384.211212,439.340485 388.808350,447.411774
C388.808350,427.203949 388.808350,407.889954 388.808350,388.289429
C394.279053,388.289429 399.350769,388.289429 405.000000,388.289429
C405.000000,393.638794 405.000000,399.070221 405.000000,405.001465
z"/>
<path fill="#000000" opacity="1.000000" stroke="none"
d="
M249.257431,409.344086
C253.106033,397.334015 267.074921,387.547974 279.351105,386.874664
C294.190857,386.060760 305.424744,391.865997 313.247284,403.998749
C316.032288,408.318268 317.785858,413.635254 318.740967,418.734650
C320.893433,430.226501 320.799469,441.827393 316.983734,453.058441
C312.179932,467.197815 303.050751,475.984131 287.536591,478.135254
C265.181366,481.234924 250.405960,466.100769 246.816910,448.492706
C244.099213,435.159607 244.443970,422.396851 249.257431,409.344086
M303.000214,444.354126
C304.869690,433.936218 304.954620,423.566223 300.930511,413.623352
C298.190186,406.852509 293.962067,400.948883 285.988159,400.100525
C277.932068,399.243378 270.543945,401.250763 266.534851,409.100616
C264.324493,413.428467 262.298431,418.183380 261.699341,422.936127
C260.164398,435.113220 259.872131,447.203949 267.469269,458.136475
C272.404816,465.238861 282.116241,467.730164 289.150177,464.478760
C297.547394,460.597198 300.930969,453.473236 303.000214,444.354126
z"/>
<path fill="#000000" opacity="1.000000" stroke="none"
d="
M221.914734,432.992401
C229.602097,438.072449 233.412491,445.610474 232.693680,453.904785
C231.700348,465.366669 226.684174,473.005859 214.252014,476.886292
C203.623688,480.203674 193.024017,479.316986 182.914948,474.064758
C180.257889,472.684326 179.246613,471.564819 180.664871,468.531799
C181.725784,466.262970 181.843887,463.553223 182.383682,461.030945
C187.711472,462.585236 192.827927,464.575104 198.130508,465.516632
C207.826859,467.238220 214.714783,465.292175 217.396255,457.108582
C219.199615,451.604858 217.277954,446.849182 211.266983,443.074890
C205.157074,439.238434 198.589371,436.106415 192.618317,432.078583
C180.249863,423.735474 179.537735,417.449280 181.726105,404.903015
C183.521027,394.612457 195.661774,386.286224 206.050934,387.089020
C212.952759,387.622345 219.794693,388.968933 226.647095,390.054565
C227.507462,390.190887 228.268005,390.957336 229.211212,391.512054
C228.405746,393.152435 227.709503,394.588226 226.997971,396.016388
C223.847519,402.339783 223.952087,401.648376 216.787628,400.547089
C212.050064,399.818909 206.477051,400.376770 202.178314,402.335052
C199.076233,403.748199 195.823029,408.288879 195.565277,411.658569
C195.198013,416.460022 198.664124,420.586670 203.345032,423.053955
C209.455063,426.274536 215.483154,429.650574 221.914734,432.992401
z"/>
<path fill="#000000" opacity="1.000000" stroke="none"
d="
M161.000000,404.000916
C161.000000,420.474213 161.298798,436.456482 160.834900,452.416595
C160.676559,457.864136 160.686386,463.557404 157.177109,468.673157
C153.237366,474.416382 147.681381,476.668518 141.458939,477.962372
C128.261826,480.706543 116.388779,476.730621 104.834747,470.458221
C107.050209,466.899139 109.158188,463.512695 110.791100,460.889465
C118.116318,462.322052 124.911293,464.197052 131.822754,464.862946
C140.277298,465.677521 145.228500,460.810181 145.100967,451.859131
C144.790802,430.092010 145.000000,408.317474 145.000000,386.273438
C150.305389,386.273438 155.372482,386.273438 161.000000,386.273438
C161.000000,391.983734 161.000000,397.742493 161.000000,404.000916
z"/>
<path fill="#FFFFFF" opacity="1.000000" stroke="none"
d="
M302.999329,444.791046
C300.930969,453.473236 297.547394,460.597198 289.150177,464.478760
C282.116241,467.730164 272.404816,465.238861 267.469269,458.136475
C259.872131,447.203949 260.164398,435.113220 261.699341,422.936127
C262.298431,418.183380 264.324493,413.428467 266.534851,409.100616
C270.543945,401.250763 277.932068,399.243378 285.988159,400.100525
C293.962067,400.948883 298.190186,406.852509 300.930511,413.623352
C304.954620,423.566223 304.869690,433.936218 302.999329,444.791046
z"/>
</svg>

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -0,0 +1,17 @@
from typing import Any
from core.tools.errors import ToolProviderCredentialValidationError
from core.tools.provider.builtin.json_process.tools.parse import JSONParseTool
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
class JsonExtractProvider(BuiltinToolProviderController):
def _validate_credentials(self, credentials: dict[str, Any]) -> None:
try:
JSONParseTool().invoke(user_id='',
tool_parameters={
'content': '{"name": "John", "age": 30, "city": "New York"}',
'json_filter': '$.name'
})
except Exception as e:
raise ToolProviderCredentialValidationError(str(e))

View File

@ -0,0 +1,14 @@
identity:
author: Mingwei Zhang
name: json_process
label:
en_US: JSON Process
zh_Hans: JSON 处理
pt_BR: JSON Process
description:
en_US: Tools for processing JSON content using jsonpath_ng
zh_Hans: 利用 jsonpath_ng 处理 JSON 内容的工具
pt_BR: Tools for processing JSON content using jsonpath_ng
icon: icon.svg
tags:
- utilities

View File

@ -0,0 +1,59 @@
import json
from typing import Any, Union
from jsonpath_ng import parse
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
class JSONDeleteTool(BuiltinTool):
def _invoke(self,
user_id: str,
tool_parameters: dict[str, Any],
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
"""
Invoke the JSON delete tool
"""
# Get content
content = tool_parameters.get('content', '')
if not content:
return self.create_text_message('Invalid parameter content')
# Get query
query = tool_parameters.get('query', '')
if not query:
return self.create_text_message('Invalid parameter query')
try:
result = self._delete(content, query)
return self.create_text_message(str(result))
except Exception as e:
return self.create_text_message(f'Failed to delete JSON content: {str(e)}')
def _delete(self, origin_json: str, query: str) -> str:
try:
input_data = json.loads(origin_json)
expr = parse('$.' + query.lstrip('$.')) # Ensure query path starts with $
matches = expr.find(input_data)
if not matches:
return json.dumps(input_data, ensure_ascii=True) # No changes if no matches found
for match in matches:
if isinstance(match.context.value, dict):
# Delete key from dictionary
del match.context.value[match.path.fields[-1]]
elif isinstance(match.context.value, list):
# Remove item from list
match.context.value.remove(match.value)
else:
# For other cases, we might want to set to None or remove the parent key
parent = match.context.parent
if parent:
del parent.value[match.path.fields[-1]]
return json.dumps(input_data, ensure_ascii=True)
except Exception as e:
raise Exception(f"Delete operation failed: {str(e)}")

View File

@ -0,0 +1,40 @@
identity:
name: json_delete
author: Mingwei Zhang
label:
en_US: JSON Delete
zh_Hans: JSON 删除
pt_BR: JSON Delete
description:
human:
en_US: A tool for deleting JSON content
zh_Hans: 一个删除 JSON 内容的工具
pt_BR: A tool for deleting JSON content
llm: A tool for deleting JSON content
parameters:
- name: content
type: string
required: true
label:
en_US: JSON content
zh_Hans: JSON 内容
pt_BR: JSON content
human_description:
en_US: JSON content to be processed
zh_Hans: 待处理的 JSON 内容
pt_BR: JSON content to be processed
llm_description: JSON content to be processed
form: llm
- name: query
type: string
required: true
label:
en_US: Query
zh_Hans: 查询
pt_BR: Query
human_description:
en_US: JSONPath query to locate the element to delete
zh_Hans: 用于定位要删除元素的 JSONPath 查询
pt_BR: JSONPath query to locate the element to delete
llm_description: JSONPath query to locate the element to delete
form: llm

View File

@ -0,0 +1,97 @@
import json
from typing import Any, Union
from jsonpath_ng import parse
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
class JSONParseTool(BuiltinTool):
def _invoke(self,
user_id: str,
tool_parameters: dict[str, Any],
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
"""
invoke tools
"""
# get content
content = tool_parameters.get('content', '')
if not content:
return self.create_text_message('Invalid parameter content')
# get query
query = tool_parameters.get('query', '')
if not query:
return self.create_text_message('Invalid parameter query')
# get new value
new_value = tool_parameters.get('new_value', '')
if not new_value:
return self.create_text_message('Invalid parameter new_value')
# get insert position
index = tool_parameters.get('index')
# get create path
create_path = tool_parameters.get('create_path', False)
try:
result = self._insert(content, query, new_value, index, create_path)
return self.create_text_message(str(result))
except Exception:
return self.create_text_message('Failed to insert JSON content')
def _insert(self, origin_json, query, new_value, index=None, create_path=False):
try:
input_data = json.loads(origin_json)
expr = parse(query)
try:
new_value = json.loads(new_value)
except json.JSONDecodeError:
new_value = new_value
matches = expr.find(input_data)
if not matches and create_path:
# create new path
path_parts = query.strip('$').strip('.').split('.')
current = input_data
for i, part in enumerate(path_parts):
if '[' in part and ']' in part:
# process array index
array_name, index = part.split('[')
index = int(index.rstrip(']'))
if array_name not in current:
current[array_name] = []
while len(current[array_name]) <= index:
current[array_name].append({})
current = current[array_name][index]
else:
if i == len(path_parts) - 1:
current[part] = new_value
elif part not in current:
current[part] = {}
current = current[part]
else:
for match in matches:
if isinstance(match.value, dict):
# insert new value into dict
if isinstance(new_value, dict):
match.value.update(new_value)
else:
raise ValueError("Cannot insert non-dict value into dict")
elif isinstance(match.value, list):
# insert new value into list
if index is None:
match.value.append(new_value)
else:
match.value.insert(int(index), new_value)
else:
# replace old value with new value
match.full_path.update(input_data, new_value)
return json.dumps(input_data, ensure_ascii=True)
except Exception as e:
return str(e)

View File

@ -0,0 +1,77 @@
identity:
name: json_insert
author: Mingwei Zhang
label:
en_US: JSON Insert
zh_Hans: JSON 插入
pt_BR: JSON Insert
description:
human:
en_US: A tool for inserting JSON content
zh_Hans: 一个插入 JSON 内容的工具
pt_BR: A tool for inserting JSON content
llm: A tool for inserting JSON content
parameters:
- name: content
type: string
required: true
label:
en_US: JSON content
zh_Hans: JSON 内容
pt_BR: JSON content
human_description:
en_US: JSON content
zh_Hans: JSON 内容
pt_BR: JSON content
llm_description: JSON content to be processed
form: llm
- name: query
type: string
required: true
label:
en_US: Query
zh_Hans: 查询
pt_BR: Query
human_description:
en_US: Object to insert
zh_Hans: 待插入的对象
pt_BR: Object to insert
llm_description: JSONPath query to locate the element to insert
form: llm
- name: new_value
type: string
required: true
label:
en_US: New Value
zh_Hans: 新值
pt_BR: New Value
human_description:
en_US: New Value
zh_Hans: 新值
pt_BR: New Value
llm_description: New Value to insert
form: llm
- name: create_path
type: select
required: true
default: "False"
label:
en_US: Whether to create a path
zh_Hans: 是否创建路径
pt_BR: Whether to create a path
human_description:
en_US: Whether to create a path when the path does not exist
zh_Hans: 查询路径不存在时是否创建路径
pt_BR: Whether to create a path when the path does not exist
options:
- value: "True"
label:
en_US: "Yes"
zh_Hans:
pt_BR: "Yes"
- value: "False"
label:
en_US: "No"
zh_Hans:
pt_BR: "No"
form: form

View File

@ -0,0 +1,51 @@
import json
from typing import Any, Union
from jsonpath_ng import parse
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
class JSONParseTool(BuiltinTool):
def _invoke(self,
user_id: str,
tool_parameters: dict[str, Any],
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
"""
invoke tools
"""
# get content
content = tool_parameters.get('content', '')
if not content:
return self.create_text_message('Invalid parameter content')
# get json filter
json_filter = tool_parameters.get('json_filter', '')
if not json_filter:
return self.create_text_message('Invalid parameter json_filter')
try:
result = self._extract(content, json_filter)
return self.create_text_message(str(result))
except Exception:
return self.create_text_message('Failed to extract JSON content')
# Extract data from JSON content
def _extract(self, content: str, json_filter: str) -> str:
try:
input_data = json.loads(content)
expr = parse(json_filter)
result = [match.value for match in expr.find(input_data)]
if len(result) == 1:
result = result[0]
if isinstance(result, dict | list):
return json.dumps(result, ensure_ascii=True)
elif isinstance(result, str | int | float | bool) or result is None:
return str(result)
else:
return repr(result)
except Exception as e:
return str(e)

View File

@ -0,0 +1,40 @@
identity:
name: parse
author: Mingwei Zhang
label:
en_US: JSON Parse
zh_Hans: JSON 解析
pt_BR: JSON Parse
description:
human:
en_US: A tool for extracting JSON objects
zh_Hans: 一个解析JSON对象的工具
pt_BR: A tool for extracting JSON objects
llm: A tool for extracting JSON objects
parameters:
- name: content
type: string
required: true
label:
en_US: JSON data
zh_Hans: JSON数据
pt_BR: JSON data
human_description:
en_US: JSON data
zh_Hans: JSON数据
pt_BR: JSON数据
llm_description: JSON data to be processed
form: llm
- name: json_filter
type: string
required: true
label:
en_US: JSON filter
zh_Hans: JSON解析对象
pt_BR: JSON filter
human_description:
en_US: JSON fields to be parsed
zh_Hans: 需要解析的 JSON 字段
pt_BR: JSON fields to be parsed
llm_description: JSON fields to be parsed
form: llm

View File

@ -0,0 +1,106 @@
import json
from typing import Any, Union
from jsonpath_ng import parse
from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
class JSONReplaceTool(BuiltinTool):
def _invoke(self,
user_id: str,
tool_parameters: dict[str, Any],
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
"""
invoke tools
"""
# get content
content = tool_parameters.get('content', '')
if not content:
return self.create_text_message('Invalid parameter content')
# get query
query = tool_parameters.get('query', '')
if not query:
return self.create_text_message('Invalid parameter query')
# get replace value
replace_value = tool_parameters.get('replace_value', '')
if not replace_value:
return self.create_text_message('Invalid parameter replace_value')
# get replace model
replace_model = tool_parameters.get('replace_model', '')
if not replace_model:
return self.create_text_message('Invalid parameter replace_model')
try:
if replace_model == 'pattern':
# get replace pattern
replace_pattern = tool_parameters.get('replace_pattern', '')
if not replace_pattern:
return self.create_text_message('Invalid parameter replace_pattern')
result = self._replace_pattern(content, query, replace_pattern, replace_value)
elif replace_model == 'key':
result = self._replace_key(content, query, replace_value)
elif replace_model == 'value':
result = self._replace_value(content, query, replace_value)
return self.create_text_message(str(result))
except Exception:
return self.create_text_message('Failed to replace JSON content')
# Replace pattern
def _replace_pattern(self, content: str, query: str, replace_pattern: str, replace_value: str) -> str:
try:
input_data = json.loads(content)
expr = parse(query)
matches = expr.find(input_data)
for match in matches:
new_value = match.value.replace(replace_pattern, replace_value)
match.full_path.update(input_data, new_value)
return json.dumps(input_data, ensure_ascii=True)
except Exception as e:
return str(e)
# Replace key
def _replace_key(self, content: str, query: str, replace_value: str) -> str:
try:
input_data = json.loads(content)
expr = parse(query)
matches = expr.find(input_data)
for match in matches:
parent = match.context.value
if isinstance(parent, dict):
old_key = match.path.fields[0]
if old_key in parent:
value = parent.pop(old_key)
parent[replace_value] = value
elif isinstance(parent, list):
for item in parent:
if isinstance(item, dict) and old_key in item:
value = item.pop(old_key)
item[replace_value] = value
return json.dumps(input_data, ensure_ascii=True)
except Exception as e:
return str(e)
# Replace value
def _replace_value(self, content: str, query: str, replace_value: str) -> str:
try:
input_data = json.loads(content)
expr = parse(query)
matches = expr.find(input_data)
for match in matches:
match.full_path.update(input_data, replace_value)
return json.dumps(input_data, ensure_ascii=True)
except Exception as e:
return str(e)

View File

@ -0,0 +1,95 @@
identity:
name: json_replace
author: Mingwei Zhang
label:
en_US: JSON Replace
zh_Hans: JSON 替换
pt_BR: JSON Replace
description:
human:
en_US: A tool for replacing JSON content
zh_Hans: 一个替换 JSON 内容的工具
pt_BR: A tool for replacing JSON content
llm: A tool for replacing JSON content
parameters:
- name: content
type: string
required: true
label:
en_US: JSON content
zh_Hans: JSON 内容
pt_BR: JSON content
human_description:
en_US: JSON content
zh_Hans: JSON 内容
pt_BR: JSON content
llm_description: JSON content to be processed
form: llm
- name: query
type: string
required: true
label:
en_US: Query
zh_Hans: 查询
pt_BR: Query
human_description:
en_US: Query
zh_Hans: 查询
pt_BR: Query
llm_description: JSONPath query to locate the element to replace
form: llm
- name: replace_pattern
type: string
required: false
label:
en_US: String to be replaced
zh_Hans: 待替换字符串
pt_BR: String to be replaced
human_description:
en_US: String to be replaced
zh_Hans: 待替换字符串
pt_BR: String to be replaced
llm_description: String to be replaced
form: llm
- name: replace_value
type: string
required: true
label:
en_US: Replace Value
zh_Hans: 替换值
pt_BR: Replace Value
human_description:
en_US: New Value
zh_Hans: New Value
pt_BR: New Value
llm_description: New Value to replace
form: llm
- name: replace_model
type: select
required: true
default: pattern
label:
en_US: Replace Model
zh_Hans: 替换模式
pt_BR: Replace Model
human_description:
en_US: Replace Model
zh_Hans: 替换模式
pt_BR: Replace Model
options:
- value: key
label:
en_US: replace key
zh_Hans: 键替换
pt_BR: replace key
- value: value
label:
en_US: replace value
zh_Hans: 值替换
pt_BR: replace value
- value: pattern
label:
en_US: replace string
zh_Hans: 字符串替换
pt_BR: replace string
form: form

16
api/poetry.lock generated
View File

@ -3702,6 +3702,20 @@ files = [
{file = "joblib-1.4.2.tar.gz", hash = "sha256:2382c5816b2636fbd20a09e0f4e9dad4736765fdfb7dca582943b9c1366b3f0e"},
]
[[package]]
name = "jsonpath-ng"
version = "1.6.1"
description = "A final implementation of JSONPath for Python that aims to be standard compliant, including arithmetic and binary comparison operators and providing clear AST for metaprogramming."
optional = false
python-versions = "*"
files = [
{file = "jsonpath-ng-1.6.1.tar.gz", hash = "sha256:086c37ba4917304850bd837aeab806670224d3f038fe2833ff593a672ef0a5fa"},
{file = "jsonpath_ng-1.6.1-py3-none-any.whl", hash = "sha256:8f22cd8273d7772eea9aaa84d922e0841aa36fdb8a2c6b7f6c3791a16a9bc0be"},
]
[package.dependencies]
ply = "*"
[[package]]
name = "kaleido"
version = "0.2.1"
@ -9081,4 +9095,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"]
[metadata]
lock-version = "2.0"
python-versions = "^3.10"
content-hash = "5f6f7d8114ece4f7e865fdf9a1fc38a86238d6bc80333b878d50c95a7885b9f5"
content-hash = "d40bed69caecf3a2bcd5ec054288d7cb36a9a231fff210d4f1a42745dd3bf604"

View File

@ -187,6 +187,7 @@ arxiv = "2.1.0"
matplotlib = "~3.8.2"
newspaper3k = "0.2.8"
duckduckgo-search = "~6.1.5"
jsonpath-ng = "1.6.1"
numexpr = "~2.9.0"
opensearch-py = "2.4.0"
qrcode = "~7.4.2"
@ -246,4 +247,4 @@ optional = true
[tool.poetry.group.lint.dependencies]
ruff = "~0.4.8"
dotenv-linter = "~0.5.0"
dotenv-linter = "~0.5.0"