選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

datasets_document.py 43KB

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ヶ月前
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. import logging
  2. from argparse import ArgumentTypeError
  3. from collections.abc import Sequence
  4. from typing import Literal, cast
  5. from flask import request
  6. from flask_login import current_user
  7. from flask_restx 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.datasource_type import DatasourceType
  43. from core.rag.extractor.entity.extract_setting import ExtractSetting
  44. from extensions.ext_database import db
  45. from fields.document_fields import (
  46. dataset_and_document_fields,
  47. document_fields,
  48. document_status_fields,
  49. document_with_segments_fields,
  50. )
  51. from libs.datetime_utils import naive_utc_now
  52. from libs.login import login_required
  53. from models import Dataset, DatasetProcessRule, Document, DocumentSegment, UploadFile
  54. from services.dataset_service import DatasetService, DocumentService
  55. from services.entities.knowledge_entities.knowledge_entities import KnowledgeConfig
  56. logger = logging.getLogger(__name__)
  57. class DocumentResource(Resource):
  58. def get_document(self, dataset_id: str, document_id: str) -> Document:
  59. dataset = DatasetService.get_dataset(dataset_id)
  60. if not dataset:
  61. raise NotFound("Dataset not found.")
  62. try:
  63. DatasetService.check_dataset_permission(dataset, current_user)
  64. except services.errors.account.NoPermissionError as e:
  65. raise Forbidden(str(e))
  66. document = DocumentService.get_document(dataset_id, document_id)
  67. if not document:
  68. raise NotFound("Document not found.")
  69. if document.tenant_id != current_user.current_tenant_id:
  70. raise Forbidden("No permission.")
  71. return document
  72. def get_batch_documents(self, dataset_id: str, batch: str) -> Sequence[Document]:
  73. dataset = DatasetService.get_dataset(dataset_id)
  74. if not dataset:
  75. raise NotFound("Dataset not found.")
  76. try:
  77. DatasetService.check_dataset_permission(dataset, current_user)
  78. except services.errors.account.NoPermissionError as e:
  79. raise Forbidden(str(e))
  80. documents = DocumentService.get_batch_documents(dataset_id, batch)
  81. if not documents:
  82. raise NotFound("Documents not found.")
  83. return documents
  84. class GetProcessRuleApi(Resource):
  85. @setup_required
  86. @login_required
  87. @account_initialization_required
  88. def get(self):
  89. req_data = request.args
  90. document_id = req_data.get("document_id")
  91. # get default rules
  92. mode = DocumentService.DEFAULT_RULES["mode"]
  93. rules = DocumentService.DEFAULT_RULES["rules"]
  94. limits = DocumentService.DEFAULT_RULES["limits"]
  95. if document_id:
  96. # get the latest process rule
  97. document = db.get_or_404(Document, document_id)
  98. dataset = DatasetService.get_dataset(document.dataset_id)
  99. if not dataset:
  100. raise NotFound("Dataset not found.")
  101. try:
  102. DatasetService.check_dataset_permission(dataset, current_user)
  103. except services.errors.account.NoPermissionError as e:
  104. raise Forbidden(str(e))
  105. # get the latest process rule
  106. dataset_process_rule = (
  107. db.session.query(DatasetProcessRule)
  108. .where(DatasetProcessRule.dataset_id == document.dataset_id)
  109. .order_by(DatasetProcessRule.created_at.desc())
  110. .limit(1)
  111. .one_or_none()
  112. )
  113. if dataset_process_rule:
  114. mode = dataset_process_rule.mode
  115. rules = dataset_process_rule.rules_dict
  116. return {"mode": mode, "rules": rules, "limits": limits}
  117. class DatasetDocumentListApi(Resource):
  118. @setup_required
  119. @login_required
  120. @account_initialization_required
  121. def get(self, dataset_id):
  122. dataset_id = str(dataset_id)
  123. page = request.args.get("page", default=1, type=int)
  124. limit = request.args.get("limit", default=20, type=int)
  125. search = request.args.get("keyword", default=None, type=str)
  126. sort = request.args.get("sort", default="-created_at", type=str)
  127. # "yes", "true", "t", "y", "1" convert to True, while others convert to False.
  128. try:
  129. fetch_val = request.args.get("fetch", default="false")
  130. if isinstance(fetch_val, bool):
  131. fetch = fetch_val
  132. else:
  133. if fetch_val.lower() in ("yes", "true", "t", "y", "1"):
  134. fetch = True
  135. elif fetch_val.lower() in ("no", "false", "f", "n", "0"):
  136. fetch = False
  137. else:
  138. raise ArgumentTypeError(
  139. f"Truthy value expected: got {fetch_val} but expected one of yes/no, true/false, t/f, y/n, 1/0 "
  140. f"(case insensitive)."
  141. )
  142. except (ArgumentTypeError, ValueError, Exception):
  143. fetch = False
  144. dataset = DatasetService.get_dataset(dataset_id)
  145. if not dataset:
  146. raise NotFound("Dataset not found.")
  147. try:
  148. DatasetService.check_dataset_permission(dataset, current_user)
  149. except services.errors.account.NoPermissionError as e:
  150. raise Forbidden(str(e))
  151. query = select(Document).filter_by(dataset_id=str(dataset_id), tenant_id=current_user.current_tenant_id)
  152. if search:
  153. search = f"%{search}%"
  154. query = query.where(Document.name.like(search))
  155. if sort.startswith("-"):
  156. sort_logic = desc
  157. sort = sort[1:]
  158. else:
  159. sort_logic = asc
  160. if sort == "hit_count":
  161. sub_query = (
  162. db.select(DocumentSegment.document_id, db.func.sum(DocumentSegment.hit_count).label("total_hit_count"))
  163. .group_by(DocumentSegment.document_id)
  164. .subquery()
  165. )
  166. query = query.outerjoin(sub_query, sub_query.c.document_id == Document.id).order_by(
  167. sort_logic(db.func.coalesce(sub_query.c.total_hit_count, 0)),
  168. sort_logic(Document.position),
  169. )
  170. elif sort == "created_at":
  171. query = query.order_by(
  172. sort_logic(Document.created_at),
  173. sort_logic(Document.position),
  174. )
  175. else:
  176. query = query.order_by(
  177. desc(Document.created_at),
  178. desc(Document.position),
  179. )
  180. paginated_documents = db.paginate(select=query, page=page, per_page=limit, max_per_page=100, error_out=False)
  181. documents = paginated_documents.items
  182. if fetch:
  183. for document in documents:
  184. completed_segments = (
  185. db.session.query(DocumentSegment)
  186. .where(
  187. DocumentSegment.completed_at.isnot(None),
  188. DocumentSegment.document_id == str(document.id),
  189. DocumentSegment.status != "re_segment",
  190. )
  191. .count()
  192. )
  193. total_segments = (
  194. db.session.query(DocumentSegment)
  195. .where(DocumentSegment.document_id == str(document.id), DocumentSegment.status != "re_segment")
  196. .count()
  197. )
  198. document.completed_segments = completed_segments
  199. document.total_segments = total_segments
  200. data = marshal(documents, document_with_segments_fields)
  201. else:
  202. data = marshal(documents, document_fields)
  203. response = {
  204. "data": data,
  205. "has_more": len(documents) == limit,
  206. "limit": limit,
  207. "total": paginated_documents.total,
  208. "page": page,
  209. }
  210. return response
  211. @setup_required
  212. @login_required
  213. @account_initialization_required
  214. @marshal_with(dataset_and_document_fields)
  215. @cloud_edition_billing_resource_check("vector_space")
  216. @cloud_edition_billing_rate_limit_check("knowledge")
  217. def post(self, dataset_id):
  218. dataset_id = str(dataset_id)
  219. dataset = DatasetService.get_dataset(dataset_id)
  220. if not dataset:
  221. raise NotFound("Dataset not found.")
  222. # The role of the current user in the ta table must be admin, owner, or editor
  223. if not current_user.is_dataset_editor:
  224. raise Forbidden()
  225. try:
  226. DatasetService.check_dataset_permission(dataset, current_user)
  227. except services.errors.account.NoPermissionError as e:
  228. raise Forbidden(str(e))
  229. parser = reqparse.RequestParser()
  230. parser.add_argument(
  231. "indexing_technique", type=str, choices=Dataset.INDEXING_TECHNIQUE_LIST, nullable=False, location="json"
  232. )
  233. parser.add_argument("data_source", type=dict, required=False, location="json")
  234. parser.add_argument("process_rule", type=dict, required=False, location="json")
  235. parser.add_argument("duplicate", type=bool, default=True, nullable=False, location="json")
  236. parser.add_argument("original_document_id", type=str, required=False, location="json")
  237. parser.add_argument("doc_form", type=str, default="text_model", required=False, nullable=False, location="json")
  238. parser.add_argument("retrieval_model", type=dict, required=False, nullable=False, location="json")
  239. parser.add_argument("embedding_model", type=str, required=False, nullable=True, location="json")
  240. parser.add_argument("embedding_model_provider", type=str, required=False, nullable=True, location="json")
  241. parser.add_argument(
  242. "doc_language", type=str, default="English", required=False, nullable=False, location="json"
  243. )
  244. args = parser.parse_args()
  245. knowledge_config = KnowledgeConfig(**args)
  246. if not dataset.indexing_technique and not knowledge_config.indexing_technique:
  247. raise ValueError("indexing_technique is required.")
  248. # validate args
  249. DocumentService.document_create_args_validate(knowledge_config)
  250. try:
  251. documents, batch = DocumentService.save_document_with_dataset_id(dataset, knowledge_config, current_user)
  252. dataset = DatasetService.get_dataset(dataset_id)
  253. except ProviderTokenNotInitError as ex:
  254. raise ProviderNotInitializeError(ex.description)
  255. except QuotaExceededError:
  256. raise ProviderQuotaExceededError()
  257. except ModelCurrentlyNotSupportError:
  258. raise ProviderModelCurrentlyNotSupportError()
  259. return {"dataset": dataset, "documents": documents, "batch": batch}
  260. @setup_required
  261. @login_required
  262. @account_initialization_required
  263. @cloud_edition_billing_rate_limit_check("knowledge")
  264. def delete(self, dataset_id):
  265. dataset_id = str(dataset_id)
  266. dataset = DatasetService.get_dataset(dataset_id)
  267. if dataset is None:
  268. raise NotFound("Dataset not found.")
  269. # check user's model setting
  270. DatasetService.check_dataset_model_setting(dataset)
  271. try:
  272. document_ids = request.args.getlist("document_id")
  273. DocumentService.delete_documents(dataset, document_ids)
  274. except services.errors.document.DocumentIndexingError:
  275. raise DocumentIndexingError("Cannot delete document during indexing.")
  276. return {"result": "success"}, 204
  277. class DatasetInitApi(Resource):
  278. @setup_required
  279. @login_required
  280. @account_initialization_required
  281. @marshal_with(dataset_and_document_fields)
  282. @cloud_edition_billing_resource_check("vector_space")
  283. @cloud_edition_billing_rate_limit_check("knowledge")
  284. def post(self):
  285. # The role of the current user in the ta table must be admin, owner, dataset_operator, or editor
  286. if not current_user.is_dataset_editor:
  287. raise Forbidden()
  288. parser = reqparse.RequestParser()
  289. parser.add_argument(
  290. "indexing_technique",
  291. type=str,
  292. choices=Dataset.INDEXING_TECHNIQUE_LIST,
  293. required=True,
  294. nullable=False,
  295. location="json",
  296. )
  297. parser.add_argument("data_source", type=dict, required=True, nullable=True, location="json")
  298. parser.add_argument("process_rule", type=dict, required=True, nullable=True, location="json")
  299. parser.add_argument("doc_form", type=str, default="text_model", required=False, nullable=False, location="json")
  300. parser.add_argument(
  301. "doc_language", type=str, default="English", required=False, nullable=False, location="json"
  302. )
  303. parser.add_argument("retrieval_model", type=dict, required=False, nullable=False, location="json")
  304. parser.add_argument("embedding_model", type=str, required=False, nullable=True, location="json")
  305. parser.add_argument("embedding_model_provider", type=str, required=False, nullable=True, location="json")
  306. args = parser.parse_args()
  307. knowledge_config = KnowledgeConfig(**args)
  308. if knowledge_config.indexing_technique == "high_quality":
  309. if knowledge_config.embedding_model is None or knowledge_config.embedding_model_provider is None:
  310. raise ValueError("embedding model and embedding model provider are required for high quality indexing.")
  311. try:
  312. model_manager = ModelManager()
  313. model_manager.get_model_instance(
  314. tenant_id=current_user.current_tenant_id,
  315. provider=args["embedding_model_provider"],
  316. model_type=ModelType.TEXT_EMBEDDING,
  317. model=args["embedding_model"],
  318. )
  319. except InvokeAuthorizationError:
  320. raise ProviderNotInitializeError(
  321. "No Embedding Model available. Please configure a valid provider in the Settings -> Model Provider."
  322. )
  323. except ProviderTokenNotInitError as ex:
  324. raise ProviderNotInitializeError(ex.description)
  325. # validate args
  326. DocumentService.document_create_args_validate(knowledge_config)
  327. try:
  328. dataset, documents, batch = DocumentService.save_document_without_dataset_id(
  329. tenant_id=current_user.current_tenant_id, knowledge_config=knowledge_config, account=current_user
  330. )
  331. except ProviderTokenNotInitError as ex:
  332. raise ProviderNotInitializeError(ex.description)
  333. except QuotaExceededError:
  334. raise ProviderQuotaExceededError()
  335. except ModelCurrentlyNotSupportError:
  336. raise ProviderModelCurrentlyNotSupportError()
  337. response = {"dataset": dataset, "documents": documents, "batch": batch}
  338. return response
  339. class DocumentIndexingEstimateApi(DocumentResource):
  340. @setup_required
  341. @login_required
  342. @account_initialization_required
  343. def get(self, dataset_id, document_id):
  344. dataset_id = str(dataset_id)
  345. document_id = str(document_id)
  346. document = self.get_document(dataset_id, document_id)
  347. if document.indexing_status in {"completed", "error"}:
  348. raise DocumentAlreadyFinishedError()
  349. data_process_rule = document.dataset_process_rule
  350. data_process_rule_dict = data_process_rule.to_dict()
  351. response = {"tokens": 0, "total_price": 0, "currency": "USD", "total_segments": 0, "preview": []}
  352. if document.data_source_type == "upload_file":
  353. data_source_info = document.data_source_info_dict
  354. if data_source_info and "upload_file_id" in data_source_info:
  355. file_id = data_source_info["upload_file_id"]
  356. file = (
  357. db.session.query(UploadFile)
  358. .where(UploadFile.tenant_id == document.tenant_id, UploadFile.id == file_id)
  359. .first()
  360. )
  361. # raise error if file not found
  362. if not file:
  363. raise NotFound("File not found.")
  364. extract_setting = ExtractSetting(
  365. datasource_type=DatasourceType.FILE.value, upload_file=file, document_model=document.doc_form
  366. )
  367. indexing_runner = IndexingRunner()
  368. try:
  369. estimate_response = indexing_runner.indexing_estimate(
  370. current_user.current_tenant_id,
  371. [extract_setting],
  372. data_process_rule_dict,
  373. document.doc_form,
  374. "English",
  375. dataset_id,
  376. )
  377. return estimate_response.model_dump(), 200
  378. except LLMBadRequestError:
  379. raise ProviderNotInitializeError(
  380. "No Embedding Model available. Please configure a valid provider "
  381. "in the Settings -> Model Provider."
  382. )
  383. except ProviderTokenNotInitError as ex:
  384. raise ProviderNotInitializeError(ex.description)
  385. except PluginDaemonClientSideError as ex:
  386. raise ProviderNotInitializeError(ex.description)
  387. except Exception as e:
  388. raise IndexingEstimateError(str(e))
  389. return response, 200
  390. class DocumentBatchIndexingEstimateApi(DocumentResource):
  391. @setup_required
  392. @login_required
  393. @account_initialization_required
  394. def get(self, dataset_id, batch):
  395. dataset_id = str(dataset_id)
  396. batch = str(batch)
  397. documents = self.get_batch_documents(dataset_id, batch)
  398. if not documents:
  399. return {"tokens": 0, "total_price": 0, "currency": "USD", "total_segments": 0, "preview": []}, 200
  400. data_process_rule = documents[0].dataset_process_rule
  401. data_process_rule_dict = data_process_rule.to_dict()
  402. extract_settings = []
  403. for document in documents:
  404. if document.indexing_status in {"completed", "error"}:
  405. raise DocumentAlreadyFinishedError()
  406. data_source_info = document.data_source_info_dict
  407. if document.data_source_type == "upload_file":
  408. if not data_source_info:
  409. continue
  410. file_id = data_source_info["upload_file_id"]
  411. file_detail = (
  412. db.session.query(UploadFile)
  413. .where(UploadFile.tenant_id == current_user.current_tenant_id, UploadFile.id == file_id)
  414. .first()
  415. )
  416. if file_detail is None:
  417. raise NotFound("File not found.")
  418. extract_setting = ExtractSetting(
  419. datasource_type=DatasourceType.FILE.value, upload_file=file_detail, document_model=document.doc_form
  420. )
  421. extract_settings.append(extract_setting)
  422. elif document.data_source_type == "notion_import":
  423. if not data_source_info:
  424. continue
  425. extract_setting = ExtractSetting(
  426. datasource_type=DatasourceType.NOTION.value,
  427. notion_info={
  428. "notion_workspace_id": data_source_info["notion_workspace_id"],
  429. "notion_obj_id": data_source_info["notion_page_id"],
  430. "notion_page_type": data_source_info["type"],
  431. "tenant_id": current_user.current_tenant_id,
  432. },
  433. document_model=document.doc_form,
  434. )
  435. extract_settings.append(extract_setting)
  436. elif document.data_source_type == "website_crawl":
  437. if not data_source_info:
  438. continue
  439. extract_setting = ExtractSetting(
  440. datasource_type=DatasourceType.WEBSITE.value,
  441. website_info={
  442. "provider": data_source_info["provider"],
  443. "job_id": data_source_info["job_id"],
  444. "url": data_source_info["url"],
  445. "tenant_id": current_user.current_tenant_id,
  446. "mode": data_source_info["mode"],
  447. "only_main_content": data_source_info["only_main_content"],
  448. },
  449. document_model=document.doc_form,
  450. )
  451. extract_settings.append(extract_setting)
  452. else:
  453. raise ValueError("Data source type not support")
  454. indexing_runner = IndexingRunner()
  455. try:
  456. response = indexing_runner.indexing_estimate(
  457. current_user.current_tenant_id,
  458. extract_settings,
  459. data_process_rule_dict,
  460. document.doc_form,
  461. "English",
  462. dataset_id,
  463. )
  464. return response.model_dump(), 200
  465. except LLMBadRequestError:
  466. raise ProviderNotInitializeError(
  467. "No Embedding Model available. Please configure a valid provider in the Settings -> Model Provider."
  468. )
  469. except ProviderTokenNotInitError as ex:
  470. raise ProviderNotInitializeError(ex.description)
  471. except PluginDaemonClientSideError as ex:
  472. raise ProviderNotInitializeError(ex.description)
  473. except Exception as e:
  474. raise IndexingEstimateError(str(e))
  475. class DocumentBatchIndexingStatusApi(DocumentResource):
  476. @setup_required
  477. @login_required
  478. @account_initialization_required
  479. def get(self, dataset_id, batch):
  480. dataset_id = str(dataset_id)
  481. batch = str(batch)
  482. documents = self.get_batch_documents(dataset_id, batch)
  483. documents_status = []
  484. for document in documents:
  485. completed_segments = (
  486. db.session.query(DocumentSegment)
  487. .where(
  488. DocumentSegment.completed_at.isnot(None),
  489. DocumentSegment.document_id == str(document.id),
  490. DocumentSegment.status != "re_segment",
  491. )
  492. .count()
  493. )
  494. total_segments = (
  495. db.session.query(DocumentSegment)
  496. .where(DocumentSegment.document_id == str(document.id), DocumentSegment.status != "re_segment")
  497. .count()
  498. )
  499. # Create a dictionary with document attributes and additional fields
  500. document_dict = {
  501. "id": document.id,
  502. "indexing_status": "paused" if document.is_paused else document.indexing_status,
  503. "processing_started_at": document.processing_started_at,
  504. "parsing_completed_at": document.parsing_completed_at,
  505. "cleaning_completed_at": document.cleaning_completed_at,
  506. "splitting_completed_at": document.splitting_completed_at,
  507. "completed_at": document.completed_at,
  508. "paused_at": document.paused_at,
  509. "error": document.error,
  510. "stopped_at": document.stopped_at,
  511. "completed_segments": completed_segments,
  512. "total_segments": total_segments,
  513. }
  514. documents_status.append(marshal(document_dict, document_status_fields))
  515. data = {"data": documents_status}
  516. return data
  517. class DocumentIndexingStatusApi(DocumentResource):
  518. @setup_required
  519. @login_required
  520. @account_initialization_required
  521. def get(self, dataset_id, document_id):
  522. dataset_id = str(dataset_id)
  523. document_id = str(document_id)
  524. document = self.get_document(dataset_id, document_id)
  525. completed_segments = (
  526. db.session.query(DocumentSegment)
  527. .where(
  528. DocumentSegment.completed_at.isnot(None),
  529. DocumentSegment.document_id == str(document_id),
  530. DocumentSegment.status != "re_segment",
  531. )
  532. .count()
  533. )
  534. total_segments = (
  535. db.session.query(DocumentSegment)
  536. .where(DocumentSegment.document_id == str(document_id), DocumentSegment.status != "re_segment")
  537. .count()
  538. )
  539. # Create a dictionary with document attributes and additional fields
  540. document_dict = {
  541. "id": document.id,
  542. "indexing_status": "paused" if document.is_paused else document.indexing_status,
  543. "processing_started_at": document.processing_started_at,
  544. "parsing_completed_at": document.parsing_completed_at,
  545. "cleaning_completed_at": document.cleaning_completed_at,
  546. "splitting_completed_at": document.splitting_completed_at,
  547. "completed_at": document.completed_at,
  548. "paused_at": document.paused_at,
  549. "error": document.error,
  550. "stopped_at": document.stopped_at,
  551. "completed_segments": completed_segments,
  552. "total_segments": total_segments,
  553. }
  554. return marshal(document_dict, document_status_fields)
  555. class DocumentApi(DocumentResource):
  556. METADATA_CHOICES = {"all", "only", "without"}
  557. @setup_required
  558. @login_required
  559. @account_initialization_required
  560. def get(self, dataset_id, document_id):
  561. dataset_id = str(dataset_id)
  562. document_id = str(document_id)
  563. document = self.get_document(dataset_id, document_id)
  564. metadata = request.args.get("metadata", "all")
  565. if metadata not in self.METADATA_CHOICES:
  566. raise InvalidMetadataError(f"Invalid metadata value: {metadata}")
  567. if metadata == "only":
  568. response = {"id": document.id, "doc_type": document.doc_type, "doc_metadata": document.doc_metadata_details}
  569. elif metadata == "without":
  570. dataset_process_rules = DatasetService.get_process_rules(dataset_id)
  571. document_process_rules = document.dataset_process_rule.to_dict()
  572. data_source_info = document.data_source_detail_dict
  573. response = {
  574. "id": document.id,
  575. "position": document.position,
  576. "data_source_type": document.data_source_type,
  577. "data_source_info": data_source_info,
  578. "dataset_process_rule_id": document.dataset_process_rule_id,
  579. "dataset_process_rule": dataset_process_rules,
  580. "document_process_rule": document_process_rules,
  581. "name": document.name,
  582. "created_from": document.created_from,
  583. "created_by": document.created_by,
  584. "created_at": document.created_at.timestamp(),
  585. "tokens": document.tokens,
  586. "indexing_status": document.indexing_status,
  587. "completed_at": int(document.completed_at.timestamp()) if document.completed_at else None,
  588. "updated_at": int(document.updated_at.timestamp()) if document.updated_at else None,
  589. "indexing_latency": document.indexing_latency,
  590. "error": document.error,
  591. "enabled": document.enabled,
  592. "disabled_at": int(document.disabled_at.timestamp()) if document.disabled_at else None,
  593. "disabled_by": document.disabled_by,
  594. "archived": document.archived,
  595. "segment_count": document.segment_count,
  596. "average_segment_length": document.average_segment_length,
  597. "hit_count": document.hit_count,
  598. "display_status": document.display_status,
  599. "doc_form": document.doc_form,
  600. "doc_language": document.doc_language,
  601. }
  602. else:
  603. dataset_process_rules = DatasetService.get_process_rules(dataset_id)
  604. document_process_rules = document.dataset_process_rule.to_dict()
  605. data_source_info = document.data_source_detail_dict
  606. response = {
  607. "id": document.id,
  608. "position": document.position,
  609. "data_source_type": document.data_source_type,
  610. "data_source_info": data_source_info,
  611. "dataset_process_rule_id": document.dataset_process_rule_id,
  612. "dataset_process_rule": dataset_process_rules,
  613. "document_process_rule": document_process_rules,
  614. "name": document.name,
  615. "created_from": document.created_from,
  616. "created_by": document.created_by,
  617. "created_at": document.created_at.timestamp(),
  618. "tokens": document.tokens,
  619. "indexing_status": document.indexing_status,
  620. "completed_at": int(document.completed_at.timestamp()) if document.completed_at else None,
  621. "updated_at": int(document.updated_at.timestamp()) if document.updated_at else None,
  622. "indexing_latency": document.indexing_latency,
  623. "error": document.error,
  624. "enabled": document.enabled,
  625. "disabled_at": int(document.disabled_at.timestamp()) if document.disabled_at else None,
  626. "disabled_by": document.disabled_by,
  627. "archived": document.archived,
  628. "doc_type": document.doc_type,
  629. "doc_metadata": document.doc_metadata_details,
  630. "segment_count": document.segment_count,
  631. "average_segment_length": document.average_segment_length,
  632. "hit_count": document.hit_count,
  633. "display_status": document.display_status,
  634. "doc_form": document.doc_form,
  635. "doc_language": document.doc_language,
  636. }
  637. return response, 200
  638. @setup_required
  639. @login_required
  640. @account_initialization_required
  641. @cloud_edition_billing_rate_limit_check("knowledge")
  642. def delete(self, dataset_id, document_id):
  643. dataset_id = str(dataset_id)
  644. document_id = str(document_id)
  645. dataset = DatasetService.get_dataset(dataset_id)
  646. if dataset is None:
  647. raise NotFound("Dataset not found.")
  648. # check user's model setting
  649. DatasetService.check_dataset_model_setting(dataset)
  650. document = self.get_document(dataset_id, document_id)
  651. try:
  652. DocumentService.delete_document(document)
  653. except services.errors.document.DocumentIndexingError:
  654. raise DocumentIndexingError("Cannot delete document during indexing.")
  655. return {"result": "success"}, 204
  656. class DocumentProcessingApi(DocumentResource):
  657. @setup_required
  658. @login_required
  659. @account_initialization_required
  660. @cloud_edition_billing_rate_limit_check("knowledge")
  661. def patch(self, dataset_id, document_id, action: Literal["pause", "resume"]):
  662. dataset_id = str(dataset_id)
  663. document_id = str(document_id)
  664. document = self.get_document(dataset_id, document_id)
  665. # The role of the current user in the ta table must be admin, owner, dataset_operator, or editor
  666. if not current_user.is_dataset_editor:
  667. raise Forbidden()
  668. if action == "pause":
  669. if document.indexing_status != "indexing":
  670. raise InvalidActionError("Document not in indexing state.")
  671. document.paused_by = current_user.id
  672. document.paused_at = naive_utc_now()
  673. document.is_paused = True
  674. db.session.commit()
  675. elif action == "resume":
  676. if document.indexing_status not in {"paused", "error"}:
  677. raise InvalidActionError("Document not in paused or error state.")
  678. document.paused_by = None
  679. document.paused_at = None
  680. document.is_paused = False
  681. db.session.commit()
  682. return {"result": "success"}, 200
  683. class DocumentMetadataApi(DocumentResource):
  684. @setup_required
  685. @login_required
  686. @account_initialization_required
  687. def put(self, dataset_id, document_id):
  688. dataset_id = str(dataset_id)
  689. document_id = str(document_id)
  690. document = self.get_document(dataset_id, document_id)
  691. req_data = request.get_json()
  692. doc_type = req_data.get("doc_type")
  693. doc_metadata = req_data.get("doc_metadata")
  694. # The role of the current user in the ta table must be admin, owner, dataset_operator, or editor
  695. if not current_user.is_dataset_editor:
  696. raise Forbidden()
  697. if doc_type is None or doc_metadata is None:
  698. raise ValueError("Both doc_type and doc_metadata must be provided.")
  699. if doc_type not in DocumentService.DOCUMENT_METADATA_SCHEMA:
  700. raise ValueError("Invalid doc_type.")
  701. if not isinstance(doc_metadata, dict):
  702. raise ValueError("doc_metadata must be a dictionary.")
  703. metadata_schema: dict = cast(dict, DocumentService.DOCUMENT_METADATA_SCHEMA[doc_type])
  704. document.doc_metadata = {}
  705. if doc_type == "others":
  706. document.doc_metadata = doc_metadata
  707. else:
  708. for key, value_type in metadata_schema.items():
  709. value = doc_metadata.get(key)
  710. if value is not None and isinstance(value, value_type):
  711. document.doc_metadata[key] = value
  712. document.doc_type = doc_type
  713. document.updated_at = naive_utc_now()
  714. db.session.commit()
  715. return {"result": "success", "message": "Document metadata updated."}, 200
  716. class DocumentStatusApi(DocumentResource):
  717. @setup_required
  718. @login_required
  719. @account_initialization_required
  720. @cloud_edition_billing_resource_check("vector_space")
  721. @cloud_edition_billing_rate_limit_check("knowledge")
  722. def patch(self, dataset_id, action: Literal["enable", "disable", "archive", "un_archive"]):
  723. dataset_id = str(dataset_id)
  724. dataset = DatasetService.get_dataset(dataset_id)
  725. if dataset is None:
  726. raise NotFound("Dataset not found.")
  727. # The role of the current user in the ta table must be admin, owner, or editor
  728. if not current_user.is_dataset_editor:
  729. raise Forbidden()
  730. # check user's model setting
  731. DatasetService.check_dataset_model_setting(dataset)
  732. # check user's permission
  733. DatasetService.check_dataset_permission(dataset, current_user)
  734. document_ids = request.args.getlist("document_id")
  735. try:
  736. DocumentService.batch_update_document_status(dataset, document_ids, action, current_user)
  737. except services.errors.document.DocumentIndexingError as e:
  738. raise InvalidActionError(str(e))
  739. except ValueError as e:
  740. raise InvalidActionError(str(e))
  741. except NotFound as e:
  742. raise NotFound(str(e))
  743. return {"result": "success"}, 200
  744. class DocumentPauseApi(DocumentResource):
  745. @setup_required
  746. @login_required
  747. @account_initialization_required
  748. @cloud_edition_billing_rate_limit_check("knowledge")
  749. def patch(self, dataset_id, document_id):
  750. """pause document."""
  751. dataset_id = str(dataset_id)
  752. document_id = str(document_id)
  753. dataset = DatasetService.get_dataset(dataset_id)
  754. if not dataset:
  755. raise NotFound("Dataset not found.")
  756. document = DocumentService.get_document(dataset.id, document_id)
  757. # 404 if document not found
  758. if document is None:
  759. raise NotFound("Document Not Exists.")
  760. # 403 if document is archived
  761. if DocumentService.check_archived(document):
  762. raise ArchivedDocumentImmutableError()
  763. try:
  764. # pause document
  765. DocumentService.pause_document(document)
  766. except services.errors.document.DocumentIndexingError:
  767. raise DocumentIndexingError("Cannot pause completed document.")
  768. return {"result": "success"}, 204
  769. class DocumentRecoverApi(DocumentResource):
  770. @setup_required
  771. @login_required
  772. @account_initialization_required
  773. @cloud_edition_billing_rate_limit_check("knowledge")
  774. def patch(self, dataset_id, document_id):
  775. """recover document."""
  776. dataset_id = str(dataset_id)
  777. document_id = str(document_id)
  778. dataset = DatasetService.get_dataset(dataset_id)
  779. if not dataset:
  780. raise NotFound("Dataset not found.")
  781. document = DocumentService.get_document(dataset.id, document_id)
  782. # 404 if document not found
  783. if document is None:
  784. raise NotFound("Document Not Exists.")
  785. # 403 if document is archived
  786. if DocumentService.check_archived(document):
  787. raise ArchivedDocumentImmutableError()
  788. try:
  789. # pause document
  790. DocumentService.recover_document(document)
  791. except services.errors.document.DocumentIndexingError:
  792. raise DocumentIndexingError("Document is not in paused status.")
  793. return {"result": "success"}, 204
  794. class DocumentRetryApi(DocumentResource):
  795. @setup_required
  796. @login_required
  797. @account_initialization_required
  798. @cloud_edition_billing_rate_limit_check("knowledge")
  799. def post(self, dataset_id):
  800. """retry document."""
  801. parser = reqparse.RequestParser()
  802. parser.add_argument("document_ids", type=list, required=True, nullable=False, location="json")
  803. args = parser.parse_args()
  804. dataset_id = str(dataset_id)
  805. dataset = DatasetService.get_dataset(dataset_id)
  806. retry_documents = []
  807. if not dataset:
  808. raise NotFound("Dataset not found.")
  809. for document_id in args["document_ids"]:
  810. try:
  811. document_id = str(document_id)
  812. document = DocumentService.get_document(dataset.id, document_id)
  813. # 404 if document not found
  814. if document is None:
  815. raise NotFound("Document Not Exists.")
  816. # 403 if document is archived
  817. if DocumentService.check_archived(document):
  818. raise ArchivedDocumentImmutableError()
  819. # 400 if document is completed
  820. if document.indexing_status == "completed":
  821. raise DocumentAlreadyFinishedError()
  822. retry_documents.append(document)
  823. except Exception:
  824. logger.exception("Failed to retry document, document id: %s", document_id)
  825. continue
  826. # retry document
  827. DocumentService.retry_document(dataset_id, retry_documents)
  828. return {"result": "success"}, 204
  829. class DocumentRenameApi(DocumentResource):
  830. @setup_required
  831. @login_required
  832. @account_initialization_required
  833. @marshal_with(document_fields)
  834. def post(self, dataset_id, document_id):
  835. # The role of the current user in the ta table must be admin, owner, editor, or dataset_operator
  836. if not current_user.is_dataset_editor:
  837. raise Forbidden()
  838. dataset = DatasetService.get_dataset(dataset_id)
  839. DatasetService.check_dataset_operator_permission(current_user, dataset)
  840. parser = reqparse.RequestParser()
  841. parser.add_argument("name", type=str, required=True, nullable=False, location="json")
  842. args = parser.parse_args()
  843. try:
  844. document = DocumentService.rename_document(dataset_id, document_id, args["name"])
  845. except services.errors.document.DocumentIndexingError:
  846. raise DocumentIndexingError("Cannot delete document during indexing.")
  847. return document
  848. class WebsiteDocumentSyncApi(DocumentResource):
  849. @setup_required
  850. @login_required
  851. @account_initialization_required
  852. def get(self, dataset_id, document_id):
  853. """sync website document."""
  854. dataset_id = str(dataset_id)
  855. dataset = DatasetService.get_dataset(dataset_id)
  856. if not dataset:
  857. raise NotFound("Dataset not found.")
  858. document_id = str(document_id)
  859. document = DocumentService.get_document(dataset.id, document_id)
  860. if not document:
  861. raise NotFound("Document not found.")
  862. if document.tenant_id != current_user.current_tenant_id:
  863. raise Forbidden("No permission.")
  864. if document.data_source_type != "website_crawl":
  865. raise ValueError("Document is not a website document.")
  866. # 403 if document is archived
  867. if DocumentService.check_archived(document):
  868. raise ArchivedDocumentImmutableError()
  869. # sync document
  870. DocumentService.sync_website_document(dataset_id, document)
  871. return {"result": "success"}, 200
  872. api.add_resource(GetProcessRuleApi, "/datasets/process-rule")
  873. api.add_resource(DatasetDocumentListApi, "/datasets/<uuid:dataset_id>/documents")
  874. api.add_resource(DatasetInitApi, "/datasets/init")
  875. api.add_resource(
  876. DocumentIndexingEstimateApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/indexing-estimate"
  877. )
  878. api.add_resource(DocumentBatchIndexingEstimateApi, "/datasets/<uuid:dataset_id>/batch/<string:batch>/indexing-estimate")
  879. api.add_resource(DocumentBatchIndexingStatusApi, "/datasets/<uuid:dataset_id>/batch/<string:batch>/indexing-status")
  880. api.add_resource(DocumentIndexingStatusApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/indexing-status")
  881. api.add_resource(DocumentApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>")
  882. api.add_resource(
  883. DocumentProcessingApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/processing/<string:action>"
  884. )
  885. api.add_resource(DocumentMetadataApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/metadata")
  886. api.add_resource(DocumentStatusApi, "/datasets/<uuid:dataset_id>/documents/status/<string:action>/batch")
  887. api.add_resource(DocumentPauseApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/processing/pause")
  888. api.add_resource(DocumentRecoverApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/processing/resume")
  889. api.add_resource(DocumentRetryApi, "/datasets/<uuid:dataset_id>/retry")
  890. api.add_resource(DocumentRenameApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/rename")
  891. api.add_resource(WebsiteDocumentSyncApi, "/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/website-sync")