Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用户管理功能 #94

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions cmd/service/service_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ import (
"context"
"embed"
"fmt"
"io/fs"
"net"
"net/http"
"net/http/httputil"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"

tiktoken2 "github.com/IceBearAI/aigc/src/helpers/tiktoken"
"github.com/IceBearAI/aigc/src/pkg/account"
"github.com/IceBearAI/aigc/src/pkg/assistants"
"github.com/IceBearAI/aigc/src/pkg/auth"
"github.com/IceBearAI/aigc/src/pkg/channels"
Expand All @@ -16,22 +28,13 @@ import (
"github.com/IceBearAI/aigc/src/pkg/modelevaluate"
"github.com/IceBearAI/aigc/src/pkg/models"
"github.com/IceBearAI/aigc/src/pkg/sys"
"github.com/IceBearAI/aigc/src/pkg/tenant"
"github.com/IceBearAI/aigc/src/pkg/terminal"
"github.com/IceBearAI/aigc/src/pkg/tools"
"github.com/IceBearAI/aigc/src/repository/types"
"github.com/igm/sockjs-go/v3/sockjs"
"github.com/pkoukk/tiktoken-go"
"github.com/tmc/langchaingo/llms/openai"
"io/fs"
"net"
"net/http"
"net/http/httputil"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"

"github.com/go-kit/kit/tracing/opentracing"

Expand Down Expand Up @@ -66,9 +69,9 @@ aigc-server start -p :8080
return err
}

_ = generateTable()
// 判断是否需要初始化数据,如果没有则初始化数据
if !gormDB.Migrator().HasTable(types.Accounts{}) {
_ = generateTable()
if err = initData(); err != nil {
_ = level.Error(logger).Log("cmd.start.PreRunE", "initData", "err", err.Error())
return err
Expand Down Expand Up @@ -107,6 +110,8 @@ aigc-server start -p :8080
assistantsSvc assistants.Service
modelEvaluateSvc modelevaluate.Service
terminalSvc terminal.Service
accountSvc account.Service
tenantSvc tenant.Service
)

func start(ctx context.Context) (err error) {
Expand All @@ -127,6 +132,8 @@ func start(ctx context.Context) (err error) {
tiktoken.SetBpeLoader(tiktoken2.NewBpeLoader(DataFs))

authSvc = auth.New(logger, traceId, store, apiSvc)
accountSvc = account.New(logger, traceId, store, apiSvc)
tenantSvc = tenant.New(logger, traceId, store, apiSvc)
fileSvc = files.NewService(logger, traceId, store, apiSvc, []files.CreationOption{
files.WithLocalDataPath(serverStoragePath),
files.WithServerUrl(fmt.Sprintf("%s/storage", serverDomain)),
Expand Down Expand Up @@ -183,6 +190,8 @@ func start(ctx context.Context) (err error) {
datasetTaskSvc = datasettask.NewLogging(logger, logging.TraceId)(datasetTaskSvc)
modelEvaluateSvc = modelevaluate.NewLogging(logger, logging.TraceId)(modelEvaluateSvc)
terminalSvc = terminal.NewLogging(logger, logging.TraceId)(terminalSvc)
accountSvc = account.NewLogging(logger, logging.TraceId)(accountSvc)
tenantSvc = tenant.NewLogging(logger, logging.TraceId)(tenantSvc)
}

if tracer != nil {
Expand All @@ -198,6 +207,8 @@ func start(ctx context.Context) (err error) {
datasetTaskSvc = datasettask.NewTracing(tracer)(datasetTaskSvc)
modelEvaluateSvc = modelevaluate.NewTracing(tracer)(modelEvaluateSvc)
terminalSvc = terminal.NewTracing(tracer)(terminalSvc)
accountSvc = account.NewTracing(tracer)(accountSvc)
tenantSvc = tenant.NewTracing(tracer)(tenantSvc)
}

g := &group.Group{}
Expand Down Expand Up @@ -302,7 +313,10 @@ func initHttpHandler(ctx context.Context, g *group.Group) {
r := mux.NewRouter()
// auth模块
r.PathPrefix("/api/auth").Handler(http.StripPrefix("/api/auth", auth.MakeHTTPHandler(authSvc, authEms, opts)))

// account模块
r.PathPrefix("/api/accounts").Handler(http.StripPrefix("/api", account.MakeHTTPHandler(accountSvc, authEms, opts)))
// tenant模块
r.PathPrefix("/api/tenants").Handler(http.StripPrefix("/api", tenant.MakeHTTPHandler(tenantSvc, authEms, opts)))
// file模块
r.PathPrefix("/api/files").Handler(http.StripPrefix("/api", files.MakeHTTPHandler(fileSvc, authEms, opts)))
// channel模块
Expand Down
181 changes: 181 additions & 0 deletions src/pkg/account/endpoint.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading