Skip to content

Commit

Permalink
feat: aiproxy service (#5209)
Browse files Browse the repository at this point in the history
* feat: aiproxy service init

* fix: go work use

* fix: golang lint

* fix: golang lint

* fix: aiproxy deploy cluster

* fix: deploy service ns

* fix: foreignkey

* fix: get channel

* fix: search key str to int

* fix: big int

* chore: add index

* fix: marshal json alias use pointer

* feat: str fmt lint and message conv to en

* fix: baidu conv frequency penalty -2.0-2.0 to 1.0-2.0

* fix: fast conv message
  • Loading branch information
zijiren233 authored Nov 20, 2024
1 parent 0d3f8b0 commit 1c05beb
Show file tree
Hide file tree
Showing 203 changed files with 18,911 additions and 83 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
strategy:
matrix:
## TODO: add more modules
module: [database, pay, account, minio, launchpad, exceptionmonitor]
module: [database, pay, account, minio, launchpad, exceptionmonitor, aiproxy]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:
strategy:
matrix:
## TODO: add more modules
module: [database, pay, account, minio, launchpad, exceptionmonitor]
module: [database, pay, account, minio, launchpad, exceptionmonitor, aiproxy]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
7 changes: 7 additions & 0 deletions service/aiproxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM gcr.io/distroless/static:nonroot
ARG TARGETARCH
COPY bin/service-aiproxy-$TARGETARCH /manager
EXPOSE 3000
USER 65532:65532

ENTRYPOINT ["/manager"]
53 changes: 53 additions & 0 deletions service/aiproxy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
IMG ?= ghcr.io/labring/sealos-aiproxy-service:latest

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

# only support linux, non cgo
PLATFORMS ?= linux_arm64 linux_amd64
GOOS=linux
GOARCH=$(shell go env GOARCH)

.PHONY: all
all: build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build

.PHONY: clean
clean:
rm -f $(SERVICE_NAME)

.PHONY: build
build: ## Build service-hub binary.
LD_FLAGS="-s -w -extldflags '-static'"; \
CGO_ENABLED=0 GOOS=linux go build -tags "jsoniter" -ldflags "$${LD_FLAGS}" -trimpath -o bin/manager main.go

.PHONY: docker-build
docker-build: build
mv bin/manager bin/service-aiproxy-${TARGETARCH}
docker build -t $(IMG) .

.PHONY: docker-push
docker-push:
docker push $(IMG)
14 changes: 14 additions & 0 deletions service/aiproxy/common/balance/balance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package balance

import "context"

type GroupBalance interface {
GetGroupRemainBalance(ctx context.Context, group string) (float64, PostGroupConsumer, error)
}

type PostGroupConsumer interface {
PostGroupConsume(ctx context.Context, tokenName string, usage float64) (float64, error)
GetBalance(ctx context.Context) (float64, error)
}

var Default GroupBalance = NewMockGroupBalance()
27 changes: 27 additions & 0 deletions service/aiproxy/common/balance/mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package balance

import "context"

var _ GroupBalance = (*MockGroupBalance)(nil)

const (
mockBalance = 10000000
)

type MockGroupBalance struct{}

func NewMockGroupBalance() *MockGroupBalance {
return &MockGroupBalance{}
}

func (q *MockGroupBalance) GetGroupRemainBalance(_ context.Context, _ string) (float64, PostGroupConsumer, error) {
return mockBalance, q, nil
}

func (q *MockGroupBalance) PostGroupConsume(_ context.Context, _ string, usage float64) (float64, error) {
return usage, nil
}

func (q *MockGroupBalance) GetBalance(_ context.Context) (float64, error) {
return mockBalance, nil
}
Loading

0 comments on commit 1c05beb

Please sign in to comment.