您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

datasets_document.py 45KB

4 个月前
4 个月前
Introduce Plugins (#13836) Signed-off-by: yihong0618 <zouzou0208@gmail.com> Signed-off-by: -LAN- <laipz8200@outlook.com> Signed-off-by: xhe <xw897002528@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: takatost <takatost@gmail.com> Co-authored-by: kurokobo <kuro664@gmail.com> Co-authored-by: Novice Lee <novicelee@NoviPro.local> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: AkaraChen <akarachen@outlook.com> Co-authored-by: Yi <yxiaoisme@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: Hiroshi Fujita <fujita-h@users.noreply.github.com> Co-authored-by: AkaraChen <85140972+AkaraChen@users.noreply.github.com> Co-authored-by: NFish <douxc512@gmail.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Novice <857526207@qq.com> Co-authored-by: Hiroki Nagai <82458324+nagaihiroki-git@users.noreply.github.com> Co-authored-by: Gen Sato <52241300+halogen22@users.noreply.github.com> Co-authored-by: eux <euxuuu@gmail.com> Co-authored-by: huangzhuo1949 <167434202+huangzhuo1949@users.noreply.github.com> Co-authored-by: huangzhuo <huangzhuo1@xiaomi.com> Co-authored-by: lotsik <lotsik@mail.ru> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: gakkiyomi <gakkiyomi@aliyun.com> Co-authored-by: CN-P5 <heibai2006@gmail.com> Co-authored-by: CN-P5 <heibai2006@qq.com> Co-authored-by: Chuehnone <1897025+chuehnone@users.noreply.github.com> Co-authored-by: yihong <zouzou0208@gmail.com> Co-authored-by: Kevin9703 <51311316+Kevin9703@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: Boris Feld <lothiraldan@gmail.com> Co-authored-by: mbo <himabo@gmail.com> Co-authored-by: mabo <mabo@aeyes.ai> Co-authored-by: Warren Chen <warren.chen830@gmail.com> Co-authored-by: JzoNgKVO <27049666+JzoNgKVO@users.noreply.github.com> Co-authored-by: jiandanfeng <chenjh3@wangsu.com> Co-authored-by: zhu-an <70234959+xhdd123321@users.noreply.github.com> Co-authored-by: zhaoqingyu.1075 <zhaoqingyu.1075@bytedance.com> Co-authored-by: 海狸大師 <86974027+yenslife@users.noreply.github.com> Co-authored-by: Xu Song <xusong.vip@gmail.com> Co-authored-by: rayshaw001 <396301947@163.com> Co-authored-by: Ding Jiatong <dingjiatong@gmail.com> Co-authored-by: Bowen Liang <liangbowen@gf.com.cn> Co-authored-by: JasonVV <jasonwangiii@outlook.com> Co-authored-by: le0zh <newlight@qq.com> Co-authored-by: zhuxinliang <zhuxinliang@didiglobal.com> Co-authored-by: k-zaku <zaku99@outlook.jp> Co-authored-by: luckylhb90 <luckylhb90@gmail.com> Co-authored-by: hobo.l <hobo.l@binance.com> Co-authored-by: jiangbo721 <365065261@qq.com> Co-authored-by: 刘江波 <jiangbo721@163.com> Co-authored-by: Shun Miyazawa <34241526+miya@users.noreply.github.com> Co-authored-by: EricPan <30651140+Egfly@users.noreply.github.com> Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: sino <sino2322@gmail.com> Co-authored-by: Jhvcc <37662342+Jhvcc@users.noreply.github.com> Co-authored-by: lowell <lowell.hu@zkteco.in> Co-authored-by: Boris Polonsky <BorisPolonsky@users.noreply.github.com> Co-authored-by: Ademílson Tonato <ademilsonft@outlook.com> Co-authored-by: Ademílson Tonato <ademilson.tonato@refurbed.com> Co-authored-by: IWAI, Masaharu <iwaim.sub@gmail.com> Co-authored-by: Yueh-Po Peng (Yabi) <94939112+y10ab1@users.noreply.github.com> Co-authored-by: Jason <ggbbddjm@gmail.com> Co-authored-by: Xin Zhang <sjhpzx@gmail.com> Co-authored-by: yjc980121 <3898524+yjc980121@users.noreply.github.com> Co-authored-by: heyszt <36215648+hieheihei@users.noreply.github.com> Co-authored-by: Abdullah AlOsaimi <osaimiacc@gmail.com> Co-authored-by: Abdullah AlOsaimi <189027247+osaimi@users.noreply.github.com> Co-authored-by: Yingchun Lai <laiyingchun@apache.org> Co-authored-by: Hash Brown <hi@xzd.me> Co-authored-by: zuodongxu <192560071+zuodongxu@users.noreply.github.com> Co-authored-by: Masashi Tomooka <tmokmss@users.noreply.github.com> Co-authored-by: aplio <ryo.091219@gmail.com> Co-authored-by: Obada Khalili <54270856+obadakhalili@users.noreply.github.com> Co-authored-by: Nam Vu <zuzoovn@gmail.com> Co-authored-by: Kei YAMAZAKI <1715090+kei-yamazaki@users.noreply.github.com> Co-authored-by: TechnoHouse <13776377+deephbz@users.noreply.github.com> Co-authored-by: Riddhimaan-Senapati <114703025+Riddhimaan-Senapati@users.noreply.github.com> Co-authored-by: MaFee921 <31881301+2284730142@users.noreply.github.com> Co-authored-by: te-chan <t-nakanome@sakura-is.co.jp> Co-authored-by: HQidea <HQidea@users.noreply.github.com> Co-authored-by: Joshbly <36315710+Joshbly@users.noreply.github.com> Co-authored-by: xhe <xw897002528@gmail.com> Co-authored-by: weiwenyan-dev <154779315+weiwenyan-dev@users.noreply.github.com> Co-authored-by: ex_wenyan.wei <ex_wenyan.wei@tcl.com> Co-authored-by: engchina <12236799+engchina@users.noreply.github.com> Co-authored-by: engchina <atjapan2015@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 呆萌闷油瓶 <253605712@qq.com> Co-authored-by: Kemal <kemalmeler@outlook.com> Co-authored-by: Lazy_Frog <4590648+lazyFrogLOL@users.noreply.github.com> Co-authored-by: Yi Xiao <54782454+YIXIAO0@users.noreply.github.com> Co-authored-by: Steven sun <98230804+Tuyohai@users.noreply.github.com> Co-authored-by: steven <sunzwj@digitalchina.com> Co-authored-by: Kalo Chin <91766386+fdb02983rhy@users.noreply.github.com> Co-authored-by: Katy Tao <34019945+KatyTao@users.noreply.github.com> Co-authored-by: depy <42985524+h4ckdepy@users.noreply.github.com> Co-authored-by: 胡春东 <gycm520@gmail.com> Co-authored-by: Junjie.M <118170653@qq.com> Co-authored-by: MuYu <mr.muzea@gmail.com> Co-authored-by: Naoki Takashima <39912547+takatea@users.noreply.github.com> Co-authored-by: Summer-Gu <37869445+gubinjie@users.noreply.github.com> Co-authored-by: Fei He <droxer.he@gmail.com> Co-authored-by: ybalbert001 <120714773+ybalbert001@users.noreply.github.com> Co-authored-by: Yuanbo Li <ybalbert@amazon.com> Co-authored-by: douxc <7553076+douxc@users.noreply.github.com> Co-authored-by: liuzhenghua <1090179900@qq.com> Co-authored-by: Wu Jiayang <62842862+Wu-Jiayang@users.noreply.github.com> Co-authored-by: Your Name <you@example.com> Co-authored-by: kimjion <45935338+kimjion@users.noreply.github.com> Co-authored-by: AugNSo <song.tiankai@icloud.com> Co-authored-by: llinvokerl <38915183+llinvokerl@users.noreply.github.com> Co-authored-by: liusurong.lsr <liusurong.lsr@alibaba-inc.com> Co-authored-by: Vasu Negi <vasu-negi@users.noreply.github.com> Co-authored-by: Hundredwz <1808096180@qq.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
8 个月前
Introduce Plugins (#13836) Signed-off-by: yihong0618 <zouzou0208@gmail.com> Signed-off-by: -LAN- <laipz8200@outlook.com> Signed-off-by: xhe <xw897002528@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: takatost <takatost@gmail.com> Co-authored-by: kurokobo <kuro664@gmail.com> Co-authored-by: Novice Lee <novicelee@NoviPro.local> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: AkaraChen <akarachen@outlook.com> Co-authored-by: Yi <yxiaoisme@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: Hiroshi Fujita <fujita-h@users.noreply.github.com> Co-authored-by: AkaraChen <85140972+AkaraChen@users.noreply.github.com> Co-authored-by: NFish <douxc512@gmail.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Novice <857526207@qq.com> Co-authored-by: Hiroki Nagai <82458324+nagaihiroki-git@users.noreply.github.com> Co-authored-by: Gen Sato <52241300+halogen22@users.noreply.github.com> Co-authored-by: eux <euxuuu@gmail.com> Co-authored-by: huangzhuo1949 <167434202+huangzhuo1949@users.noreply.github.com> Co-authored-by: huangzhuo <huangzhuo1@xiaomi.com> Co-authored-by: lotsik <lotsik@mail.ru> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: gakkiyomi <gakkiyomi@aliyun.com> Co-authored-by: CN-P5 <heibai2006@gmail.com> Co-authored-by: CN-P5 <heibai2006@qq.com> Co-authored-by: Chuehnone <1897025+chuehnone@users.noreply.github.com> Co-authored-by: yihong <zouzou0208@gmail.com> Co-authored-by: Kevin9703 <51311316+Kevin9703@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: Boris Feld <lothiraldan@gmail.com> Co-authored-by: mbo <himabo@gmail.com> Co-authored-by: mabo <mabo@aeyes.ai> Co-authored-by: Warren Chen <warren.chen830@gmail.com> Co-authored-by: JzoNgKVO <27049666+JzoNgKVO@users.noreply.github.com> Co-authored-by: jiandanfeng <chenjh3@wangsu.com> Co-authored-by: zhu-an <70234959+xhdd123321@users.noreply.github.com> Co-authored-by: zhaoqingyu.1075 <zhaoqingyu.1075@bytedance.com> Co-authored-by: 海狸大師 <86974027+yenslife@users.noreply.github.com> Co-authored-by: Xu Song <xusong.vip@gmail.com> Co-authored-by: rayshaw001 <396301947@163.com> Co-authored-by: Ding Jiatong <dingjiatong@gmail.com> Co-authored-by: Bowen Liang <liangbowen@gf.com.cn> Co-authored-by: JasonVV <jasonwangiii@outlook.com> Co-authored-by: le0zh <newlight@qq.com> Co-authored-by: zhuxinliang <zhuxinliang@didiglobal.com> Co-authored-by: k-zaku <zaku99@outlook.jp> Co-authored-by: luckylhb90 <luckylhb90@gmail.com> Co-authored-by: hobo.l <hobo.l@binance.com> Co-authored-by: jiangbo721 <365065261@qq.com> Co-authored-by: 刘江波 <jiangbo721@163.com> Co-authored-by: Shun Miyazawa <34241526+miya@users.noreply.github.com> Co-authored-by: EricPan <30651140+Egfly@users.noreply.github.com> Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: sino <sino2322@gmail.com> Co-authored-by: Jhvcc <37662342+Jhvcc@users.noreply.github.com> Co-authored-by: lowell <lowell.hu@zkteco.in> Co-authored-by: Boris Polonsky <BorisPolonsky@users.noreply.github.com> Co-authored-by: Ademílson Tonato <ademilsonft@outlook.com> Co-authored-by: Ademílson Tonato <ademilson.tonato@refurbed.com> Co-authored-by: IWAI, Masaharu <iwaim.sub@gmail.com> Co-authored-by: Yueh-Po Peng (Yabi) <94939112+y10ab1@users.noreply.github.com> Co-authored-by: Jason <ggbbddjm@gmail.com> Co-authored-by: Xin Zhang <sjhpzx@gmail.com> Co-authored-by: yjc980121 <3898524+yjc980121@users.noreply.github.com> Co-authored-by: heyszt <36215648+hieheihei@users.noreply.github.com> Co-authored-by: Abdullah AlOsaimi <osaimiacc@gmail.com> Co-authored-by: Abdullah AlOsaimi <189027247+osaimi@users.noreply.github.com> Co-authored-by: Yingchun Lai <laiyingchun@apache.org> Co-authored-by: Hash Brown <hi@xzd.me> Co-authored-by: zuodongxu <192560071+zuodongxu@users.noreply.github.com> Co-authored-by: Masashi Tomooka <tmokmss@users.noreply.github.com> Co-authored-by: aplio <ryo.091219@gmail.com> Co-authored-by: Obada Khalili <54270856+obadakhalili@users.noreply.github.com> Co-authored-by: Nam Vu <zuzoovn@gmail.com> Co-authored-by: Kei YAMAZAKI <1715090+kei-yamazaki@users.noreply.github.com> Co-authored-by: TechnoHouse <13776377+deephbz@users.noreply.github.com> Co-authored-by: Riddhimaan-Senapati <114703025+Riddhimaan-Senapati@users.noreply.github.com> Co-authored-by: MaFee921 <31881301+2284730142@users.noreply.github.com> Co-authored-by: te-chan <t-nakanome@sakura-is.co.jp> Co-authored-by: HQidea <HQidea@users.noreply.github.com> Co-authored-by: Joshbly <36315710+Joshbly@users.noreply.github.com> Co-authored-by: xhe <xw897002528@gmail.com> Co-authored-by: weiwenyan-dev <154779315+weiwenyan-dev@users.noreply.github.com> Co-authored-by: ex_wenyan.wei <ex_wenyan.wei@tcl.com> Co-authored-by: engchina <12236799+engchina@users.noreply.github.com> Co-authored-by: engchina <atjapan2015@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 呆萌闷油瓶 <253605712@qq.com> Co-authored-by: Kemal <kemalmeler@outlook.com> Co-authored-by: Lazy_Frog <4590648+lazyFrogLOL@users.noreply.github.com> Co-authored-by: Yi Xiao <54782454+YIXIAO0@users.noreply.github.com> Co-authored-by: Steven sun <98230804+Tuyohai@users.noreply.github.com> Co-authored-by: steven <sunzwj@digitalchina.com> Co-authored-by: Kalo Chin <91766386+fdb02983rhy@users.noreply.github.com> Co-authored-by: Katy Tao <34019945+KatyTao@users.noreply.github.com> Co-authored-by: depy <42985524+h4ckdepy@users.noreply.github.com> Co-authored-by: 胡春东 <gycm520@gmail.com> Co-authored-by: Junjie.M <118170653@qq.com> Co-authored-by: MuYu <mr.muzea@gmail.com> Co-authored-by: Naoki Takashima <39912547+takatea@users.noreply.github.com> Co-authored-by: Summer-Gu <37869445+gubinjie@users.noreply.github.com> Co-authored-by: Fei He <droxer.he@gmail.com> Co-authored-by: ybalbert001 <120714773+ybalbert001@users.noreply.github.com> Co-authored-by: Yuanbo Li <ybalbert@amazon.com> Co-authored-by: douxc <7553076+douxc@users.noreply.github.com> Co-authored-by: liuzhenghua <1090179900@qq.com> Co-authored-by: Wu Jiayang <62842862+Wu-Jiayang@users.noreply.github.com> Co-authored-by: Your Name <you@example.com> Co-authored-by: kimjion <45935338+kimjion@users.noreply.github.com> Co-authored-by: AugNSo <song.tiankai@icloud.com> Co-authored-by: llinvokerl <38915183+llinvokerl@users.noreply.github.com> Co-authored-by: liusurong.lsr <liusurong.lsr@alibaba-inc.com> Co-authored-by: Vasu Negi <vasu-negi@users.noreply.github.com> Co-authored-by: Hundredwz <1808096180@qq.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
8 个月前
Introduce Plugins (#13836) Signed-off-by: yihong0618 <zouzou0208@gmail.com> Signed-off-by: -LAN- <laipz8200@outlook.com> Signed-off-by: xhe <xw897002528@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: takatost <takatost@gmail.com> Co-authored-by: kurokobo <kuro664@gmail.com> Co-authored-by: Novice Lee <novicelee@NoviPro.local> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: AkaraChen <akarachen@outlook.com> Co-authored-by: Yi <yxiaoisme@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: Hiroshi Fujita <fujita-h@users.noreply.github.com> Co-authored-by: AkaraChen <85140972+AkaraChen@users.noreply.github.com> Co-authored-by: NFish <douxc512@gmail.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Novice <857526207@qq.com> Co-authored-by: Hiroki Nagai <82458324+nagaihiroki-git@users.noreply.github.com> Co-authored-by: Gen Sato <52241300+halogen22@users.noreply.github.com> Co-authored-by: eux <euxuuu@gmail.com> Co-authored-by: huangzhuo1949 <167434202+huangzhuo1949@users.noreply.github.com> Co-authored-by: huangzhuo <huangzhuo1@xiaomi.com> Co-authored-by: lotsik <lotsik@mail.ru> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: gakkiyomi <gakkiyomi@aliyun.com> Co-authored-by: CN-P5 <heibai2006@gmail.com> Co-authored-by: CN-P5 <heibai2006@qq.com> Co-authored-by: Chuehnone <1897025+chuehnone@users.noreply.github.com> Co-authored-by: yihong <zouzou0208@gmail.com> Co-authored-by: Kevin9703 <51311316+Kevin9703@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: Boris Feld <lothiraldan@gmail.com> Co-authored-by: mbo <himabo@gmail.com> Co-authored-by: mabo <mabo@aeyes.ai> Co-authored-by: Warren Chen <warren.chen830@gmail.com> Co-authored-by: JzoNgKVO <27049666+JzoNgKVO@users.noreply.github.com> Co-authored-by: jiandanfeng <chenjh3@wangsu.com> Co-authored-by: zhu-an <70234959+xhdd123321@users.noreply.github.com> Co-authored-by: zhaoqingyu.1075 <zhaoqingyu.1075@bytedance.com> Co-authored-by: 海狸大師 <86974027+yenslife@users.noreply.github.com> Co-authored-by: Xu Song <xusong.vip@gmail.com> Co-authored-by: rayshaw001 <396301947@163.com> Co-authored-by: Ding Jiatong <dingjiatong@gmail.com> Co-authored-by: Bowen Liang <liangbowen@gf.com.cn> Co-authored-by: JasonVV <jasonwangiii@outlook.com> Co-authored-by: le0zh <newlight@qq.com> Co-authored-by: zhuxinliang <zhuxinliang@didiglobal.com> Co-authored-by: k-zaku <zaku99@outlook.jp> Co-authored-by: luckylhb90 <luckylhb90@gmail.com> Co-authored-by: hobo.l <hobo.l@binance.com> Co-authored-by: jiangbo721 <365065261@qq.com> Co-authored-by: 刘江波 <jiangbo721@163.com> Co-authored-by: Shun Miyazawa <34241526+miya@users.noreply.github.com> Co-authored-by: EricPan <30651140+Egfly@users.noreply.github.com> Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: sino <sino2322@gmail.com> Co-authored-by: Jhvcc <37662342+Jhvcc@users.noreply.github.com> Co-authored-by: lowell <lowell.hu@zkteco.in> Co-authored-by: Boris Polonsky <BorisPolonsky@users.noreply.github.com> Co-authored-by: Ademílson Tonato <ademilsonft@outlook.com> Co-authored-by: Ademílson Tonato <ademilson.tonato@refurbed.com> Co-authored-by: IWAI, Masaharu <iwaim.sub@gmail.com> Co-authored-by: Yueh-Po Peng (Yabi) <94939112+y10ab1@users.noreply.github.com> Co-authored-by: Jason <ggbbddjm@gmail.com> Co-authored-by: Xin Zhang <sjhpzx@gmail.com> Co-authored-by: yjc980121 <3898524+yjc980121@users.noreply.github.com> Co-authored-by: heyszt <36215648+hieheihei@users.noreply.github.com> Co-authored-by: Abdullah AlOsaimi <osaimiacc@gmail.com> Co-authored-by: Abdullah AlOsaimi <189027247+osaimi@users.noreply.github.com> Co-authored-by: Yingchun Lai <laiyingchun@apache.org> Co-authored-by: Hash Brown <hi@xzd.me> Co-authored-by: zuodongxu <192560071+zuodongxu@users.noreply.github.com> Co-authored-by: Masashi Tomooka <tmokmss@users.noreply.github.com> Co-authored-by: aplio <ryo.091219@gmail.com> Co-authored-by: Obada Khalili <54270856+obadakhalili@users.noreply.github.com> Co-authored-by: Nam Vu <zuzoovn@gmail.com> Co-authored-by: Kei YAMAZAKI <1715090+kei-yamazaki@users.noreply.github.com> Co-authored-by: TechnoHouse <13776377+deephbz@users.noreply.github.com> Co-authored-by: Riddhimaan-Senapati <114703025+Riddhimaan-Senapati@users.noreply.github.com> Co-authored-by: MaFee921 <31881301+2284730142@users.noreply.github.com> Co-authored-by: te-chan <t-nakanome@sakura-is.co.jp> Co-authored-by: HQidea <HQidea@users.noreply.github.com> Co-authored-by: Joshbly <36315710+Joshbly@users.noreply.github.com> Co-authored-by: xhe <xw897002528@gmail.com> Co-authored-by: weiwenyan-dev <154779315+weiwenyan-dev@users.noreply.github.com> Co-authored-by: ex_wenyan.wei <ex_wenyan.wei@tcl.com> Co-authored-by: engchina <12236799+engchina@users.noreply.github.com> Co-authored-by: engchina <atjapan2015@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 呆萌闷油瓶 <253605712@qq.com> Co-authored-by: Kemal <kemalmeler@outlook.com> Co-authored-by: Lazy_Frog <4590648+lazyFrogLOL@users.noreply.github.com> Co-authored-by: Yi Xiao <54782454+YIXIAO0@users.noreply.github.com> Co-authored-by: Steven sun <98230804+Tuyohai@users.noreply.github.com> Co-authored-by: steven <sunzwj@digitalchina.com> Co-authored-by: Kalo Chin <91766386+fdb02983rhy@users.noreply.github.com> Co-authored-by: Katy Tao <34019945+KatyTao@users.noreply.github.com> Co-authored-by: depy <42985524+h4ckdepy@users.noreply.github.com> Co-authored-by: 胡春东 <gycm520@gmail.com> Co-authored-by: Junjie.M <118170653@qq.com> Co-authored-by: MuYu <mr.muzea@gmail.com> Co-authored-by: Naoki Takashima <39912547+takatea@users.noreply.github.com> Co-authored-by: Summer-Gu <37869445+gubinjie@users.noreply.github.com> Co-authored-by: Fei He <droxer.he@gmail.com> Co-authored-by: ybalbert001 <120714773+ybalbert001@users.noreply.github.com> Co-authored-by: Yuanbo Li <ybalbert@amazon.com> Co-authored-by: douxc <7553076+douxc@users.noreply.github.com> Co-authored-by: liuzhenghua <1090179900@qq.com> Co-authored-by: Wu Jiayang <62842862+Wu-Jiayang@users.noreply.github.com> Co-authored-by: Your Name <you@example.com> Co-authored-by: kimjion <45935338+kimjion@users.noreply.github.com> Co-authored-by: AugNSo <song.tiankai@icloud.com> Co-authored-by: llinvokerl <38915183+llinvokerl@users.noreply.github.com> Co-authored-by: liusurong.lsr <liusurong.lsr@alibaba-inc.com> Co-authored-by: Vasu Negi <vasu-negi@users.noreply.github.com> Co-authored-by: Hundredwz <1808096180@qq.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
8 个月前
5 个月前
4 个月前
4 个月前
4 个月前
4 个月前
4 个月前
4 个月前
4 个月前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. import json
  2. import logging
  3. from argparse import ArgumentTypeError
  4. from typing import cast
  5. from flask import request
  6. from flask_login import current_user
  7. from flask_restful import Resource, marshal, marshal_with, reqparse
  8. from sqlalchemy import asc, desc, select
  9. from werkzeug.exceptions import Forbidden, NotFound
  10. import services
  11. from controllers.console import api
  12. from controllers.console.app.error import (
  13. ProviderModelCurrentlyNotSupportError,
  14. ProviderNotInitializeError,
  15. ProviderQuotaExceededError,
  16. )
  17. from controllers.console.datasets.error import (
  18. ArchivedDocumentImmutableError,
  19. DocumentAlreadyFinishedError,
  20. DocumentIndexingError,
  21. IndexingEstimateError,
  22. InvalidActionError,
  23. InvalidMetadataError,
  24. )
  25. from controllers.console.wraps import (
  26. account_initialization_required,
  27. cloud_edition_billing_rate_limit_check,
  28. cloud_edition_billing_resource_check,
  29. setup_required,
  30. )
  31. from core.errors.error import (
  32. LLMBadRequestError,
  33. ModelCurrentlyNotSupportError,
  34. ProviderTokenNotInitError,
  35. QuotaExceededError,
  36. )
  37. from core.indexing_runner import IndexingRunner
  38. from core.model_manager import ModelManager
  39. from core.model_runtime.entities.model_entities import ModelType
  40. from core.model_runtime.errors.invoke import InvokeAuthorizationError
  41. from core.plugin.impl.exc import PluginDaemonClientSideError
  42. from core.rag.extractor.entity.extract_setting import ExtractSetting
  43. from extensions.ext_database import db
  44. from fields.document_fields import (
  45. dataset_and_document_fields,
  46. document_fields,
  47. document_status_fields,
  48. document_with_segments_fields,
  49. )
  50. from libs.datetime_utils import naive_utc_now
  51. from libs.login import login_required
  52. from models import Dataset, DatasetProcessRule, Document, DocumentSegment, UploadFile
  53. from models.dataset import DocumentPipelineExecutionLog
  54. from services.dataset_service import DatasetService, DocumentService
  55. from services.entities.knowledge_entities.knowledge_entities import KnowledgeConfig
  56. class DocumentResource(Resource):
  57. def get_document(self, dataset_id: str, document_id: str) -> Document:
  58. dataset = DatasetService.get_dataset(dataset_id)
  59. if not dataset:
  60. raise NotFound("Dataset not found.")
  61. try:
  62. DatasetService.check_dataset_permission(dataset, current_user)
  63. except services.errors.account.NoPermissionError as e:
  64. raise Forbidden(str(e))
  65. document = DocumentService.get_document(dataset_id, document_id)
  66. if not document:
  67. raise NotFound("Document not found.")
  68. if document.tenant_id != current_user.current_tenant_id:
  69. raise Forbidden("No permission.")
  70. return document
  71. def get_batch_documents(self, dataset_id: str, batch: str) -> list[Document]:
  72. dataset = DatasetService.get_dataset(dataset_id)
  73. if not dataset:
  74. raise NotFound("Dataset not found.")
  75. try:
  76. DatasetService.check_dataset_permission(dataset, current_user)
  77. except services.errors.account.NoPermissionError as e:
  78. raise Forbidden(str(e))
  79. documents = DocumentService.get_batch_documents(dataset_id, batch)
  80. if not documents:
  81. raise NotFound("Documents not found.")
  82. return documents
  83. class GetProcessRuleApi(Resource):
  84. @setup_required
  85. @login_required
  86. @account_initialization_required
  87. def get(self):
  88. req_data = request.args
  89. document_id = req_data.get("document_id")
  90. # get default rules
  91. mode = DocumentService.DEFAULT_RULES["mode"]
  92. rules = DocumentService.DEFAULT_RULES["rules"]
  93. limits = DocumentService.DEFAULT_RULES["limits"]
  94. if document_id:
  95. # get the latest process rule
  96. document = db.get_or_404(Document, document_id)
  97. dataset = DatasetService.get_dataset(document.dataset_id)
  98. if not dataset:
  99. raise NotFound("Dataset not found.")
  100. try:
  101. DatasetService.check_dataset_permission(dataset, current_user)
  102. except services.errors.account.NoPermissionError as e:
  103. raise Forbidden(str(e))
  104. # get the latest process rule
  105. dataset_process_rule = (
  106. db.session.query(DatasetProcessRule)
  107. .where(DatasetProcessRule.dataset_id == document.dataset_id)
  108. .order_by(DatasetProcessRule.created_at.desc())
  109. .limit(1)
  110. .one_or_none()
  111. )
  112. if dataset_process_rule:
  113. mode = dataset_process_rule.mode
  114. rules = dataset_process_rule.rules_dict
  115. return {"mode": mode, "rules": rules, "limits": limits}
  116. class DatasetDocumentListApi(Resource):
  117. @setup_required
  118. @login_required
  119. @account_initialization_required
  120. def get(self, dataset_id):
  121. dataset_id = str(dataset_id)
  122. page = request.args.get("page", default=1, type=int)
  123. limit = request.args.get("limit", default=20, type=int)
  124. search = request.args.get("keyword", default=None, type=str)
  125. sort = request.args.get("sort", default="-created_at", type=str)
  126. # "yes", "true", "t", "y", "1" convert to True, while others convert to False.
  127. try:
  128. fetch_val = request.args.get("fetch", default="false")
  129. if isinstance(fetch_val, bool):
  130. fetch = fetch_val
  131. else:
  132. if fetch_val.lower() in ("yes", "true", "t", "y", "1"):
  133. fetch = True
  134. elif fetch_val.lower() in ("no", "false", "f", "n", "0"):
  135. fetch = False
  136. else:
  137. raise ArgumentTypeError(
  138. f"Truthy value expected: got {fetch_val} but expected one of yes/no, true/false, t/f, y/n, 1/0 "
  139. f"(case insensitive)."
  140. )
  141. except (ArgumentTypeError, ValueError, Exception):
  142. fetch = False
  143. dataset = DatasetService.get_dataset(dataset_id)
  144. if not dataset:
  145. raise NotFound("Dataset not found.")
  146. try:
  147. DatasetService.check_dataset_permission(dataset, current_user)
  148. except services.errors.account.NoPermissionError as e:
  149. raise Forbidden(str(e))
  150. query = select(Document).filter_by(dataset_id=str(dataset_id), tenant_id=current_user.current_tenant_id)
  151. if search:
  152. search = f"%{search}%"
  153. query = query.where(Document.name.like(search))
  154. if sort.startswith("-"):
  155. sort_logic = desc
  156. sort = sort[1:]
  157. else:
  158. sort_logic = asc
  159. if sort == "hit_count":
  160. sub_query = (
  161. db.select(DocumentSegment.document_id, db.func.sum(DocumentSegment.hit_count).label("total_hit_count"))
  162. .group_by(DocumentSegment.document_id)
  163. .subquery()
  164. )
  165. query = query.outerjoin(sub_query, sub_query.c.document_id == Document.id).order_by(
  166. sort_logic(db.func.coalesce(sub_query.c.total_hit_count, 0)),
  167. sort_logic(Document.position),
  168. )
  169. elif sort == "created_at":
  170. query = query.order_by(
  171. sort_logic(Document.created_at),
  172. sort_logic(Document.position),
  173. )
  174. else:
  175. query = query.order_by(
  176. desc(Document.created_at),
  177. desc(Document.position),
  178. )
  179. paginated_documents = db.paginate(select=query, page=page, per_page=limit, max_per_page=100, error_out=False)
  180. documents = paginated_documents.items
  181. if fetch:
  182. for document in documents:
  183. completed_segments = (
  184. db.session.query(DocumentSegment)
  185. .where(
  186. DocumentSegment.completed_at.isnot(None),
  187. DocumentSegment.document_id == str(document.id),
  188. DocumentSegment.status != "re_segment",
  189. )
  190. .count()
  191. )
  192. total_segments = (
  193. db.session.query(DocumentSegment)
  194. .where(DocumentSegment.document_id == str(document.id), DocumentSegment.status != "re_segment")
  195. .count()
  196. )
  197. document.completed_segments = completed_segments
  198. document.total_segments = total_segments
  199. data = marshal(documents, document_with_segments_fields)
  200. else:
  201. data = marshal(documents, document_fields)
  202. response = {
  203. "data": data,
  204. "has_more": len(documents) == limit,
  205. "limit": limit,
  206. "total": paginated_documents.total,
  207. "page": page,
  208. }
  209. return response
  210. @setup_required
  211. @login_required
  212. @account_initialization_required
  213. @marshal_with(dataset_and_document_fields)
  214. @cloud_edition_billing_resource_check("vector_space")
  215. @cloud_edition_billing_rate_limit_check("knowledge")
  216. def post(self, dataset_id):
  217. dataset_id = str(dataset_id)
  218. dataset = DatasetService.get_dataset(dataset_id)
  219. if not dataset:
  220. raise NotFound("Dataset not found.")
  221. # The role of the current user in the ta table must be admin, owner, or editor
  222. if not current_user.is_dataset_editor:
  223. raise Forbidden()
  224. try:
  225. DatasetService.check_dataset_permission(dataset, current_user)
  226. except services.errors.account.NoPermissionError as e:
  227. raise Forbidden(str(e))
  228. parser = reqparse.RequestParser()
  229. parser.add_argument(
  230. "indexing_technique", type=str, choices=Dataset.INDEXING_TECHNIQUE_LIST, nullable=False, location="json"
  231. )
  232. parser.add_argument("data_source", type=dict, required=False, location="json")
  233. parser.add_argument("process_rule", type=dict, required=False, location="json")
  234. parser.add_argument("duplicate", type=bool, default=True, nullable=False, location="json")
  235. parser.add_argument("original_document_id", type=str, required=False, location="json")
  236. parser.add_argument("doc_form", type=str, default="text_model", required=False, nullable=False, location="json")
  237. parser.add_argument("retrieval_model", type=dict, required=False, nullable=False, location="json")
  238. parser.add_argument("embedding_model", type=str, required=False, nullable=True, location="json")
  239. parser.add_argument("embedding_model_provider", type=str, required=False, nullable=True, location="json")
  240. parser.add_argument(
  241. "doc_language", type=str, default="English", required=False, nullable=False, location="json"
  242. )
  243. args = parser.parse_args()
  244. knowledge_config = KnowledgeConfig(**args)
  245. if not dataset.indexing_technique and not knowledge_config.indexing_technique:
  246. raise ValueError("indexing_technique is required.")
  247. # validate args
  248. DocumentService.document_create_args_validate(knowledge_config)
  249. try:
  250. documents, batch = DocumentService.save_document_with_dataset_id(dataset, knowledge_config, current_user)
  251. dataset = DatasetService.get_dataset(dataset_id)
  252. except ProviderTokenNotInitError as ex:
  253. raise ProviderNotInitializeError(ex.description)
  254. except QuotaExceededError:
  255. raise ProviderQuotaExceededError()
  256. except ModelCurrentlyNotSupportError:
  257. raise ProviderModelCurrentlyNotSupportError()
  258. return {"dataset": dataset, "documents": documents, "batch": batch}
  259. @setup_required
  260. @login_required
  261. @account_initialization_required
  262. @cloud_edition_billing_rate_limit_check("knowledge")
  263. def delete(self, dataset_id):
  264. dataset_id = str(dataset_id)
  265. dataset = DatasetService.get_dataset(dataset_id)
  266. if dataset is None:
  267. raise NotFound("Dataset not found.")
  268. # check user's model setting
  269. DatasetService.check_dataset_model_setting(dataset)
  270. try:
  271. document_ids = request.args.getlist("document_id")
  272. DocumentService.delete_documents(dataset, document_ids)
  273. except services.errors.document.DocumentIndexingError:
  274. raise DocumentIndexingError("Cannot delete document during indexing.")
  275. return {"result": "success"}, 204
  276. class DatasetInitApi(Resource):
  277. @setup_required
  278. @login_required
  279. @account_initialization_required
  280. @marshal_with(dataset_and_document_fields)
  281. @cloud_edition_billing_resource_check("vector_space")
  282. @cloud_edition_billing_rate_limit_check("knowledge")
  283. def post(self):
  284. # The role of the current user in the ta table must be admin, owner, dataset_operator, or editor
  285. if not current_user.is_dataset_editor:
  286. raise Forbidden()
  287. parser = reqparse.RequestParser()
  288. parser.add_argument(
  289. "indexing_technique",
  290. type=str,
  291. choices=Dataset.INDEXING_TECHNIQUE_LIST,
  292. required=True,
  293. nullable=False,
  294. location="json",
  295. )
  296. parser.add_argument("data_source", type=dict, required=True, nullable=True, location="json")
  297. parser.add_argument("process_rule", type=dict, required=True, nullable=True, location="json")
  298. parser.add_argument("doc_form", type=str, default="text_model", required=False, nullable=False, location="json")
  299. parser.add_argument(
  300. "doc_language", type=str, default="English", required=False, nullable=False, location="json"
  301. )
  302. parser.add_argument("retrieval_model", type=dict, required=False, nullable=False, location="json")
  303. parser.add_argument("embedding_model", type=str, required=False, nullable=True, location="json")
  304. parser.add_argument("embedding_model_provider", type=str, required=False, nullable=True, location="json")
  305. args = parser.parse_args()
  306. # The role of the current user in the ta table must be admin, owner, or editor, or dataset_operator
  307. if not current_user.is_dataset_editor:
  308. raise Forbidden()
  309. knowledge_config = KnowledgeConfig(**args)
  310. if knowledge_config.indexing_technique == "high_quality":
  311. if knowledge_config.embedding_model is None or knowledge_config.embedding_model_provider is None:
  312. raise ValueError("embedding model and embedding model provider are required for high quality indexing.")
  313. try:
  314. model_manager = ModelManager()
  315. model_manager.get_model_instance(
  316. tenant_id=current_user.current_tenant_id,
  317. provider=args["embedding_model_provider"],
  318. model_type=ModelType.TEXT_EMBEDDING,
  319. model=args["embedding_model"],
  320. )
  321. except InvokeAuthorizationError:
  322. raise ProviderNotInitializeError(
  323. "No Embedding Model available. Please configure a valid provider in the Settings -> Model Provider."
  324. )
  325. except ProviderTokenNotInitError as ex:
  326. raise ProviderNotInitializeError(ex.description)
  327. # validate args
  328. DocumentService.document_create_args_validate(knowledge_config)
  329. try:
  330. dataset, documents, batch = DocumentService.save_document_without_dataset_id(
  331. tenant_id=current_user.current_tenant_id, knowledge_config=knowledge_config, account=current_user
  332. )
  333. except ProviderTokenNotInitError as ex:
  334. raise ProviderNotInitializeError(ex.description)
  335. except QuotaExceededError:
  336. raise ProviderQuotaExceededError()
  337. except ModelCurrentlyNotSupportError:
  338. raise ProviderModelCurrentlyNotSupportError()
  339. response = {"dataset": dataset, "documents": documents, "batch": batch}
  340. return response
  341. class DocumentIndexingEstimateApi(DocumentResource):
  342. @setup_required
  343. @login_required
  344. @account_initialization_required
  345. def get(self, dataset_id, document_id):
  346. dataset_id = str(dataset_id)
  347. document_id = str(document_id)
  348. document = self.get_document(dataset_id, document_id)
  349. if document.indexing_status in {"completed", "error"}:
  350. raise DocumentAlreadyFinishedError()
  351. data_process_rule = document.dataset_process_rule
  352. data_process_rule_dict = data_process_rule.to_dict()
  353. response = {"tokens": 0, "total_price": 0, "currency": "USD", "total_segments": 0, "preview": []}
  354. if document.data_source_type == "upload_file":
  355. data_source_info = document.data_source_info_dict
  356. if data_source_info and "upload_file_id" in data_source_info:
  357. file_id = data_source_info["upload_file_id"]
  358. file = (
  359. db.session.query(UploadFile)
  360. .where(UploadFile.tenant_id == document.tenant_id, UploadFile.id == file_id)
  361. .first()
  362. )
  363. # raise error if file not found
  364. if not file:
  365. raise NotFound("File not found.")
  366. extract_setting = ExtractSetting(
  367. datasource_type="upload_file", upload_file=file, document_model=document.doc_form
  368. )
  369. indexing_runner = IndexingRunner()
  370. try:
  371. estimate_response = indexing_runner.indexing_estimate(
  372. current_user.current_tenant_id,
  373. [extract_setting],
  374. data_process_rule_dict,
  375. document.doc_form,
  376. "English",
  377. dataset_id,
  378. )
  379. return estimate_response.model_dump(), 200
  380. except LLMBadRequestError:
  381. raise ProviderNotInitializeError(
  382. "No Embedding Model available. Please configure a valid provider "
  383. "in the Settings -> Model Provider."
  384. )
  385. except ProviderTokenNotInitError as ex:
  386. raise ProviderNotInitializeError(ex.description)
  387. except PluginDaemonClientSideError as ex:
  388. raise ProviderNotInitializeError(ex.description)
  389. except Exception as e:
  390. raise IndexingEstimateError(str(e))
  391. return response, 200
  392. class DocumentBatchIndexingEstimateApi(DocumentResource):
  393. @setup_required
  394. @login_required
  395. @account_initialization_required
  396. def get(self, dataset_id, batch):
  397. dataset_id = str(dataset_id)
  398. batch = str(batch)
  399. documents = self.get_batch_documents(dataset_id, batch)
  400. if not documents:
  401. return {"tokens": 0, "total_price": 0, "currency": "USD", "total_segments": 0, "preview": []}, 200
  402. data_process_rule = documents[0].dataset_process_rule
  403. data_process_rule_dict = data_process_rule.to_dict()
  404. info_list = []
  405. extract_settings = []
  406. for document in documents:
  407. if document.indexing_status in {"completed", "error"}:
  408. raise DocumentAlreadyFinishedError()
  409. data_source_info = document.data_source_info_dict
  410. # format document files info
  411. if data_source_info and "upload_file_id" in data_source_info:
  412. file_id = data_source_info["upload_file_id"]
  413. info_list.append(file_id)
  414. # format document notion info
  415. elif (
  416. data_source_info and "notion_workspace_id" in data_source_info and "notion_page_id" in data_source_info
  417. ):
  418. pages = []
  419. page = {"page_id": data_source_info["notion_page_id"], "type": data_source_info["type"]}
  420. pages.append(page)
  421. notion_info = {"workspace_id": data_source_info["notion_workspace_id"], "pages": pages}
  422. info_list.append(notion_info)
  423. if document.data_source_type == "upload_file":
  424. file_id = data_source_info["upload_file_id"]
  425. file_detail = (
  426. db.session.query(UploadFile)
  427. .where(UploadFile.tenant_id == current_user.current_tenant_id, UploadFile.id == file_id)
  428. .first()
  429. )
  430. if file_detail is None:
  431. raise NotFound("File not found.")
  432. extract_setting = ExtractSetting(
  433. datasource_type="upload_file", upload_file=file_detail, document_model=document.doc_form
  434. )
  435. extract_settings.append(extract_setting)
  436. elif document.data_source_type == "notion_import":
  437. extract_setting = ExtractSetting(
  438. datasource_type="notion_import",
  439. notion_info={
  440. "credential_id": data_source_info["credential_id"],
  441. "notion_workspace_id": data_source_info["notion_workspace_id"],
  442. "notion_obj_id": data_source_info["notion_page_id"],
  443. "notion_page_type": data_source_info["type"],
  444. "tenant_id": current_user.current_tenant_id,
  445. },
  446. document_model=document.doc_form,
  447. )
  448. extract_settings.append(extract_setting)
  449. elif document.data_source_type == "website_crawl":
  450. extract_setting = ExtractSetting(
  451. datasource_type="website_crawl",
  452. website_info={
  453. "provider": data_source_info["provider"],
  454. "job_id": data_source_info["job_id"],
  455. "url": data_source_info["url"],
  456. "tenant_id": current_user.current_tenant_id,
  457. "mode": data_source_info["mode"],
  458. "only_main_content": data_source_info["only_main_content"],
  459. },
  460. document_model=document.doc_form,
  461. )
  462. extract_settings.append(extract_setting)
  463. else:
  464. raise ValueError("Data source type not support")
  465. indexing_runner = IndexingRunner()
  466. try:
  467. response = indexing_runner.indexing_estimate(
  468. current_user.current_tenant_id,
  469. extract_settings,
  470. data_process_rule_dict,
  471. document.doc_form,
  472. "English",
  473. dataset_id,
  474. )
  475. return response.model_dump(), 200
  476. except LLMBadRequestError:
  477. raise ProviderNotInitializeError(
  478. "No Embedding Model available. Please configure a valid provider in the Settings -> Model Provider."
  479. )
  480. except ProviderTokenNotInitError as ex:
  481. raise ProviderNotInitializeError(ex.description)
  482. except PluginDaemonClientSideError as ex:
  483. raise ProviderNotInitializeError(ex.description)
  484. except Exception as e:
  485. raise IndexingEstimateError(str(e))
  486. class DocumentBatchIndexingStatusApi(DocumentResource):
  487. @setup_required
  488. @login_required
  489. @account_initialization_required
  490. def get(self, dataset_id, batch):
  491. dataset_id = str(dataset_id)
  492. batch = str(batch)
  493. documents = self.get_batch_documents(dataset_id, batch)
  494. documents_status = []
  495. for document in documents:
  496. completed_segments = (
  497. db.session.query(DocumentSegment)
  498. .where(
  499. DocumentSegment.completed_at.isnot(None),
  500. DocumentSegment.document_id == str(document.id),
  501. DocumentSegment.status != "re_segment",
  502. )
  503. .count()
  504. )
  505. total_segments = (
  506. db.session.query(DocumentSegment)
  507. .where(DocumentSegment.document_id == str(document.id), DocumentSegment.status != "re_segment")
  508. .count()
  509. )
  510. # Create a dictionary with document attributes and additional fields
  511. document_dict = {
  512. "id": document.id,
  513. "indexing_status": "paused" if document.is_paused else document.indexing_status,
  514. "processing_started_at": document.processing_started_at,
  515. "parsing_completed_at": document.parsing_completed_at,
  516. "cleaning_completed_at": document.cleaning_completed_at,
  517. "splitting_completed_at": document.splitting_completed_at,
  518. "completed_at": document.completed_at,
  519. "paused_at": document.paused_at,
  520. "error": document.error,
  521. "stopped_at": document.stopped_at,
  522. "completed_segments": completed_segments,
  523. "total_segments": total_segments,
  524. }
  525. documents_status.append(marshal(document_dict, document_status_fields))
  526. data = {"data": documents_status}
  527. return data
  528. class DocumentIndexingStatusApi(DocumentResource):
  529. @setup_required
  530. @login_required
  531. @account_initialization_required
  532. def get(self, dataset_id, document_id):
  533. dataset_id = str(dataset_id)
  534. document_id = str(document_id)
  535. document = self.get_document(dataset_id, document_id)
  536. completed_segments = (
  537. db.session.query(DocumentSegment)
  538. .where(
  539. DocumentSegment.completed_at.isnot(None),
  540. DocumentSegment.document_id == str(document_id),
  541. DocumentSegment.status != "re_segment",
  542. )
  543. .count()
  544. )
  545. total_segments = (
  546. db.session.query(DocumentSegment)
  547. .where(DocumentSegment.document_id == str(document_id), DocumentSegment.status != "re_segment")
  548. .count()
  549. )
  550. # Create a dictionary with document attributes and additional fields
  551. document_dict = {
  552. "id": document.id,
  553. "indexing_status": "paused" if document.is_paused else document.indexing_status,
  554. "processing_started_at": document.processing_started_at,
  555. "parsing_completed_at": document.parsing_completed_at,
  556. "cleaning_completed_at": document.cleaning_completed_at,
  557. "splitting_completed_at": document.splitting_completed_at,
  558. "completed_at": document.completed_at,
  559. "paused_at": document.paused_at,
  560. "error": document.error,
  561. "stopped_at": document.stopped_at,
  562. "completed_segments": completed_segments,
  563. "total_segments": total_segments,
  564. }
  565. return marshal(document_dict, document_status_fields)
  566. class DocumentDetailApi(DocumentResource):
  567. METADATA_CHOICES = {"all", "only", "without"}
  568. @setup_required
  569. @login_required
  570. @account_initialization_required
  571. def get(self, dataset_id, document_id):
  572. dataset_id = str(dataset_id)
  573. document_id = str(document_id)
  574. document = self.get_document(dataset_id, document_id)
  575. metadata = request.args.get("metadata", "all")
  576. if metadata not in self.METADATA_CHOICES:
  577. raise InvalidMetadataError(f"Invalid metadata value: {metadata}")
  578. if metadata == "only":
  579. response = {"id": document.id, "doc_type": document.doc_type, "doc_metadata": document.doc_metadata_details}
  580. elif metadata == "without":
  581. dataset_process_rules = DatasetService.get_process_rules(dataset_id)
  582. document_process_rules = document.dataset_process_rule.to_dict() if document.dataset_process_rule else {}
  583. data_source_info = document.data_source_detail_dict
  584. response = {
  585. "id": document.id,
  586. "position": document.position,
  587. "data_source_type": document.data_source_type,
  588. "data_source_info": data_source_info,
  589. "dataset_process_rule_id": document.dataset_process_rule_id,
  590. "dataset_process_rule": dataset_process_rules,
  591. "document_process_rule": document_process_rules,
  592. "name": document.name,
  593. "created_from": document.created_from,
  594. "created_by": document.created_by,
  595. "created_at": document.created_at.timestamp(),
  596. "tokens": document.tokens,
  597. "indexing_status": document.indexing_status,
  598. "completed_at": int(document.completed_at.timestamp()) if document.completed_at else None,
  599. "updated_at": int(document.updated_at.timestamp()) if document.updated_at else None,
  600. "indexing_latency": document.indexing_latency,
  601. "error": document.error,
  602. "enabled": document.enabled,
  603. "disabled_at": int(document.disabled_at.timestamp()) if document.disabled_at else None,
  604. "disabled_by": document.disabled_by,
  605. "archived": document.archived,
  606. "segment_count": document.segment_count,
  607. "average_segment_length": document.average_segment_length,
  608. "hit_count": document.hit_count,
  609. "display_status": document.display_status,
  610. "doc_form": document.doc_form,
  611. "doc_language": document.doc_language,
  612. }
  613. else:
  614. dataset_process_rules = DatasetService.get_process_rules(dataset_id)
  615. document_process_rules = document.dataset_process_rule.to_dict()
  616. data_source_info = document.data_source_detail_dict
  617. response = {
  618. "id": document.id,
  619. "position": document.position,
  620. "data_source_type": document.data_source_type,
  621. "data_source_info": data_source_info,
  622. "dataset_process_rule_id": document.dataset_process_rule_id,
  623. "dataset_process_rule": dataset_process_rules,
  624. "document_process_rule": document_process_rules,
  625. "name": document.name,
  626. "created_from": document.created_from,
  627. "created_by": document.created_by,
  628. "created_at": document.created_at.timestamp(),
  629. "tokens": document.tokens,
  630. "indexing_status": document.indexing_status,
  631. "completed_at": int(document.completed_at.timestamp()) if document.completed_at else None,
  632. "updated_at": int(document.updated_at.timestamp()) if document.updated_at else None,
  633. "indexing_latency": document.indexing_latency,
  634. "error": document.error,
  635. "enabled": document.enabled,
  636. "disabled_at": int(document.disabled_at.timestamp()) if document.disabled_at else None,
  637. "disabled_by": document.disabled_by,
  638. "archived": document.archived,
  639. "doc_type": document.doc_type,
  640. "doc_metadata": document.doc_metadata_details,
  641. "segment_count": document.segment_count,
  642. "average_segment_length": document.average_segment_length,
  643. "hit_count": document.hit_count,
  644. "display_status": document.display_status,
  645. "doc_form": document.doc_form,
  646. "doc_language": document.doc_language,
  647. }
  648. return response, 200
  649. class DocumentProcessingApi(DocumentResource):
  650. @setup_required
  651. @login_required
  652. @account_initialization_required
  653. @cloud_edition_billing_rate_limit_check("knowledge")
  654. def patch(self, dataset_id, document_id, action):
  655. dataset_id = str(dataset_id)
  656. document_id = str(document_id)
  657. document = self.get_document(dataset_id, document_id)
  658. # The role of the current user in the ta table must be admin, owner, dataset_operator, or editor
  659. if not current_user.is_dataset_editor:
  660. raise Forbidden()
  661. if action == "pause":
  662. if document.indexing_status != "indexing":
  663. raise InvalidActionError("Document not in indexing state.")
  664. document.paused_by = current_user.id
  665. document.paused_at = naive_utc_now()
  666. document.is_paused = True
  667. db.session.commit()
  668. elif action == "resume":
  669. if document.indexing_status not in {"paused", "error"}:
  670. raise InvalidActionError("Document not in paused or error state.")
  671. document.paused_by = None
  672. document.paused_at = None
  673. document.is_paused = False
  674. db.session.commit()
  675. else:
  676. raise InvalidActionError()
  677. return {"result": "success"}, 200
  678. class DocumentDeleteApi(DocumentResource):
  679. @setup_required
  680. @login_required
  681. @account_initialization_required
  682. @cloud_edition_billing_rate_limit_check("knowledge")
  683. def delete(self, dataset_id, document_id):
  684. dataset_id = str(dataset_id)
  685. document_id = str(document_id)
  686. dataset = DatasetService.get_dataset(dataset_id)
  687. if dataset is None:
  688. raise NotFound("Dataset not found.")
  689. # check user's model setting
  690. DatasetService.check_dataset_model_setting(dataset)
  691. document = self.get_document(dataset_id, document_id)
  692. try:
  693. DocumentService.delete_document(document)
  694. except services.errors.document.DocumentIndexingError:
  695. raise DocumentIndexingError("Cannot delete document during indexing.")
  696. return {"result": "success"}, 204
  697. class DocumentMetadataApi(DocumentResource):
  698. @setup_required
  699. @login_required
  700. @account_initialization_required
  701. def put(self, dataset_id, document_id):
  702. dataset_id = str(dataset_id)
  703. document_id = str(document_id)
  704. document = self.get_document(dataset_id, document_id)
  705. req_data = request.get_json()
  706. doc_type = req_data.get("doc_type")
  707. doc_metadata = req_data.get("doc_metadata")
  708. # The role of the current user in the ta table must be admin, owner, dataset_operator, or editor
  709. if not current_user.is_dataset_editor:
  710. raise Forbidden()
  711. if doc_type is None or doc_metadata is None:
  712. raise ValueError("Both doc_type and doc_metadata must be provided.")
  713. if doc_type not in DocumentService.DOCUMENT_METADATA_SCHEMA:
  714. raise ValueError("Invalid doc_type.")
  715. if not isinstance(doc_metadata, dict):
  716. raise ValueError("doc_metadata must be a dictionary.")
  717. metadata_schema: dict = cast(dict, DocumentService.DOCUMENT_METADATA_SCHEMA[doc_type])
  718. document.doc_metadata = {}
  719. if doc_type == "others":
  720. document.doc_metadata = doc_metadata
  721. else:
  722. for key, value_type in metadata_schema.items():
  723. value = doc_metadata.get(key)
  724. if value is not None and isinstance(value, value_type):
  725. document.doc_metadata[key] = value
  726. document.doc_type = doc_type
  727. document.updated_at = naive_utc_now()
  728. db.session.commit()
  729. return {"result": "success", "message": "Document metadata updated."}, 200
  730. class DocumentStatusApi(DocumentResource):
  731. @setup_required
  732. @login_required
  733. @account_initialization_required
  734. @cloud_edition_billing_resource_check("vector_space")
  735. @cloud_edition_billing_rate_limit_check("knowledge")
  736. def patch(self, dataset_id, action):
  737. dataset_id = str(dataset_id)
  738. dataset = DatasetService.get_dataset(dataset_id)
  739. if dataset is None:
  740. raise NotFound("Dataset not found.")
  741. # The role of the current user in the ta table must be admin, owner, or editor
  742. if not current_user.is_dataset_editor:
  743. raise Forbidden()
  744. # check user's model setting
  745. DatasetService.check_dataset_model_setting(dataset)
  746. # check user's permission
  747. DatasetService.check_dataset_permission(dataset, current_user)
  748. document_ids = request.args.getlist("document_id")
  749. try:
  750. DocumentService.batch_update_document_status(dataset, document_ids, action, current_user)
  751. except services.errors.document.DocumentIndexingError as e:
  752. raise InvalidActionError(str(e))
  753. except ValueError as e:
  754. raise InvalidActionError(str(e))
  755. except NotFound as e:
  756. raise NotFound(str(e))
  757. return {"result": "success"}, 200
  758. class DocumentPauseApi(DocumentResource):
  759. @setup_required
  760. @login_required
  761. @account_initialization_required
  762. @cloud_edition_billing_rate_limit_check("knowledge")
  763. def patch(self, dataset_id, document_id):
  764. """pause document."""
  765. dataset_id = str(dataset_id)
  766. document_id = str(document_id)
  767. dataset = DatasetService.get_dataset(dataset_id)
  768. if not dataset:
  769. raise NotFound("Dataset not found.")
  770. document = DocumentService.get_document(dataset.id, document_id)
  771. # 404 if document not found
  772. if document is None:
  773. raise NotFound("Document Not Exists.")
  774. # 403 if document is archived
  775. if DocumentService.check_archived(document):
  776. raise ArchivedDocumentImmutableError()
  777. try:
  778. # pause document
  779. DocumentService.pause_document(document)
  780. except services.errors.document.DocumentIndexingError:
  781. raise DocumentIndexingError("Cannot pause completed document.")
  782. return {"result": "success"}, 204
  783. class DocumentRecoverApi(DocumentResource):
  784. @setup_required
  785. @login_required
  786. @account_initialization_required
  787. @cloud_edition_billing_rate_limit_check("knowledge")
  788. def patch(self, dataset_id, document_id):
  789. """recover document."""
  790. dataset_id = str(dataset_id)
  791. document_id = str(document_id)
  792. dataset = DatasetService.get_dataset(dataset_id)
  793. if not dataset:
  794. raise NotFound("Dataset not found.")
  795. document = DocumentService.get_document(dataset.id, document_id)
  796. # 404 if document not found
  797. if document is None:
  798. raise NotFound("Document Not Exists.")
  799. # 403 if document is archived
  800. if DocumentService.check_archived(document):
  801. raise ArchivedDocumentImmutableError()
  802. try:
  803. # pause document
  804. DocumentService.recover_document(document)
  805. except services.errors.document.DocumentIndexingError:
  806. raise DocumentIndexingError("Document is not in paused status.")
  807. return {"result": "success"}, 204
  808. class DocumentRetryApi(DocumentResource):
  809. @setup_required
  810. @login_required
  811. @account_initialization_required
  812. @cloud_edition_billing_rate_limit_check("knowledge")
  813. def post(self, dataset_id):
  814. """retry document."""
  815. parser = reqparse.RequestParser()
  816. parser.add_argument("document_ids", type=list, required=True, nullable=False, location="json")
  817. args = parser.parse_args()
  818. dataset_id = str(dataset_id)
  819. dataset = DatasetService.get_dataset(dataset_id)
  820. retry_documents = []
  821. if not dataset:
  822. raise NotFound("Dataset not found.")
  823. for document_id in args["document_ids"]:
  824. try:
  825. document_id = str(document_id)
  826. document = DocumentService.get_document(dataset.id, document_id)
  827. # 404 if document not found
  828. if document is None:
  829. raise NotFound("Document Not Exists.")
  830. # 403 if document is archived
  831. if DocumentService.check_archived(document):
  832. raise ArchivedDocumentImmutableError()
  833. # 400 if document is completed
  834. if document.indexing_status == "completed":
  835. raise DocumentAlreadyFinishedError()
  836. retry_documents.append(document)
  837. except Exception:
  838. logging.exception("Failed to retry document, document id: %s", document_id)
  839. continue
  840. # retry document
  841. DocumentService.retry_document(dataset_id, retry_documents)
  842. return {"result": "success"}, 204
  843. class DocumentRenameApi(DocumentResource):
  844. @setup_required
  845. @login_required
  846. @account_initialization_required
  847. @marshal_with(document_fields)
  848. def post(self, dataset_id, document_id):
  849. # The role of the current user in the ta table must be admin, owner, editor, or dataset_operator
  850. if not current_user.is_dataset_editor:
  851. raise Forbidden()
  852. dataset = DatasetService.get_dataset(dataset_id)
  853. DatasetService.check_dataset_operator_permission(current_user, dataset)
  854. parser = reqparse.RequestParser()
  855. parser.add_argument("name", type=str, required=True, nullable=False, location="json")
  856. args = parser.parse_args()
  857. try:
  858. document = DocumentService.rename_document(dataset_id, document_id, args["name"])
  859. except services.errors.document.DocumentIndexingError:
  860. raise DocumentIndexingError("Cannot delete document during indexing.")
  861. return document
  862. class WebsiteDocumentSyncApi(DocumentResource):
  863. @setup_required
  864. @login_required
  865. @account_initialization_required
  866. def get(self, dataset_id, document_id):
  867. """sync website document."""
  868. dataset_id = str(dataset_id)
  869. dataset = DatasetService.get_dataset(dataset_id)
  870. if not dataset:
  871. raise NotFound("Dataset not found.")
  872. document_id = str(document_id)
  873. document = DocumentService.get_document(dataset.id, document_id)
  874. if not document:
  875. raise NotFound("Document not found.")
  876. if document.tenant_id != current_user.current_tenant_id:
  877. raise Forbidden("No permission.")
  878. if document.data_source_type != "website_crawl":
  879. raise ValueError("Document is not a website document.")
  880. # 403 if document is archived
  881. if DocumentService.check_archived(document):
  882. raise ArchivedDocumentImmutableError()
  883. # sync document
  884. DocumentService.sync_website_document(dataset_id, document)
  885. return {"result": "success"}, 200
  886. class DocumentPipelineExecutionLogApi(DocumentResource):
  887. @setup_required
  888. @login_required
  889. @account_initialization_required
  890. def get(self, dataset_id, document_id):
  891. dataset_id = str(dataset_id)
  892. document_id = str(document_id)
  893. dataset = DatasetService.get_dataset(dataset_id)
  894. if not dataset:
  895. raise NotFound("Dataset not found.")
  896. document = DocumentService.get_document(dataset.id, document_id)
  897. if not document:
  898. raise NotFound("Document not found.")
  899. log = (
  900. db.session.query(DocumentPipelineExecutionLog)
  901. .filter_by(document_id=document_id)
  902. .order_by(DocumentPipelineExecutionLog.created_at.desc())
  903. .first()
  904. )
  905. if not log:
  906. return {
  907. "datasource_info": None,
  908. "datasource_type": None,
  909. "input_data": None,
  910. "datasource_node_id": None,
  911. }, 200
  912. return {
  913. "datasource_info": json.loads(log.datasource_info),
  914. "datasource_type": log.datasource_type,
  915. "input_data": log.input_data,
  916. "datasource_node_id": log.datasource_node_id,
  917. }, 200
  918. api.add_resource(GetProcessRuleApi, "/datasets/process-rule")
  919. api.add_resource(DatasetDocumentListApi, "/datasets/<uuid:dataset_id>/documents")
  920. api.add_resource(DatasetInitApi, "/datasets/init")
  921. api.add_resource(
  922. DocumentIndexingEstimateApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/indexing-estimate"
  923. )
  924. api.add_resource(DocumentBatchIndexingEstimateApi, "/datasets/<uuid:dataset_id>/batch/<string:batch>/indexing-estimate")
  925. api.add_resource(DocumentBatchIndexingStatusApi, "/datasets/<uuid:dataset_id>/batch/<string:batch>/indexing-status")
  926. api.add_resource(DocumentIndexingStatusApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/indexing-status")
  927. api.add_resource(DocumentDetailApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>")
  928. api.add_resource(
  929. DocumentProcessingApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/processing/<string:action>"
  930. )
  931. api.add_resource(DocumentDeleteApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>")
  932. api.add_resource(DocumentMetadataApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/metadata")
  933. api.add_resource(DocumentStatusApi, "/datasets/<uuid:dataset_id>/documents/status/<string:action>/batch")
  934. api.add_resource(DocumentPauseApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/processing/pause")
  935. api.add_resource(DocumentRecoverApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/processing/resume")
  936. api.add_resource(DocumentRetryApi, "/datasets/<uuid:dataset_id>/retry")
  937. api.add_resource(DocumentRenameApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/rename")
  938. api.add_resource(WebsiteDocumentSyncApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/website-sync")
  939. api.add_resource(
  940. DocumentPipelineExecutionLogApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/pipeline-execution-log"
  941. )