Selaa lähdekoodia

fix:add fastgpt usage

jimmyyem 6 kuukautta sitten
vanhempi
commit
d1833c0c81
8 muutettua tiedostoa jossa 1102 lisäystä ja 31 poistoa
  1. 11 9
      go.mod
  2. 52 22
      go.sum
  3. 333 0
      hook/fastgpt/collection.go
  4. 198 0
      hook/fastgpt/data.go
  5. 185 0
      hook/fastgpt/dataset.go
  6. 55 0
      hook/fastgpt/resty.go
  7. 61 0
      hook/fastgpt/search.go
  8. 207 0
      hook/fastgpt/usage.go

+ 11 - 9
go.mod

@@ -5,8 +5,10 @@ go 1.22.1
 require (
 	entgo.io/ent v0.13.1
 	github.com/casbin/casbin/v2 v2.85.0
+	github.com/go-resty/resty/v2 v2.14.0
 	github.com/imroc/req/v3 v3.43.1
 	github.com/redis/go-redis/v9 v9.5.1
+	github.com/robfig/cron/v3 v3.0.1
 	github.com/spf13/cast v1.6.0
 	github.com/suyuan32/simple-admin-common v1.3.11
 	github.com/suyuan32/simple-admin-core v1.3.11
@@ -91,7 +93,6 @@ require (
 	github.com/quic-go/qpack v0.4.0 // indirect
 	github.com/quic-go/quic-go v0.42.0 // indirect
 	github.com/refraction-networking/utls v1.6.3 // indirect
-	github.com/robfig/cron/v3 v3.0.1 // indirect
 	github.com/spaolacci/murmur3 v1.1.0 // indirect
 	github.com/zclconf/go-cty v1.14.3 // indirect
 	go.etcd.io/etcd/api/v3 v3.5.12 // indirect
@@ -112,16 +113,17 @@ require (
 	go.uber.org/mock v0.4.0 // indirect
 	go.uber.org/multierr v1.11.0 // indirect
 	go.uber.org/zap v1.24.0 // indirect
-	golang.org/x/crypto v0.21.0 // indirect
+	golang.org/x/crypto v0.26.0 // indirect
 	golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
-	golang.org/x/mod v0.16.0 // indirect
-	golang.org/x/net v0.22.0 // indirect
+	golang.org/x/mod v0.17.0 // indirect
+	golang.org/x/net v0.28.0 // indirect
 	golang.org/x/oauth2 v0.18.0 // indirect
-	golang.org/x/sys v0.18.0 // indirect
-	golang.org/x/term v0.18.0 // indirect
-	golang.org/x/text v0.14.0 // indirect
-	golang.org/x/time v0.5.0 // indirect
-	golang.org/x/tools v0.19.0 // indirect
+	golang.org/x/sync v0.8.0 // indirect
+	golang.org/x/sys v0.23.0 // indirect
+	golang.org/x/term v0.23.0 // indirect
+	golang.org/x/text v0.17.0 // indirect
+	golang.org/x/time v0.6.0 // indirect
+	golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
 	google.golang.org/appengine v1.6.8 // indirect
 	google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
 	google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect

+ 52 - 22
go.sum

@@ -145,6 +145,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
 github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
 github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
 github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
+github.com/go-resty/resty/v2 v2.14.0 h1:/rhkzsAqGQkozwfKS5aFAbb6TyKd3zyFRWcdRXLPCAU=
+github.com/go-resty/resty/v2 v2.14.0/go.mod h1:IW6mekUOsElt9C7oWr0XRt9BNSD6D5rr9mhk6NjmNHg=
 github.com/go-sql-driver/mysql v1.5.1-0.20200311113236-681ffa848bae/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 github.com/go-sql-driver/mysql v1.8.0 h1:UtktXaU2Nb64z/pLiGIxY4431SJ4/dR5cjMmlVHgnT4=
 github.com/go-sql-driver/mysql v1.8.0/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
@@ -254,8 +256,6 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J
 github.com/imroc/req/v3 v3.43.1 h1:tsWAhvxik4egtHAvMlxcjaWJtHlJL8EpBqJMOm5rmyQ=
 github.com/imroc/req/v3 v3.43.1/go.mod h1:SQIz5iYop16MJxbo8ib+4LnostGCok8NQf8ToyQc2xA=
 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
-github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
-github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
 github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
 github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
 github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
@@ -364,7 +364,6 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
 github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
 github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
-github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
 github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
 github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
@@ -395,7 +394,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
 github.com/nicksnyder/go-i18n/v2 v2.4.0 h1:3IcvPOAvnCKwNm0TB0dLDTuawWEj+ax/RERNC+diLMM=
 github.com/nicksnyder/go-i18n/v2 v2.4.0/go.mod h1:nxYSZE9M0bf3Y70gPQjN9ha7XNHX7gMc814+6wVyEI4=
 github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
-github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
 github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
 github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8=
 github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
@@ -476,8 +474,6 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU
 github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
 github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
 github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
-github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
-github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
 github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
 github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
@@ -585,8 +581,12 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y
 golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
-golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
-golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
+golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
+golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
+golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
+golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
+golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
+golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -612,8 +612,11 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
-golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
-golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
+golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
+golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
+golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
+golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
+golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -636,8 +639,13 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
 golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
 golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
-golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
-golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
+golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
+golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
+golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
+golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
+golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
+golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
+golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -652,8 +660,12 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
 golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
+golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
 golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
+golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
 golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -686,14 +698,25 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
-golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
+golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
-golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
-golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
+golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
+golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
+golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
+golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
+golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
+golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
+golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
@@ -703,12 +726,17 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
 golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
-golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
+golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
+golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
 golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
+golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
+golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
+golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
+golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
 golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
-golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
-golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
+golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
+golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
 golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -739,8 +767,10 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
 golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
 golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
 golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
-golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
-golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
+golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
+golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
+golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
+golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
 golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

+ 333 - 0
hook/fastgpt/collection.go

@@ -0,0 +1,333 @@
+package fastgpt
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"time"
+)
+
+type CollectionResp struct {
+	Code       int    `json:"code"`
+	StatusText string `json:"statusText"`
+	Message    string `json:"message"`
+	Data       string `json:"data"`
+}
+
+type CreateCollectionReq struct {
+	DatasetId string      `json:"datasetId"`
+	ParentId  string      `json:"parentId,optional"`
+	Name      string      `json:"name"`
+	Type      string      `json:"type"`
+	Metadata  interface{} `json:"metadata,optional"`
+}
+
+type CreateTextCollectionReq struct {
+	DatasetId     string      `json:"datasetId"`
+	ParentId      string      `json:"parentId,optional"`
+	Name          string      `json:"name"`
+	Text          string      `json:"text"`
+	Metadata      interface{} `json:"metadata,optional"`
+	TrainingType  string      `json:"trainingType,optional"`
+	ChunkSize     int         `json:"chunkSize,optional"`
+	ChunkSplitter string      `json:"chunkSplitter,optional"`
+	QaPrompt      string      `json:"qaPrompt,optional"`
+}
+
+type CreateTextCollectionResp struct {
+	Code       int    `json:"code"`
+	StatusText string `json:"statusText"`
+	Message    string `json:"message"`
+	Data       struct {
+		CollectionID string `json:"collectionId"`
+		Results      struct {
+			InsertLen int   `json:"insertLen"`
+			OverToken []any `json:"overToken"`
+			Repeat    []any `json:"repeat"`
+			Error     []any `json:"error"`
+		} `json:"results"`
+	} `json:"data"`
+}
+
+type CreateLinkCollectionReq struct {
+	DatasetId string `json:"datasetId"`
+	ParentId  string `json:"parentId,optional"`
+	Name      string `json:"name"`
+	Link      string `json:"link"`
+
+	Metadata      interface{} `json:"metadata,optional"`
+	TrainingType  string      `json:"trainingType,optional"`
+	ChunkSize     int         `json:"chunkSize,optional"`
+	ChunkSplitter string      `json:"chunkSplitter,optional"`
+	QaPrompt      string      `json:"qaPrompt,optional"`
+}
+
+type CreateLinkCollectionResp struct {
+	Code       int    `json:"code"`
+	StatusText string `json:"statusText"`
+	Message    string `json:"message"`
+	Data       struct {
+		CollectionID string `json:"collectionId"`
+	} `json:"data"`
+}
+
+type CreateFileCollectionReq struct {
+	DatasetId string `json:"datasetId"`
+	ParentId  string `json:"parentId,optional"`
+
+	Metadata      interface{} `json:"metadata,optional"`
+	TrainingType  string      `json:"trainingType,optional"`
+	ChunkSize     int         `json:"chunkSize,optional"`
+	ChunkSplitter string      `json:"chunkSplitter,optional"`
+	QaPrompt      string      `json:"qaPrompt,optional"`
+}
+
+type CreateFileCollectionResp struct {
+	Code       int    `json:"code"`
+	StatusText string `json:"statusText,optional"`
+	Message    string `json:"message,optional"`
+	Data       struct {
+		CollectionID string `json:"collectionId,optional"`
+		Results      struct {
+			InsertLen int   `json:"insertLen"`
+			OverToken []any `json:"overToken"`
+			Repeat    []any `json:"repeat"`
+			Error     []any `json:"error"`
+		} `json:"results,optional"`
+	} `json:"data,optional"`
+}
+
+type GetCollectionListReq struct {
+	PageNum    int    `json:"pageNum,optional"`
+	PageSize   int    `json:"pageSize,optional"`
+	DatasetId  string `json:"datasetId,optional"`
+	ParentId   string `json:"parentId,optional"`
+	SearchText string `json:"searchText,optional"`
+}
+
+type CollectionInfo struct {
+	ID        string      `json:"_id"`
+	ParentID  interface{} `json:"parentId"`
+	TeamID    string      `json:"teamId"`
+	TmbID     string      `json:"tmbId"`
+	DatasetID struct {
+		ID          string      `json:"_id"`
+		ParentID    interface{} `json:"parentId"`
+		TeamID      string      `json:"teamId"`
+		TmbID       string      `json:"tmbId"`
+		Type        string      `json:"type"`
+		Status      string      `json:"status"`
+		Avatar      string      `json:"avatar"`
+		Name        string      `json:"name"`
+		VectorModel string      `json:"vectorModel"`
+		AgentModel  string      `json:"agentModel"`
+		Intro       string      `json:"intro"`
+		Permission  string      `json:"permission"`
+		UpdateTime  time.Time   `json:"updateTime"`
+	} `json:"datasetId"`
+	Type          string    `json:"type"`
+	Name          string    `json:"name"`
+	TrainingType  string    `json:"trainingType"`
+	ChunkSize     int       `json:"chunkSize"`
+	ChunkSplitter string    `json:"chunkSplitter"`
+	QaPrompt      string    `json:"qaPrompt"`
+	RawTextLength int       `json:"rawTextLength"`
+	HashRawText   string    `json:"hashRawText"`
+	CreateTime    time.Time `json:"createTime"`
+	UpdateTime    time.Time `json:"updateTime"`
+	CanWrite      bool      `json:"canWrite"`
+	SourceName    string    `json:"sourceName"`
+}
+
+type CollectionListResp struct {
+	Code       int    `json:"code"`
+	StatusText string `json:"statusText"`
+	Message    string `json:"message"`
+	Data       struct {
+		PageNum  int `json:"pageNum"`
+		PageSize int `json:"pageSize"`
+		Data     []struct {
+			ID             string    `json:"_id"`
+			ParentID       string    `json:"parentId"`
+			TmbID          string    `json:"tmbId"`
+			Type           string    `json:"type"`
+			Name           string    `json:"name"`
+			UpdateTime     time.Time `json:"updateTime"`
+			DataAmount     int       `json:"dataAmount"`
+			TrainingAmount int       `json:"trainingAmount"`
+			CanWrite       bool      `json:"canWrite"`
+			RawLink        string    `json:"rawLink,omitempty"`
+		} `json:"data"`
+		Total int `json:"total"`
+	} `json:"data"`
+}
+
+type CollectionDetailResp struct {
+	Code       int            `json:"code"`
+	StatusText string         `json:"statusText"`
+	Message    string         `json:"message"`
+	Data       CollectionInfo `json:"data"`
+}
+
+type UpdateCollectionReq struct {
+	ID       string `json:"id"`
+	ParentId string `json:"parentId"`
+	Name     string `json:"name"`
+}
+
+// GetCollectionDetail 获取合集详情
+func GetCollectionDetail(id string) (collection *CollectionDetailResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&collection).
+		SetQueryParam("id", id).
+		Get("core/dataset/collection/detail")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// GetCollectionList 获取合集列表
+func GetCollectionList(params *GetCollectionListReq) (collectionList *CollectionListResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&collectionList).
+		SetBody(params).
+		Post("core/dataset/collection/list")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// CreateEmptyCollection 创建空合集
+func CreateEmptyCollection(data *CreateCollectionReq) (collection *CollectionResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&collection).
+		SetBody(data).
+		Post("core/dataset/collection/create")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// CreateTextCollection 创建文本合集
+func CreateTextCollection(data *CreateTextCollectionReq) (collection *CreateTextCollectionResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&collection).
+		SetBody(*data).
+		Post("core/dataset/collection/create/text")
+
+	if err != nil {
+		fmt.Printf(err.Error())
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// CreateLinkCollection 创建链接合集
+func CreateLinkCollection(data *CreateLinkCollectionReq) (collection *CreateLinkCollectionResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&collection).
+		SetBody(*data).
+		Post("core/dataset/collection/create/link")
+
+	if err != nil {
+		fmt.Printf(err.Error())
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// CreateFileCollection 创建文件合集
+func CreateFileCollection(data *map[string]string, filePath string) (collection *CreateFileCollectionResp, err error) {
+	dataString, _ := json.Marshal(*data)
+	resp, err := NewResty().
+		R().
+		SetResult(&collection).
+		SetFormData(map[string]string{"data": string(dataString)}).
+		SetFile("file", filePath).
+		Post("core/dataset/collection/create/localFile")
+
+	fmt.Printf("%v, %v", err, resp.String())
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// UpdateCollection 修改合集
+func UpdateCollection(data *UpdateCollectionReq) (collection *CollectionResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&collection).
+		SetBody(*data).
+		Put("core/dataset/collection/update")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// DeleteCollection 删除合集
+func DeleteCollection(id string) (collection *CollectionResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&collection).
+		SetQueryParam("id", id).
+		Delete("core/dataset/collection/delete")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}

+ 198 - 0
hook/fastgpt/data.go

@@ -0,0 +1,198 @@
+package fastgpt
+
+import (
+	"errors"
+)
+
+type DataResp struct {
+	Code       int    `json:"code"`
+	StatusText string `json:"statusText"`
+	Message    string `json:"message"`
+	Data       string `json:"data,optional"`
+}
+
+type CreateBulkDataReq struct {
+	CollectionID string         `json:"collectionId"`
+	TrainingMode string         `json:"trainingMode"`
+	Prompt       string         `json:"prompt,optional"`
+	BillID       string         `json:"billId,optional"`
+	Data         []DataQuestion `json:"data"`
+}
+
+type DataQuestion struct {
+	Q       string  `json:"q"`
+	A       string  `json:"a,optional"`
+	Indexes []Index `json:"indexes,omitempty,optional"`
+}
+
+type Index struct {
+	DataId       string `json:"dataId,optional"`
+	DefaultIndex bool   `json:"defaultIndex,optional"`
+	Text         string `json:"text"`
+}
+
+type CreateBulkDataResp struct {
+	Code       int    `json:"code"`
+	StatusText string `json:"statusText"`
+	Data       struct {
+		InsertLen int   `json:"insertLen"`
+		OverToken []any `json:"overToken"`
+		Repeat    []any `json:"repeat"`
+		Error     []any `json:"error"`
+	} `json:"data"`
+}
+
+type GetDataListReq struct {
+	PageNum      int    `json:"pageNum,optional"`
+	PageSize     int    `json:"pageSize,optional"`
+	CollectionId string `json:"collectionId,optional"`
+	SearchText   string `json:"searchText,optional"`
+}
+
+type DataInfo struct {
+	ID         string `json:"id"`
+	TeamID     string `json:"teamId"`
+	Q          string `json:"q"`
+	A          string `json:"a"`
+	ChunkIndex int    `json:"chunkIndex"`
+	Indexes    []struct {
+		DefaultIndex bool   `json:"defaultIndex"`
+		DataID       string `json:"dataId"`
+		Text         string `json:"text"`
+		ID           string `json:"_id"`
+	} `json:"indexes"`
+	DatasetID    string `json:"datasetId"`
+	CollectionID string `json:"collectionId"`
+	SourceName   string `json:"sourceName"`
+	SourceID     string `json:"sourceId"`
+	IsOwner      bool   `json:"isOwner"`
+	CanWrite     bool   `json:"canWrite"`
+}
+
+type DataListResp struct {
+	Code       int    `json:"code"`
+	StatusText string `json:"statusText"`
+	Message    string `json:"message"`
+	Data       struct {
+		PageNum  int `json:"pageNum"`
+		PageSize int `json:"pageSize"`
+		Data     []struct {
+			ID           string `json:"_id"`
+			DatasetID    string `json:"datasetId"`
+			CollectionID string `json:"collectionId"`
+			Q            string `json:"q"`
+			A            string `json:"a"`
+			ChunkIndex   int    `json:"chunkIndex"`
+		} `json:"data,optional"`
+		Total int `json:"total"`
+	} `json:"data,optional"`
+}
+
+type DataDetail struct {
+	Code       int      `json:"code"`
+	StatusText string   `json:"statusText"`
+	Message    string   `json:"message"`
+	Data       DataInfo `json:"data,optional"`
+}
+
+type UpdateDataReq struct {
+	ID      string  `json:"id"`
+	Q       string  `json:"q"`
+	A       string  `json:"a"`
+	Indexes []Index `json:"indexes,omitempty,optional"`
+}
+
+// GetDataDetail 获取数据详情
+func GetDataDetail(id string) (data *DataDetail, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&data).
+		SetQueryParam("id", id).
+		Get("core/dataset/data/detail")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// GetDataList 获取数据列表
+func GetDataList(params *GetDataListReq) (dataList *DataListResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&dataList).
+		SetBody(params).
+		Post("core/dataset/data/list")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// CreateBulkData 批量创建数据
+func CreateBulkData(data *CreateBulkDataReq) (response *CreateBulkDataResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&response).
+		SetBody(*data).
+		Post("core/dataset/data/pushData")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// UpdateData 修改数据
+func UpdateData(data *UpdateDataReq) (response *DataResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&response).
+		SetBody(*data).
+		Put("core/dataset/data/update")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// DeleteData 删除数据
+func DeleteData(id string) (response *DataResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&response).
+		SetQueryParam("id", id).
+		Delete("core/dataset/data/delete")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}

+ 185 - 0
hook/fastgpt/dataset.go

@@ -0,0 +1,185 @@
+package fastgpt
+
+import (
+	"errors"
+	"time"
+)
+
+type DatasetResp struct {
+	Code       int    `json:"code"`
+	StatusText string `json:"statusText"`
+	Message    string `json:"message"`
+	Data       string `json:"data"`
+}
+
+type DatasetReq struct {
+	ParentID    string `json:"parentId,optional"`
+	Type        string `json:"type,optional"`
+	Avatar      string `json:"avatar,optional"`
+	Name        string `json:"name"`
+	Intro       string `json:"intro,optional"`
+	VectorModel string `json:"vectorModel"`
+	AgentModel  string `json:"agentModel"`
+}
+
+type DatasetInfo struct {
+	ID          string `json:"_id"`
+	ParentID    string `json:"parentId,optional"`
+	TeamID      string `json:"teamId,optional"`
+	TmbID       string `json:"tmbId,optional"`
+	Type        string `json:"type,optional"`
+	Status      string `json:"status,optional"`
+	Avatar      string `json:"avatar,optional"`
+	Name        string `json:"name,optional"`
+	VectorModel struct {
+		Model            string `json:"model"`
+		Name             string `json:"name"`
+		Avatar           string `json:"avatar"`
+		CharsPointsPrice int    `json:"charsPointsPrice"`
+		DefaultToken     int    `json:"defaultToken"`
+		MaxToken         int    `json:"maxToken"`
+		Weight           int    `json:"weight"`
+		DefaultConfig    struct {
+		} `json:"defaultConfig"`
+		DbConfig struct {
+		} `json:"dbConfig"`
+		QueryConfig struct {
+		} `json:"queryConfig"`
+	} `json:"vectorModel,optional"`
+	AgentModel struct {
+		Model                   string  `json:"model"`
+		Name                    string  `json:"name"`
+		Avatar                  string  `json:"avatar"`
+		MaxContext              int     `json:"maxContext"`
+		MaxResponse             int     `json:"maxResponse"`
+		QuoteMaxToken           int     `json:"quoteMaxToken"`
+		MaxTemperature          float64 `json:"maxTemperature"`
+		CharsPointsPrice        int     `json:"charsPointsPrice"`
+		Censor                  bool    `json:"censor"`
+		Vision                  bool    `json:"vision"`
+		DatasetProcess          bool    `json:"datasetProcess"`
+		UsedInClassify          bool    `json:"usedInClassify"`
+		UsedInExtractFields     bool    `json:"usedInExtractFields"`
+		UsedInToolCall          bool    `json:"usedInToolCall"`
+		UsedInQueryExtension    bool    `json:"usedInQueryExtension"`
+		ToolChoice              bool    `json:"toolChoice"`
+		FunctionCall            bool    `json:"functionCall"`
+		CustomCQPrompt          string  `json:"customCQPrompt"`
+		CustomExtractPrompt     string  `json:"customExtractPrompt"`
+		DefaultSystemChatPrompt string  `json:"defaultSystemChatPrompt"`
+		DefaultConfig           struct {
+		} `json:"defaultConfig"`
+	} `json:"agentModel,optional"`
+	Intro      string `json:"intro,optional"`
+	Permission struct {
+		Value        int64 `json:"value"`
+		IsOwner      bool  `json:"isOwner"`
+		HasManagePer bool  `json:"hasManagePer"`
+		HasWritePer  bool  `json:"hasWritePer"`
+		HasReadPer   bool  `json:"hasReadPer"`
+	} `json:"permission,optional"`
+	DefaultPermission int       `json:"defaultPermission.optional"`
+	UpdateTime        time.Time `json:"updateTime,optional"`
+	V                 int       `json:"__v,optional"`
+}
+
+type DatasetList struct {
+	Code       int           `json:"code"`
+	StatusText string        `json:"statusText"`
+	Message    string        `json:"message"`
+	Data       []DatasetInfo `json:"data"`
+}
+
+type DatasetDetail struct {
+	Code       int         `json:"code"`
+	StatusText string      `json:"statusText"`
+	Message    string      `json:"message"`
+	Data       DatasetInfo `json:"data"`
+}
+
+// GetDatasetDetail 获取数据集详情
+func GetDatasetDetail(id string) (dataset *DatasetDetail, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&dataset).
+		SetQueryParam("id", id).
+		Get("core/dataset/detail")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+	return
+}
+
+// GetDatasetList 获取数据集列表
+func GetDatasetList(parentId string) (datasetList *DatasetList, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&datasetList).
+		SetBody(map[string]string{"parentId": parentId}).
+		Post("core/dataset/list")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// CreateDataset 创建数据集
+func CreateDataset(data *DatasetReq) (dataset *DatasetResp, err error) {
+	data.Type = "dataset"
+	if data.Avatar == "" {
+		data.Avatar = "/icon/logo.svg"
+	}
+
+	resp, err := NewResty().
+		R().
+		SetResult(&dataset).
+		SetBody(*data).
+		Post("core/dataset/create")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}
+
+// CreateDatasetFolder 创建数据集目录
+func CreateDatasetFolder(data *DatasetReq) (*DatasetResp, error) {
+	data.Type = "folder"
+	data.Avatar = "/imgs/files/folder.svg"
+	return CreateDataset(data)
+}
+
+// DeleteDataset 删除数据集
+func DeleteDataset(id string) (dataset *DatasetResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&dataset).
+		SetQueryParam("id", id).
+		Delete("core/dataset/delete")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}

+ 55 - 0
hook/fastgpt/resty.go

@@ -0,0 +1,55 @@
+package fastgpt
+
+import (
+	"github.com/go-resty/resty/v2"
+	"log"
+	"os"
+)
+
+// NewResty new resty client
+func NewResty() *resty.Client {
+	client := resty.New()
+	logger := newLogger()
+	client.SetRetryCount(2).
+		SetHeader("Content-Type", "application/json").
+		SetLogger(logger).
+		SetBaseURL("https://fastgpt.gkscrm.com/api").
+		SetHeader("Authorization", "Bearer "+getToken())
+
+	return client
+}
+
+// getToken 获取配置的可用的Token
+func getToken() string {
+	return "fastgpt-czbAiqKKse65hwwviZhwkgvyDEKE3aeB31Fx18oUsAGojyWQ672HdsWZi1E1C"
+}
+
+type logger struct {
+	l *log.Logger
+}
+
+func (l *logger) Errorf(format string, v ...interface{}) {
+	l.output("ERROR RESTY "+format, v...)
+}
+
+func (l *logger) Warnf(format string, v ...interface{}) {
+	l.output("WARN RESTY "+format, v...)
+}
+
+func (l *logger) Debugf(format string, v ...interface{}) {
+	l.output("DEBUG RESTY "+format, v...)
+}
+
+func (l *logger) output(format string, v ...interface{}) {
+	if len(v) == 0 {
+		l.l.Print(format)
+		return
+	}
+	l.l.Printf(format, v...)
+}
+
+// newLogger return a new logger
+func newLogger() *logger {
+	l := &logger{l: log.New(os.Stdout, "", log.Ldate|log.Lmicroseconds)}
+	return l
+}

+ 61 - 0
hook/fastgpt/search.go

@@ -0,0 +1,61 @@
+package fastgpt
+
+import (
+	"errors"
+)
+
+type SearchReq struct {
+	DatasetID   string `json:"datasetId"`           //知识库ID
+	Text        string `json:"text"`                //需要测试的文本
+	Limit       int    `json:"limit"`               //最大 tokens 数量
+	Similarity  int    `json:"similarity,optional"` //最低相关度(0~1,可选)
+	SearchMode  string `json:"searchMode"`          //搜索模式:embedding | fullTextRecall | mixedRecall
+	UsingReRank bool   `json:"usingReRank"`         //使用重排
+}
+
+type SearchResp struct {
+	Code       int    `json:"code"`
+	StatusText string `json:"statusText"`
+	Message    string `json:"message"`
+	Data       struct {
+		List []struct {
+			ID           string `json:"id"`
+			DatasetID    string `json:"datasetId"`
+			CollectionID string `json:"collectionId"`
+			SourceName   string `json:"sourceName"`
+			Q            string `json:"q"`
+			A            string `json:"a"`
+			ChunkIndex   int    `json:"chunkIndex"`
+			Score        []struct {
+				Type  string  `json:"type"`
+				Value float64 `json:"value"`
+				Index int     `json:"index"`
+			} `json:"score"`
+		} `json:"list,optional"`
+		Duration              string `json:"duration"`
+		SearchMode            string `json:"searchMode"`
+		Limit                 int    `json:"limit"`
+		Similarity            int    `json:"similarity"`
+		UsingReRank           bool   `json:"usingReRank"`
+		UsingSimilarityFilter bool   `json:"usingSimilarityFilter"`
+	} `json:"data,optional"`
+}
+
+// SearchText 搜索数据
+func SearchText(params *SearchReq) (dataList *SearchResp, err error) {
+	resp, err := NewResty().
+		R().
+		SetResult(&dataList).
+		SetBody(params).
+		Post("core/dataset/searchTest")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return
+}

+ 207 - 0
hook/fastgpt/usage.go

@@ -0,0 +1,207 @@
+package fastgpt
+
+/**
+以下为知识库相关
+*/
+
+//var info DatasetReq
+//info.ParentID = "66cc44d725aea7116ded5281"
+//info.Name = "dataset-测试数据(huaguo)"
+//info.Intro = "测试数据(huaguo)"
+//info.AgentModel = "gpt-3.5-turbo"
+//info.VectorModel = "text-embedding-ada-002"
+//
+//var dataset *DatasetResp
+//dataset, err := CreateDataset(&info)
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//	return
+//}
+//fmt.Printf("%v", dataset)
+//fmt.Println(dataset.Code, dataset.StatusText, dataset.Message, dataset.Data)
+
+//resp, err := DeleteDataset("66cc43e125aea7116ded514f")
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("code=%v, data=%v, message=%v, statusText=%v", resp.Code, resp.Data, resp.Message, resp.StatusText)
+
+//resp, err := GetDatasetDetail("66cc44d725aea7116ded5281")
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("code=%v, data=%v, message=%v, statusText=%v", resp.Code, resp.Data, resp.Message, resp.StatusText)
+
+//resp, err := GetDatasetList("66cc44d725aea7116ded5281")
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("%v", resp)
+
+//resp, err := GetCollectionDetail("66cc458925aea7116ded53bc")
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("code=%v, data=%v", resp.Code, resp.Data)
+
+/**
+以下为集合相关
+*/
+
+//var params GetCollectionListReq
+//params.DatasetId = "66cc458925aea7116ded53ba"
+//params.PageNum = 1
+//params.PageSize = 20
+//resp, err := GetCollectionList(&params)
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("code=%v, data=%v", resp.Code, resp.Data)
+
+//var params CreateCollectionReq
+//params.DatasetId = "66cc458925aea7116ded53ba"
+//params.Name = "空集合v3"
+//params.Type = "folder"
+//resp, err := CreateEmptyCollection(&params)
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("%v", resp)
+
+//var params CreateTextCollectionReq
+//params.DatasetId = "66cc458925aea7116ded53ba"
+//params.Name = "文本测试训练v5"
+//params.Text = " 《毒战》改编自杜琪峰执导的同名电影,讲述为了抓捕韩国最大规模贩毒组织的神秘大BOSS李先生,警察元浩与李先生手下成员乐联手破案的故事。 "
+//params.TrainingType = "qa"
+//params.ChunkSize = 8000
+//params.ChunkSplitter = ""
+//params.QaPrompt = "11"
+//resp, err := CreateTextCollection(&params)
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("%v", resp)
+
+//var params CreateLinkCollectionReq
+//params.DatasetId = "66cc458925aea7116ded53ba"
+//params.Name = "链接测试训练v5"
+//params.Link = "https://doc.in/docs/course/quick-start/"
+//params.TrainingType = "chunk"
+//params.ChunkSize = 512
+//params.ChunkSplitter = ""
+//params.QaPrompt = ""
+//metadata := make(map[string]string)
+//metadata["webPageSelector"] = ".docs-content"
+//params.Metadata = metadata
+//resp, err := CreateLinkCollection(&params)
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("collectionId=%v", resp.Data.CollectionID)
+
+//data := make(map[string]string, 8)
+//filePath := "/tmp/movie.txt"
+//data["datasetId"] = "66cc458925aea7116ded53ba"
+//data["trainingType"] = "chunk"
+//data["chunkSize"] = "512"
+//data["chunkSplitter"] = ""
+//data["qaPrompt"] = ""
+//resp, err := CreateFileCollection(&data, filePath)
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("%v", resp)
+
+//var params UpdateCollectionReq
+//params.ID = "66cd6c0025aea7116dedb313"
+//params.Name = "链接集合V6"
+//resp, err := UpdateCollection(&params)
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("resp=%v", resp)
+
+//resp, err := DeleteCollection("66cd6c0025aea7116dedb313")
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("resp=%v", resp)
+
+/**
+以下为数据相关
+*/
+
+//resp, err := GetDataDetail("66cd773b25aea7116dedc017")
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("resp=%v", resp)
+
+//var params GetDataListReq
+//params.PageSize = 10
+//params.PageNum = 1
+//params.CollectionId = "66cd773b25aea7116dedc01a"
+//resp, err := GetDataList(&params)
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("resp=%v", resp)
+
+//var params CreateBulkDataReq
+//params.CollectionID = "66cd773b25aea7116dedc01a"
+//params.TrainingMode = "chunk"
+//params.Data = []DataQuestion{
+//	{
+//		Q: "你是谁?",
+//		A: "我是FastGPT助手",
+//	},
+//	{
+//		Q: "你会什么?",
+//		A: "我什么都会",
+//		Indexes: []Index{
+//			{Text: "自定义索引1"},
+//			{Text: "自定义索引2"},
+//		},
+//	},
+//}
+//resp, err := CreateBulkData(&params)
+//if err != nil {
+//	fmt.Printf("%v", err.Error())
+//}
+//fmt.Printf("resp=%v", resp)
+
+//var params UpdateDataReq
+//params.ID = "66cd7e1925aea7116dedc64b"
+//params.Q = "你是谁3?"
+//params.A = "我是FastGPT助手3"
+//params.Indexes = []Index{
+//	{Text: "自定义索引1", DataId: "66cd7e1925aea7116dedc64b", DefaultIndex: true},
+//	{Text: "自定义索引2", DataId: "66cd7e1925aea7116dedc64b", DefaultIndex: false},
+//}
+//resp, err := UpdateData(&params)
+//if err != nil {
+//	fmt.Printf("%v", err)
+//}
+//fmt.Printf("resp=%v", resp)
+
+//resp, err := DeleteData("66cd7e1925aea7116dedc651")
+//if err != nil {
+//	fmt.Printf("%v", err)
+//}
+//fmt.Printf("resp=%v", resp)
+
+/**
+以下为搜索相关
+*/
+
+//var params SearchReq
+//params.DatasetID = "66cc458925aea7116ded53ba"
+//params.Text = "毒战"
+//params.Limit = 20
+//params.SearchMode = "fullTextRecall"
+//params.UsingReRank = true
+//resp, err := SearchText(&params)
+//if err != nil {
+//	fmt.Printf("%v", err)
+//}
+//fmt.Printf("resp=%v", resp)