mirror of
https://github.com/linux-do/new-api.git
synced 2025-11-18 03:23:42 +08:00
Compare commits
103 Commits
208bc5e794
...
v0.2.10
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c0b93c38c | ||
|
|
b648816add | ||
|
|
1f694315ce | ||
|
|
0fd3e407dc | ||
|
|
c0ab39e446 | ||
|
|
e4c01cb9ae | ||
|
|
d43a65bc52 | ||
|
|
d62dd4d9a2 | ||
|
|
f113e1874e | ||
|
|
c6d5245c5c | ||
|
|
d1ea2d2d0a | ||
|
|
8b8abfadaf | ||
|
|
65e65097b2 | ||
|
|
62e321fe30 | ||
|
|
312ab44800 | ||
|
|
a2678a256d | ||
|
|
8b67664995 | ||
|
|
e0f780185a | ||
|
|
c47e1dc6fe | ||
|
|
ade6d0f56a | ||
|
|
f599c65944 | ||
|
|
40baa636e4 | ||
|
|
d6359ec4ff | ||
|
|
89ddf83b44 | ||
|
|
6a8a4bcf65 | ||
|
|
e298f2e5a4 | ||
|
|
8cea6dff4a | ||
|
|
5035cd054a | ||
|
|
02c0c6501e | ||
|
|
f0b808a41d | ||
|
|
31d84ee32f | ||
|
|
9969ed2d7c | ||
|
|
746311242b | ||
|
|
04a68a85dd | ||
|
|
f9ba10f180 | ||
|
|
334a6f8280 | ||
|
|
0cf53ac5ff | ||
|
|
af02cdc58b | ||
|
|
9a4ca1e210 | ||
|
|
27b8495698 | ||
|
|
9fe1f35fd1 | ||
|
|
972ac1ee0f | ||
|
|
0f95502b04 | ||
|
|
b58b1dc0ec | ||
|
|
05d9aa61df | ||
|
|
221894d972 | ||
|
|
333849429b | ||
|
|
50eab6b4e4 | ||
|
|
ed972eef06 | ||
|
|
c6ff785a83 | ||
|
|
2e734e0c37 | ||
|
|
af33f36c7b | ||
|
|
3aa86a8cd9 | ||
|
|
af7fecbfa7 | ||
|
|
3fbdd502b6 | ||
|
|
052bc2075b | ||
|
|
5f3798053f | ||
|
|
e31022c676 | ||
|
|
fff7609f06 | ||
|
|
9032b5cfbf | ||
|
|
131453dac8 | ||
|
|
ed948c121a | ||
|
|
a03cd15505 | ||
|
|
02f5137781 | ||
|
|
e6df0ed20c | ||
|
|
f505afdc10 | ||
|
|
feb1d76942 | ||
|
|
6263616cd9 | ||
|
|
9b14c5da63 | ||
|
|
6bbf1d4843 | ||
|
|
13c993d87e | ||
|
|
cb73889353 | ||
|
|
804aad3f37 | ||
|
|
3af62a3efa | ||
|
|
be54369c12 | ||
|
|
0cbf8e07e7 | ||
|
|
1675679be9 | ||
|
|
0b5f2a7089 | ||
|
|
b5bb708072 | ||
|
|
2650ec9b59 | ||
|
|
d168a685c1 | ||
|
|
a9e3555cac | ||
|
|
8d83630d85 | ||
|
|
a60f209c85 | ||
|
|
a0d20896b3 | ||
|
|
5cab06d1ce | ||
|
|
e3b3fdec48 | ||
|
|
5863aa8061 | ||
|
|
0ada2371b6 | ||
|
|
a0673ef2b6 | ||
|
|
416f831a6c | ||
|
|
0b4317ce28 | ||
|
|
2223aeb022 | ||
|
|
ecf2f7f212 | ||
|
|
033359e93c | ||
|
|
1379d7f184 | ||
|
|
716bf6f48a | ||
|
|
2422eb2820 | ||
|
|
c97e2875b4 | ||
|
|
64794630c8 | ||
|
|
fc5055c766 | ||
|
|
27eb358497 | ||
|
|
6810ee0a28 |
10
Dockerfile
10
Dockerfile
@@ -1,13 +1,13 @@
|
|||||||
FROM node:16 as builder
|
FROM oven/bun:latest AS builder
|
||||||
|
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
COPY web/package.json .
|
COPY web/package.json .
|
||||||
RUN npm install
|
RUN bun install
|
||||||
COPY ./web .
|
COPY ./web .
|
||||||
COPY ./VERSION .
|
COPY ./VERSION .
|
||||||
RUN DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(cat VERSION) npm run build
|
RUN DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(cat VERSION) bun run build
|
||||||
|
|
||||||
FROM golang AS builder2
|
FROM golang:1.21 AS builder2
|
||||||
|
|
||||||
ENV GO111MODULE=on \
|
ENV GO111MODULE=on \
|
||||||
CGO_ENABLED=1 \
|
CGO_ENABLED=1 \
|
||||||
@@ -25,7 +25,7 @@ FROM alpine
|
|||||||
RUN apk update \
|
RUN apk update \
|
||||||
&& apk upgrade \
|
&& apk upgrade \
|
||||||
&& apk add --no-cache ca-certificates tzdata \
|
&& apk add --no-cache ca-certificates tzdata \
|
||||||
&& update-ca-certificates 2>/dev/null || true
|
&& update-ca-certificates
|
||||||
|
|
||||||
COPY --from=builder2 /build/one-api /
|
COPY --from=builder2 /build/one-api /
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|||||||
24
README.md
24
README.md
@@ -1,6 +1,13 @@
|
|||||||
|
<div align="center">
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
# New API
|
# New API
|
||||||
|
|
||||||
|
<a href="https://trendshift.io/repositories/8227" target="_blank"><img src="https://trendshift.io/api/badge/repositories/8227" alt="Calcium-Ion%2Fnew-api | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> 本项目为开源项目,在[One API](https://github.com/songquanpeng/one-api)的基础上进行二次开发
|
> 本项目为开源项目,在[One API](https://github.com/songquanpeng/one-api)的基础上进行二次开发
|
||||||
|
|
||||||
@@ -59,6 +66,7 @@
|
|||||||
您可以在渠道中添加自定义模型gpt-4-gizmo-*或g-*,此模型并非OpenAI官方模型,而是第三方模型,使用官方key无法调用。
|
您可以在渠道中添加自定义模型gpt-4-gizmo-*或g-*,此模型并非OpenAI官方模型,而是第三方模型,使用官方key无法调用。
|
||||||
|
|
||||||
## 比原版One API多出的配置
|
## 比原版One API多出的配置
|
||||||
|
- `GENERATE_DEFAULT_TOKEN`:是否为新注册用户生成初始令牌,默认为 `false`。
|
||||||
- `STREAMING_TIMEOUT`:设置流式一次回复的超时时间,默认为 30 秒。
|
- `STREAMING_TIMEOUT`:设置流式一次回复的超时时间,默认为 30 秒。
|
||||||
- `DIFY_DEBUG`:设置 Dify 渠道是否输出工作流和节点信息到客户端,默认为 `true`。
|
- `DIFY_DEBUG`:设置 Dify 渠道是否输出工作流和节点信息到客户端,默认为 `true`。
|
||||||
- `FORCE_STREAM_OPTION`:是否覆盖客户端stream_options参数,请求上游返回流模式usage,默认为 `true`,建议开启,不影响客户端传入stream_options参数返回结果。
|
- `FORCE_STREAM_OPTION`:是否覆盖客户端stream_options参数,请求上游返回流模式usage,默认为 `true`,建议开启,不影响客户端传入stream_options参数返回结果。
|
||||||
@@ -66,7 +74,7 @@
|
|||||||
- `GET_MEDIA_TOKEN_NOT_STREAM`:是否在非流(`stream=false`)情况下统计图片token,默认为 `true`。
|
- `GET_MEDIA_TOKEN_NOT_STREAM`:是否在非流(`stream=false`)情况下统计图片token,默认为 `true`。
|
||||||
- `UPDATE_TASK`:是否更新异步任务(Midjourney、Suno),默认为 `true`,关闭后将不会更新任务进度。
|
- `UPDATE_TASK`:是否更新异步任务(Midjourney、Suno),默认为 `true`,关闭后将不会更新任务进度。
|
||||||
- `GEMINI_MODEL_MAP`:Gemini模型指定版本(v1/v1beta),使用“模型:版本”指定,","分隔,例如:-e GEMINI_MODEL_MAP="gemini-1.5-pro-latest:v1beta,gemini-1.5-pro-001:v1beta",为空则使用默认配置
|
- `GEMINI_MODEL_MAP`:Gemini模型指定版本(v1/v1beta),使用“模型:版本”指定,","分隔,例如:-e GEMINI_MODEL_MAP="gemini-1.5-pro-latest:v1beta,gemini-1.5-pro-001:v1beta",为空则使用默认配置
|
||||||
|
- `COHERE_SAFETY_SETTING`:Cohere模型[安全设置](https://docs.cohere.com/docs/safety-modes#overview),可选值为 `NONE`, `CONTEXTUAL`,`STRICT`,默认为 `NONE`。
|
||||||
## 部署
|
## 部署
|
||||||
### 部署要求
|
### 部署要求
|
||||||
- 本地数据库(默认):SQLite(Docker 部署默认使用 SQLite,必须挂载 `/data` 目录到宿主机)
|
- 本地数据库(默认):SQLite(Docker 部署默认使用 SQLite,必须挂载 `/data` 目录到宿主机)
|
||||||
@@ -115,22 +123,14 @@ docker run --name new-api -d --restart always -p 3000:3000 -e SQL_DSN="root:1234
|
|||||||
## Suno接口设置文档
|
## Suno接口设置文档
|
||||||
[对接文档](Suno.md)
|
[对接文档](Suno.md)
|
||||||
|
|
||||||
## 交流群
|
|
||||||
<img src="https://github.com/Calcium-Ion/new-api/assets/61247483/de536a8a-0161-47a7-a0a2-66ef6de81266" width="300">
|
|
||||||
|
|
||||||
## 界面截图
|
## 界面截图
|
||||||
|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||
夜间模式
|
夜间模式
|
||||||

|

|
||||||
|
|
||||||

|
|
||||||

|

|
||||||
|
|
||||||
## 相关项目
|
## 相关项目
|
||||||
|
|||||||
@@ -129,6 +129,9 @@ var RelayTimeout = GetEnvOrDefault("RELAY_TIMEOUT", 0) // unit is second
|
|||||||
|
|
||||||
var GeminiSafetySetting = GetEnvOrDefaultString("GEMINI_SAFETY_SETTING", "BLOCK_NONE")
|
var GeminiSafetySetting = GetEnvOrDefaultString("GEMINI_SAFETY_SETTING", "BLOCK_NONE")
|
||||||
|
|
||||||
|
// https://docs.cohere.com/docs/safety-modes Type; NONE/CONTEXTUAL/STRICT
|
||||||
|
var CohereSafetySetting = GetEnvOrDefaultString("COHERE_SAFETY_SETTING", "NONE")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RequestIdKey = "X-Oneapi-Request-Id"
|
RequestIdKey = "X-Oneapi-Request-Id"
|
||||||
)
|
)
|
||||||
@@ -140,6 +143,10 @@ const (
|
|||||||
RoleRootUser = 100
|
RoleRootUser = 100
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func IsValidateRole(role int) bool {
|
||||||
|
return role == RoleGuestUser || role == RoleCommonUser || role == RoleAdminUser || role == RoleRootUser
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
FileUploadPermission = RoleGuestUser
|
FileUploadPermission = RoleGuestUser
|
||||||
FileDownloadPermission = RoleGuestUser
|
FileDownloadPermission = RoleGuestUser
|
||||||
|
|||||||
@@ -23,123 +23,136 @@ const (
|
|||||||
|
|
||||||
var defaultModelRatio = map[string]float64{
|
var defaultModelRatio = map[string]float64{
|
||||||
//"midjourney": 50,
|
//"midjourney": 50,
|
||||||
"gpt-4-gizmo-*": 15,
|
"gpt-4-gizmo-*": 15,
|
||||||
"g-*": 15,
|
"g-*": 15,
|
||||||
"gpt-4": 15,
|
"gpt-4": 15,
|
||||||
"gpt-4-0314": 15,
|
"gpt-4-0314": 15,
|
||||||
"gpt-4-0613": 15,
|
"gpt-4-0613": 15,
|
||||||
"gpt-4-32k": 30,
|
"gpt-4-32k": 30,
|
||||||
"gpt-4-32k-0314": 30,
|
"gpt-4-32k-0314": 30,
|
||||||
"gpt-4-32k-0613": 30,
|
"gpt-4-32k-0613": 30,
|
||||||
"gpt-4o-mini": 0.075, // $0.00015 / 1K tokens
|
"gpt-4o-mini": 0.075, // $0.00015 / 1K tokens
|
||||||
"gpt-4o-mini-2024-07-18": 0.075,
|
"gpt-4o-mini-2024-07-18": 0.075,
|
||||||
"chatgpt-4o-latest": 2.5, // $0.01 / 1K tokens
|
"chatgpt-4o-latest": 2.5, // $0.01 / 1K tokens
|
||||||
"gpt-4o": 2.5, // $0.005 / 1K tokens
|
"gpt-4o": 1.25, // $0.005 / 1K tokens
|
||||||
"gpt-4o-2024-05-13": 2.5, // $0.005 / 1K tokens
|
"gpt-4o-2024-05-13": 2.5, // $0.005 / 1K tokens
|
||||||
"gpt-4o-2024-08-06": 1.25, // $0.01 / 1K tokens
|
"gpt-4o-2024-08-06": 1.25, // $0.01 / 1K tokens
|
||||||
"gpt-4-turbo": 5, // $0.01 / 1K tokens
|
"gpt-4o-2024-11-20": 1.25, // $0.01 / 1K tokens
|
||||||
"gpt-4-turbo-2024-04-09": 5, // $0.01 / 1K tokens
|
"o1-preview": 7.5,
|
||||||
"gpt-4-1106-preview": 5, // $0.01 / 1K tokens
|
"o1-preview-2024-09-12": 7.5,
|
||||||
"gpt-4-0125-preview": 5, // $0.01 / 1K tokens
|
"o1-mini": 0.55, // $0.0011 / 1K tokens
|
||||||
"gpt-4-turbo-preview": 5, // $0.01 / 1K tokens
|
"o1-mini-2024-09-12": 0.55,
|
||||||
"gpt-4-vision-preview": 5, // $0.01 / 1K tokens
|
"o3-mini": 0.55,
|
||||||
"gpt-4-1106-vision-preview": 5, // $0.01 / 1K tokens
|
"o3-mini-2025-01-31": 0.55,
|
||||||
"gpt-3.5-turbo": 0.25, // $0.0005 / 1K tokens
|
"gpt-4-turbo": 5, // $0.01 / 1K tokens
|
||||||
"gpt-3.5-turbo-0301": 0.75,
|
"gpt-4-turbo-2024-04-09": 5, // $0.01 / 1K tokens
|
||||||
"gpt-3.5-turbo-0613": 0.75,
|
"gpt-4-1106-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-3.5-turbo-16k": 1.5, // $0.003 / 1K tokens
|
"gpt-4-0125-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-3.5-turbo-16k-0613": 1.5,
|
"gpt-4-turbo-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-3.5-turbo-instruct": 0.75, // $0.0015 / 1K tokens
|
"gpt-4-vision-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-3.5-turbo-1106": 0.5, // $0.001 / 1K tokens
|
"gpt-4-1106-vision-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-3.5-turbo-0125": 0.25,
|
"gpt-3.5-turbo": 0.25, // $0.0005 / 1K tokens
|
||||||
"babbage-002": 0.2, // $0.0004 / 1K tokens
|
"gpt-3.5-turbo-0301": 0.75,
|
||||||
"davinci-002": 1, // $0.002 / 1K tokens
|
"gpt-3.5-turbo-0613": 0.75,
|
||||||
"text-ada-001": 0.2,
|
"gpt-3.5-turbo-16k": 1.5, // $0.003 / 1K tokens
|
||||||
"text-babbage-001": 0.25,
|
"gpt-3.5-turbo-16k-0613": 1.5,
|
||||||
"text-curie-001": 1,
|
"gpt-3.5-turbo-instruct": 0.75, // $0.0015 / 1K tokens
|
||||||
"text-davinci-002": 10,
|
"gpt-3.5-turbo-1106": 0.5, // $0.001 / 1K tokens
|
||||||
"text-davinci-003": 10,
|
"gpt-3.5-turbo-0125": 0.25,
|
||||||
"text-davinci-edit-001": 10,
|
"babbage-002": 0.2, // $0.0004 / 1K tokens
|
||||||
"code-davinci-edit-001": 10,
|
"davinci-002": 1, // $0.002 / 1K tokens
|
||||||
"whisper-1": 15, // $0.006 / minute -> $0.006 / 150 words -> $0.006 / 200 tokens -> $0.03 / 1k tokens
|
"text-ada-001": 0.2,
|
||||||
"tts-1": 7.5, // 1k characters -> $0.015
|
"text-babbage-001": 0.25,
|
||||||
"tts-1-1106": 7.5, // 1k characters -> $0.015
|
"text-curie-001": 1,
|
||||||
"tts-1-hd": 15, // 1k characters -> $0.03
|
"text-davinci-002": 10,
|
||||||
"tts-1-hd-1106": 15, // 1k characters -> $0.03
|
"text-davinci-003": 10,
|
||||||
"davinci": 10,
|
"text-davinci-edit-001": 10,
|
||||||
"curie": 10,
|
"code-davinci-edit-001": 10,
|
||||||
"babbage": 10,
|
"whisper-1": 15, // $0.006 / minute -> $0.006 / 150 words -> $0.006 / 200 tokens -> $0.03 / 1k tokens
|
||||||
"ada": 10,
|
"tts-1": 7.5, // 1k characters -> $0.015
|
||||||
"text-embedding-3-small": 0.01,
|
"tts-1-1106": 7.5, // 1k characters -> $0.015
|
||||||
"text-embedding-3-large": 0.065,
|
"tts-1-hd": 15, // 1k characters -> $0.03
|
||||||
"text-embedding-ada-002": 0.05,
|
"tts-1-hd-1106": 15, // 1k characters -> $0.03
|
||||||
"text-search-ada-doc-001": 10,
|
"davinci": 10,
|
||||||
"text-moderation-stable": 0.1,
|
"curie": 10,
|
||||||
"text-moderation-latest": 0.1,
|
"babbage": 10,
|
||||||
"claude-instant-1": 0.4, // $0.8 / 1M tokens
|
"ada": 10,
|
||||||
"claude-2.0": 4, // $8 / 1M tokens
|
"text-embedding-3-small": 0.01,
|
||||||
"claude-2.1": 4, // $8 / 1M tokens
|
"text-embedding-3-large": 0.065,
|
||||||
"claude-3-haiku-20240307": 0.125, // $0.25 / 1M tokens
|
"text-embedding-ada-002": 0.05,
|
||||||
"claude-3-5-sonnet-20240620": 1.5, // $3 / 1M tokens
|
"text-search-ada-doc-001": 10,
|
||||||
"claude-3-sonnet-20240229": 1.5, // $3 / 1M tokens
|
"text-moderation-stable": 0.1,
|
||||||
"claude-3-opus-20240229": 7.5, // $15 / 1M tokens
|
"text-moderation-latest": 0.1,
|
||||||
"ERNIE-4.0-8K": 0.120 * RMB,
|
"claude-instant-1": 0.4, // $0.8 / 1M tokens
|
||||||
"ERNIE-3.5-8K": 0.012 * RMB,
|
"claude-2.0": 4, // $8 / 1M tokens
|
||||||
"ERNIE-3.5-8K-0205": 0.024 * RMB,
|
"claude-2.1": 4, // $8 / 1M tokens
|
||||||
"ERNIE-3.5-8K-1222": 0.012 * RMB,
|
"claude-3-7-sonnet-20250219": 1.5,
|
||||||
"ERNIE-Bot-8K": 0.024 * RMB,
|
"claude-3-7-sonnet-20250219-thinking": 1.5,
|
||||||
"ERNIE-3.5-4K-0205": 0.012 * RMB,
|
"claude-3-5-haiku-20241022": 0.4,
|
||||||
"ERNIE-Speed-8K": 0.004 * RMB,
|
"claude-3-haiku-20240307": 0.125, // $0.25 / 1M tokens
|
||||||
"ERNIE-Speed-128K": 0.004 * RMB,
|
"claude-3-5-sonnet-20240620": 1.5, // $3 / 1M tokens
|
||||||
"ERNIE-Lite-8K-0922": 0.008 * RMB,
|
"claude-3-5-sonnet-20241022": 1.5, // $3 / 1M tokens
|
||||||
"ERNIE-Lite-8K-0308": 0.003 * RMB,
|
"claude-3-sonnet-20240229": 1.5, // $3 / 1M tokens
|
||||||
"ERNIE-Tiny-8K": 0.001 * RMB,
|
"claude-3-opus-20240229": 7.5, // $15 / 1M tokens
|
||||||
"BLOOMZ-7B": 0.004 * RMB,
|
"ERNIE-4.0-8K": 0.120 * RMB,
|
||||||
"Embedding-V1": 0.002 * RMB,
|
"ERNIE-3.5-8K": 0.012 * RMB,
|
||||||
"bge-large-zh": 0.002 * RMB,
|
"ERNIE-3.5-8K-0205": 0.024 * RMB,
|
||||||
"bge-large-en": 0.002 * RMB,
|
"ERNIE-3.5-8K-1222": 0.012 * RMB,
|
||||||
"tao-8k": 0.002 * RMB,
|
"ERNIE-Bot-8K": 0.024 * RMB,
|
||||||
"PaLM-2": 1,
|
"ERNIE-3.5-4K-0205": 0.012 * RMB,
|
||||||
"gemini-pro": 1, // $0.00025 / 1k characters -> $0.001 / 1k tokens
|
"ERNIE-Speed-8K": 0.004 * RMB,
|
||||||
"gemini-pro-vision": 1, // $0.00025 / 1k characters -> $0.001 / 1k tokens
|
"ERNIE-Speed-128K": 0.004 * RMB,
|
||||||
"gemini-1.0-pro-vision-001": 1,
|
"ERNIE-Lite-8K-0922": 0.008 * RMB,
|
||||||
"gemini-1.0-pro-001": 1,
|
"ERNIE-Lite-8K-0308": 0.003 * RMB,
|
||||||
"gemini-1.5-pro-latest": 1,
|
"ERNIE-Tiny-8K": 0.001 * RMB,
|
||||||
"gemini-1.5-flash-latest": 1,
|
"BLOOMZ-7B": 0.004 * RMB,
|
||||||
"gemini-1.0-pro-latest": 1,
|
"Embedding-V1": 0.002 * RMB,
|
||||||
"gemini-1.0-pro-vision-latest": 1,
|
"bge-large-zh": 0.002 * RMB,
|
||||||
"gemini-ultra": 1,
|
"bge-large-en": 0.002 * RMB,
|
||||||
"chatglm_turbo": 0.3572, // ¥0.005 / 1k tokens
|
"tao-8k": 0.002 * RMB,
|
||||||
"chatglm_pro": 0.7143, // ¥0.01 / 1k tokens
|
"PaLM-2": 1,
|
||||||
"chatglm_std": 0.3572, // ¥0.005 / 1k tokens
|
"gemini-pro": 1, // $0.00025 / 1k characters -> $0.001 / 1k tokens
|
||||||
"chatglm_lite": 0.1429, // ¥0.002 / 1k tokens
|
"gemini-pro-vision": 1, // $0.00025 / 1k characters -> $0.001 / 1k tokens
|
||||||
"glm-4": 7.143, // ¥0.1 / 1k tokens
|
"gemini-1.0-pro-vision-001": 1,
|
||||||
"glm-4v": 0.05 * RMB, // ¥0.05 / 1k tokens
|
"gemini-1.0-pro-001": 1,
|
||||||
"glm-4-alltools": 0.1 * RMB, // ¥0.1 / 1k tokens
|
"gemini-1.5-pro-latest": 1.75, // $3.5 / 1M tokens
|
||||||
"glm-3-turbo": 0.3572,
|
"gemini-1.5-pro-exp-0827": 1.75, // $3.5 / 1M tokens
|
||||||
"glm-4-plus": 0.05 * RMB,
|
"gemini-1.5-flash-latest": 1,
|
||||||
"glm-4-0520": 0.1 * RMB,
|
"gemini-1.5-flash-exp-0827": 1,
|
||||||
"glm-4-air": 0.001 * RMB,
|
"gemini-1.0-pro-latest": 1,
|
||||||
"glm-4-airx": 0.01 * RMB,
|
"gemini-1.0-pro-vision-latest": 1,
|
||||||
"glm-4-long": 0.001 * RMB,
|
"gemini-ultra": 1,
|
||||||
"glm-4-flash": 0,
|
"chatglm_turbo": 0.3572, // ¥0.005 / 1k tokens
|
||||||
"glm-4v-plus": 0.01 * RMB,
|
"chatglm_pro": 0.7143, // ¥0.01 / 1k tokens
|
||||||
"qwen-turbo": 0.8572, // ¥0.012 / 1k tokens
|
"chatglm_std": 0.3572, // ¥0.005 / 1k tokens
|
||||||
"qwen-plus": 10, // ¥0.14 / 1k tokens
|
"chatglm_lite": 0.1429, // ¥0.002 / 1k tokens
|
||||||
"text-embedding-v1": 0.05, // ¥0.0007 / 1k tokens
|
"glm-4": 7.143, // ¥0.1 / 1k tokens
|
||||||
"SparkDesk-v1.1": 1.2858, // ¥0.018 / 1k tokens
|
"glm-4v": 0.05 * RMB, // ¥0.05 / 1k tokens
|
||||||
"SparkDesk-v2.1": 1.2858, // ¥0.018 / 1k tokens
|
"glm-4-alltools": 0.1 * RMB, // ¥0.1 / 1k tokens
|
||||||
"SparkDesk-v3.1": 1.2858, // ¥0.018 / 1k tokens
|
"glm-3-turbo": 0.3572,
|
||||||
"SparkDesk-v3.5": 1.2858, // ¥0.018 / 1k tokens
|
"glm-4-plus": 0.05 * RMB,
|
||||||
"SparkDesk-v4.0": 1.2858,
|
"glm-4-0520": 0.1 * RMB,
|
||||||
"360GPT_S2_V9": 0.8572, // ¥0.012 / 1k tokens
|
"glm-4-air": 0.001 * RMB,
|
||||||
"360gpt-turbo": 0.0858, // ¥0.0012 / 1k tokens
|
"glm-4-airx": 0.01 * RMB,
|
||||||
"360gpt-turbo-responsibility-8k": 0.8572, // ¥0.012 / 1k tokens
|
"glm-4-long": 0.001 * RMB,
|
||||||
"360gpt-pro": 0.8572, // ¥0.012 / 1k tokens
|
"glm-4-flash": 0,
|
||||||
"embedding-bert-512-v1": 0.0715, // ¥0.001 / 1k tokens
|
"glm-4v-plus": 0.01 * RMB,
|
||||||
"embedding_s1_v1": 0.0715, // ¥0.001 / 1k tokens
|
"qwen-turbo": 0.8572, // ¥0.012 / 1k tokens
|
||||||
"semantic_similarity_s1_v1": 0.0715, // ¥0.001 / 1k tokens
|
"qwen-plus": 10, // ¥0.14 / 1k tokens
|
||||||
"hunyuan": 7.143, // ¥0.1 / 1k tokens // https://cloud.tencent.com/document/product/1729/97731#e0e6be58-60c8-469f-bdeb-6c264ce3b4d0
|
"text-embedding-v1": 0.05, // ¥0.0007 / 1k tokens
|
||||||
|
"SparkDesk-v1.1": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v2.1": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v3.1": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v3.5": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v4.0": 1.2858,
|
||||||
|
"360GPT_S2_V9": 0.8572, // ¥0.012 / 1k tokens
|
||||||
|
"360gpt-turbo": 0.0858, // ¥0.0012 / 1k tokens
|
||||||
|
"360gpt-turbo-responsibility-8k": 0.8572, // ¥0.012 / 1k tokens
|
||||||
|
"360gpt-pro": 0.8572, // ¥0.012 / 1k tokens
|
||||||
|
"embedding-bert-512-v1": 0.0715, // ¥0.001 / 1k tokens
|
||||||
|
"embedding_s1_v1": 0.0715, // ¥0.001 / 1k tokens
|
||||||
|
"semantic_similarity_s1_v1": 0.0715, // ¥0.001 / 1k tokens
|
||||||
|
"hunyuan": 7.143, // ¥0.1 / 1k tokens // https://cloud.tencent.com/document/product/1729/97731#e0e6be58-60c8-469f-bdeb-6c264ce3b4d0
|
||||||
// https://platform.lingyiwanwu.com/docs#-计费单元
|
// https://platform.lingyiwanwu.com/docs#-计费单元
|
||||||
// 已经按照 7.2 来换算美元价格
|
// 已经按照 7.2 来换算美元价格
|
||||||
"yi-34b-chat-0205": 0.18,
|
"yi-34b-chat-0205": 0.18,
|
||||||
@@ -344,15 +357,22 @@ func GetCompletionRatio(name string) float64 {
|
|||||||
return 4.0 / 3.0
|
return 4.0 / 3.0
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(name, "gpt-4") && name != "gpt-4-all" && name != "gpt-4-gizmo-*" {
|
if strings.HasPrefix(name, "gpt-4") && name != "gpt-4-all" && name != "gpt-4-gizmo-*" {
|
||||||
if strings.HasPrefix(name, "gpt-4o-mini") || "gpt-4o-2024-08-06" == name {
|
if strings.HasSuffix(name, "preview") || strings.HasPrefix(name, "gpt-4-turbo") || "gpt-4o-2024-05-13" == name {
|
||||||
|
return 3
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(name, "gpt-4o") {
|
||||||
return 4
|
return 4
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasSuffix(name, "preview") || strings.HasPrefix(name, "gpt-4-turbo") || strings.HasPrefix(name, "gpt-4o") {
|
|
||||||
return 3
|
|
||||||
}
|
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
if "o1" == name || strings.HasPrefix(name, "o1-") {
|
||||||
|
return 4
|
||||||
|
}
|
||||||
|
if "o3" == name || strings.HasPrefix(name, "o3-") {
|
||||||
|
return 4
|
||||||
|
}
|
||||||
if name == "chatgpt-4o-latest" {
|
if name == "chatgpt-4o-latest" {
|
||||||
return 3
|
return 3
|
||||||
}
|
}
|
||||||
@@ -367,7 +387,7 @@ func GetCompletionRatio(name string) float64 {
|
|||||||
return 3
|
return 3
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(name, "gemini-") {
|
if strings.HasPrefix(name, "gemini-") {
|
||||||
return 3
|
return 4
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(name, "command") {
|
if strings.HasPrefix(name, "command") {
|
||||||
switch name {
|
switch name {
|
||||||
|
|||||||
46
common/user_groups.go
Normal file
46
common/user_groups.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
var UserUsableGroups = map[string]string{
|
||||||
|
"default": "默认分组",
|
||||||
|
"vip": "vip分组",
|
||||||
|
}
|
||||||
|
|
||||||
|
func UserUsableGroups2JSONString() string {
|
||||||
|
jsonBytes, err := json.Marshal(UserUsableGroups)
|
||||||
|
if err != nil {
|
||||||
|
SysError("error marshalling user groups: " + err.Error())
|
||||||
|
}
|
||||||
|
return string(jsonBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateUserUsableGroupsByJSONString(jsonStr string) error {
|
||||||
|
UserUsableGroups = make(map[string]string)
|
||||||
|
return json.Unmarshal([]byte(jsonStr), &UserUsableGroups)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetUserUsableGroups(userGroup string) map[string]string {
|
||||||
|
if userGroup == "" {
|
||||||
|
// 如果userGroup为空,返回UserUsableGroups
|
||||||
|
return UserUsableGroups
|
||||||
|
}
|
||||||
|
// 如果userGroup不在UserUsableGroups中,返回UserUsableGroups + userGroup
|
||||||
|
if _, ok := UserUsableGroups[userGroup]; !ok {
|
||||||
|
appendUserUsableGroups := make(map[string]string)
|
||||||
|
for k, v := range UserUsableGroups {
|
||||||
|
appendUserUsableGroups[k] = v
|
||||||
|
}
|
||||||
|
appendUserUsableGroups[userGroup] = "用户分组"
|
||||||
|
return appendUserUsableGroups
|
||||||
|
}
|
||||||
|
// 如果userGroup在UserUsableGroups中,返回UserUsableGroups
|
||||||
|
return UserUsableGroups
|
||||||
|
}
|
||||||
|
|
||||||
|
func GroupInUserUsableGroups(groupName string) bool {
|
||||||
|
_, ok := UserUsableGroups[groupName]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
@@ -3,11 +3,14 @@ package common
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
crand "crypto/rand"
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"golang.org/x/net/proxy"
|
"golang.org/x/net/proxy"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
|
"math/big"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -133,6 +136,11 @@ func IntMax(a int, b int) int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsIP(s string) bool {
|
||||||
|
ip := net.ParseIP(s)
|
||||||
|
return ip != nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetUUID() string {
|
func GetUUID() string {
|
||||||
code := uuid.New().String()
|
code := uuid.New().String()
|
||||||
code = strings.Replace(code, "-", "", -1)
|
code = strings.Replace(code, "-", "", -1)
|
||||||
@@ -142,24 +150,35 @@ func GetUUID() string {
|
|||||||
const keyChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
const keyChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateKey() string {
|
func GenerateRandomCharsKey(length int) (string, error) {
|
||||||
//rand.Seed(time.Now().UnixNano())
|
b := make([]byte, length)
|
||||||
key := make([]byte, 48)
|
maxI := big.NewInt(int64(len(keyChars)))
|
||||||
for i := 0; i < 16; i++ {
|
|
||||||
key[i] = keyChars[rand.Intn(len(keyChars))]
|
for i := range b {
|
||||||
}
|
n, err := crand.Int(crand.Reader, maxI)
|
||||||
uuid_ := GetUUID()
|
if err != nil {
|
||||||
for i := 0; i < 32; i++ {
|
return "", err
|
||||||
c := uuid_[i]
|
|
||||||
if i%2 == 0 && c >= 'a' && c <= 'z' {
|
|
||||||
c = c - 'a' + 'A'
|
|
||||||
}
|
}
|
||||||
key[i+16] = c
|
b[i] = keyChars[n.Int64()]
|
||||||
}
|
}
|
||||||
return string(key)
|
|
||||||
|
return string(b), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GenerateRandomKey(length int) (string, error) {
|
||||||
|
bytes := make([]byte, length*3/4) // 对于48位的输出,这里应该是36
|
||||||
|
if _, err := crand.Read(bytes); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return base64.StdEncoding.EncodeToString(bytes), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GenerateKey() (string, error) {
|
||||||
|
//rand.Seed(time.Now().UnixNano())
|
||||||
|
return GenerateRandomCharsKey(48)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRandomInt(max int) int {
|
func GetRandomInt(max int) int {
|
||||||
|
|||||||
35
constant/chat.go
Normal file
35
constant/chat.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package constant
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"one-api/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Chats = []map[string]string{
|
||||||
|
{
|
||||||
|
"ChatGPT Next Web 官方示例": "https://app.nextchat.dev/#/?settings={\"key\":\"{key}\",\"url\":\"{address}\"}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Lobe Chat 官方示例": "https://chat-preview.lobehub.com/?settings={\"keyVaults\":{\"openai\":{\"apiKey\":\"{key}\",\"baseURL\":\"{address}/v1\"}}}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"AMA 问天": "ama://set-api-key?server={address}&key={key}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"OpenCat": "opencat://team/join?domain={address}&token={key}",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateChatsByJsonString(jsonString string) error {
|
||||||
|
Chats = make([]map[string]string, 0)
|
||||||
|
return json.Unmarshal([]byte(jsonString), &Chats)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Chats2JsonString() string {
|
||||||
|
jsonBytes, err := json.Marshal(Chats)
|
||||||
|
if err != nil {
|
||||||
|
common.SysError("error marshalling chats: " + err.Error())
|
||||||
|
return "[]"
|
||||||
|
}
|
||||||
|
return string(jsonBytes)
|
||||||
|
}
|
||||||
@@ -20,14 +20,16 @@ var GetMediaTokenNotStream = common.GetEnvOrDefaultBool("GET_MEDIA_TOKEN_NOT_STR
|
|||||||
var UpdateTask = common.GetEnvOrDefaultBool("UPDATE_TASK", true)
|
var UpdateTask = common.GetEnvOrDefaultBool("UPDATE_TASK", true)
|
||||||
|
|
||||||
var GeminiModelMap = map[string]string{
|
var GeminiModelMap = map[string]string{
|
||||||
"gemini-1.5-pro-latest": "v1beta",
|
"gemini-1.5-pro-latest": "v1beta",
|
||||||
"gemini-1.5-pro-001": "v1beta",
|
"gemini-1.5-pro-001": "v1beta",
|
||||||
"gemini-1.5-pro": "v1beta",
|
"gemini-1.5-pro": "v1beta",
|
||||||
"gemini-1.5-pro-exp-0801": "v1beta",
|
"gemini-1.5-pro-exp-0801": "v1beta",
|
||||||
"gemini-1.5-flash-latest": "v1beta",
|
"gemini-1.5-pro-exp-0827": "v1beta",
|
||||||
"gemini-1.5-flash-001": "v1beta",
|
"gemini-1.5-flash-latest": "v1beta",
|
||||||
"gemini-1.5-flash": "v1beta",
|
"gemini-1.5-flash-exp-0827": "v1beta",
|
||||||
"gemini-ultra": "v1beta",
|
"gemini-1.5-flash-001": "v1beta",
|
||||||
|
"gemini-1.5-flash": "v1beta",
|
||||||
|
"gemini-ultra": "v1beta",
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitEnv() {
|
func InitEnv() {
|
||||||
@@ -44,3 +46,6 @@ func InitEnv() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否生成初始令牌,默认关闭。
|
||||||
|
var GenerateDefaultToken = common.GetEnvOrDefaultBool("GENERATE_DEFAULT_TOKEN", false)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"one-api/relay/constant"
|
"one-api/relay/constant"
|
||||||
"one-api/service"
|
"one-api/service"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -81,8 +82,7 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
|
|||||||
return fmt.Errorf("invalid api type: %d, adaptor is nil", apiType), nil
|
return fmt.Errorf("invalid api type: %d, adaptor is nil", apiType), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
request := buildTestRequest()
|
request := buildTestRequest(testModel)
|
||||||
request.Model = testModel
|
|
||||||
meta.UpstreamModelName = testModel
|
meta.UpstreamModelName = testModel
|
||||||
common.SysLog(fmt.Sprintf("testing channel %d with model %s", channel.Id, testModel))
|
common.SysLog(fmt.Sprintf("testing channel %d with model %s", channel.Id, testModel))
|
||||||
|
|
||||||
@@ -141,17 +141,22 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildTestRequest() *dto.GeneralOpenAIRequest {
|
func buildTestRequest(model string) *dto.GeneralOpenAIRequest {
|
||||||
testRequest := &dto.GeneralOpenAIRequest{
|
testRequest := &dto.GeneralOpenAIRequest{
|
||||||
Model: "", // this will be set later
|
Model: "", // this will be set later
|
||||||
MaxTokens: 1,
|
Stream: false,
|
||||||
Stream: false,
|
}
|
||||||
|
if "o1" == model || strings.HasPrefix(model, "o1-") {
|
||||||
|
testRequest.MaxCompletionTokens = 1
|
||||||
|
} else {
|
||||||
|
testRequest.MaxTokens = 1
|
||||||
}
|
}
|
||||||
content, _ := json.Marshal("hi")
|
content, _ := json.Marshal("hi")
|
||||||
testMessage := dto.Message{
|
testMessage := dto.Message{
|
||||||
Role: "user",
|
Role: "user",
|
||||||
Content: content,
|
Content: content,
|
||||||
}
|
}
|
||||||
|
testRequest.Model = model
|
||||||
testRequest.Messages = append(testRequest.Messages, testMessage)
|
testRequest.Messages = append(testRequest.Messages, testMessage)
|
||||||
return testRequest
|
return testRequest
|
||||||
}
|
}
|
||||||
@@ -226,26 +231,22 @@ func testAllChannels(notify bool) error {
|
|||||||
tok := time.Now()
|
tok := time.Now()
|
||||||
milliseconds := tok.Sub(tik).Milliseconds()
|
milliseconds := tok.Sub(tik).Milliseconds()
|
||||||
|
|
||||||
ban := false
|
shouldBanChannel := false
|
||||||
if milliseconds > disableThreshold {
|
|
||||||
err = errors.New(fmt.Sprintf("响应时间 %.2fs 超过阈值 %.2fs", float64(milliseconds)/1000.0, float64(disableThreshold)/1000.0))
|
|
||||||
ban = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// request error disables the channel
|
// request error disables the channel
|
||||||
if openaiWithStatusErr != nil {
|
if openaiWithStatusErr != nil {
|
||||||
oaiErr := openaiWithStatusErr.Error
|
oaiErr := openaiWithStatusErr.Error
|
||||||
err = errors.New(fmt.Sprintf("type %s, httpCode %d, code %v, message %s", oaiErr.Type, openaiWithStatusErr.StatusCode, oaiErr.Code, oaiErr.Message))
|
err = errors.New(fmt.Sprintf("type %s, httpCode %d, code %v, message %s", oaiErr.Type, openaiWithStatusErr.StatusCode, oaiErr.Code, oaiErr.Message))
|
||||||
ban = service.ShouldDisableChannel(channel.Type, openaiWithStatusErr)
|
shouldBanChannel = service.ShouldDisableChannel(channel.Type, openaiWithStatusErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse *int to bool
|
if milliseconds > disableThreshold {
|
||||||
if !channel.GetAutoBan() {
|
err = errors.New(fmt.Sprintf("响应时间 %.2fs 超过阈值 %.2fs", float64(milliseconds)/1000.0, float64(disableThreshold)/1000.0))
|
||||||
ban = false
|
shouldBanChannel = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable channel
|
// disable channel
|
||||||
if ban && isChannelEnabled {
|
if isChannelEnabled && shouldBanChannel && channel.GetAutoBan() {
|
||||||
service.DisableChannel(channel.Id, channel.Name, err.Error())
|
service.DisableChannel(channel.Id, channel.Name, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,9 @@ func GitHubOAuth(c *gin.Context) {
|
|||||||
user := model.User{
|
user := model.User{
|
||||||
GitHubId: githubUser.Login,
|
GitHubId: githubUser.Login,
|
||||||
}
|
}
|
||||||
|
// IsGitHubIdAlreadyTaken is unscoped
|
||||||
if model.IsGitHubIdAlreadyTaken(user.GitHubId) {
|
if model.IsGitHubIdAlreadyTaken(user.GitHubId) {
|
||||||
|
// FillUserByGitHubId is scoped
|
||||||
err := user.FillUserByGitHubId()
|
err := user.FillUserByGitHubId()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
@@ -121,6 +123,14 @@ func GitHubOAuth(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// if user.Id == 0 , user has been deleted
|
||||||
|
if user.Id == 0 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户已注销",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if common.RegisterEnabled {
|
if common.RegisterEnabled {
|
||||||
user.InviterId, _ = model.GetUserIdByAffCode(c.Query("aff"))
|
user.InviterId, _ = model.GetUserIdByAffCode(c.Query("aff"))
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
|
"one-api/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetGroups(c *gin.Context) {
|
func GetGroups(c *gin.Context) {
|
||||||
@@ -17,3 +18,22 @@ func GetGroups(c *gin.Context) {
|
|||||||
"data": groupNames,
|
"data": groupNames,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetUserGroups(c *gin.Context) {
|
||||||
|
usableGroups := make(map[string]string)
|
||||||
|
userGroup := ""
|
||||||
|
userId := c.GetInt("id")
|
||||||
|
userGroup, _ = model.CacheGetUserGroup(userId)
|
||||||
|
for groupName, _ := range common.GroupRatio {
|
||||||
|
// UserUsableGroups contains the groups that the user can use
|
||||||
|
userUsableGroups := common.GetUserUsableGroups(userGroup)
|
||||||
|
if _, ok := userUsableGroups[groupName]; ok {
|
||||||
|
usableGroups[groupName] = userUsableGroups[groupName]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": true,
|
||||||
|
"message": "",
|
||||||
|
"data": usableGroups,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -132,6 +132,14 @@ func LinuxDoOAuth(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.Id == 0 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户已注销",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
user.LinuxDoLevel = linuxdoUser.TrustLevel
|
user.LinuxDoLevel = linuxdoUser.TrustLevel
|
||||||
err = user.Update(false)
|
err = user.Update(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ func DeleteHistoryLogs(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
count, err := model.DeleteOldLog(targetTimestamp)
|
count, err := model.DeleteOldLog(c.Request.Context(), targetTimestamp, 100)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ func GetStatus(c *gin.Context) {
|
|||||||
"default_collapse_sidebar": common.DefaultCollapseSidebar,
|
"default_collapse_sidebar": common.DefaultCollapseSidebar,
|
||||||
"payment_enabled": common.PaymentEnabled,
|
"payment_enabled": common.PaymentEnabled,
|
||||||
"mj_notify_enabled": constant.MjNotifyEnabled,
|
"mj_notify_enabled": constant.MjNotifyEnabled,
|
||||||
|
"chats": constant.Chats,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -137,31 +137,63 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ListModels(c *gin.Context) {
|
func ListModels(c *gin.Context) {
|
||||||
userId := c.GetInt("id")
|
|
||||||
user, err := model.GetUserById(userId, true)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
|
||||||
"success": false,
|
|
||||||
"message": err.Error(),
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
models := model.GetGroupModels(user.Group)
|
|
||||||
userOpenAiModels := make([]dto.OpenAIModels, 0)
|
userOpenAiModels := make([]dto.OpenAIModels, 0)
|
||||||
permission := getPermission()
|
permission := getPermission()
|
||||||
for _, s := range models {
|
|
||||||
if _, ok := openAIModelsMap[s]; ok {
|
modelLimitEnable := c.GetBool("token_model_limit_enabled")
|
||||||
userOpenAiModels = append(userOpenAiModels, openAIModelsMap[s])
|
if modelLimitEnable {
|
||||||
|
s, ok := c.Get("token_model_limit")
|
||||||
|
var tokenModelLimit map[string]bool
|
||||||
|
if ok {
|
||||||
|
tokenModelLimit = s.(map[string]bool)
|
||||||
} else {
|
} else {
|
||||||
userOpenAiModels = append(userOpenAiModels, dto.OpenAIModels{
|
tokenModelLimit = map[string]bool{}
|
||||||
Id: s,
|
}
|
||||||
Object: "model",
|
for allowModel, _ := range tokenModelLimit {
|
||||||
Created: 1626777600,
|
if _, ok := openAIModelsMap[allowModel]; ok {
|
||||||
OwnedBy: "custom",
|
userOpenAiModels = append(userOpenAiModels, openAIModelsMap[allowModel])
|
||||||
Permission: permission,
|
} else {
|
||||||
Root: s,
|
userOpenAiModels = append(userOpenAiModels, dto.OpenAIModels{
|
||||||
Parent: nil,
|
Id: allowModel,
|
||||||
|
Object: "model",
|
||||||
|
Created: 1626777600,
|
||||||
|
OwnedBy: "custom",
|
||||||
|
Permission: permission,
|
||||||
|
Root: allowModel,
|
||||||
|
Parent: nil,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
userId := c.GetInt("id")
|
||||||
|
userGroup, err := model.GetUserGroup(userId)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "get user group failed",
|
||||||
})
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
group := userGroup
|
||||||
|
tokenGroup := c.GetString("token_group")
|
||||||
|
if tokenGroup != "" {
|
||||||
|
group = tokenGroup
|
||||||
|
}
|
||||||
|
models := model.GetGroupModels(group)
|
||||||
|
for _, s := range models {
|
||||||
|
if _, ok := openAIModelsMap[s]; ok {
|
||||||
|
userOpenAiModels = append(userOpenAiModels, openAIModelsMap[s])
|
||||||
|
} else {
|
||||||
|
userOpenAiModels = append(userOpenAiModels, dto.OpenAIModels{
|
||||||
|
Id: s,
|
||||||
|
Object: "model",
|
||||||
|
Created: 1626777600,
|
||||||
|
OwnedBy: "custom",
|
||||||
|
Permission: permission,
|
||||||
|
Root: s,
|
||||||
|
Parent: nil,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
|
|||||||
@@ -7,18 +7,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetPricing(c *gin.Context) {
|
func GetPricing(c *gin.Context) {
|
||||||
userId := c.GetInt("id")
|
pricing := model.GetPricing()
|
||||||
// if no login, get default group ratio
|
|
||||||
groupRatio := common.GetGroupRatio("default")
|
|
||||||
group, err := model.CacheGetUserGroup(userId)
|
|
||||||
if err == nil {
|
|
||||||
groupRatio = common.GetGroupRatio(group)
|
|
||||||
}
|
|
||||||
pricing := model.GetPricing(group)
|
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
"data": pricing,
|
"data": pricing,
|
||||||
"group_ratio": groupRatio,
|
"group_ratio": common.GroupRatio,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,58 @@ func relayHandler(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Playground(c *gin.Context) {
|
||||||
|
var openaiErr *dto.OpenAIErrorWithStatusCode
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if openaiErr != nil {
|
||||||
|
c.JSON(openaiErr.StatusCode, gin.H{
|
||||||
|
"error": openaiErr.Error,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
useAccessToken := c.GetBool("use_access_token")
|
||||||
|
if useAccessToken {
|
||||||
|
openaiErr = service.OpenAIErrorWrapperLocal(errors.New("暂不支持使用 access token"), "access_token_not_supported", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
playgroundRequest := &dto.PlayGroundRequest{}
|
||||||
|
err := common.UnmarshalBodyReusable(c, playgroundRequest)
|
||||||
|
if err != nil {
|
||||||
|
openaiErr = service.OpenAIErrorWrapperLocal(err, "unmarshal_request_failed", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if playgroundRequest.Model == "" {
|
||||||
|
openaiErr = service.OpenAIErrorWrapperLocal(errors.New("请选择模型"), "model_required", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Set("original_model", playgroundRequest.Model)
|
||||||
|
group := playgroundRequest.Group
|
||||||
|
userGroup := c.GetString("group")
|
||||||
|
|
||||||
|
if group == "" {
|
||||||
|
group = userGroup
|
||||||
|
} else {
|
||||||
|
if !common.GroupInUserUsableGroups(group) && group != userGroup {
|
||||||
|
openaiErr = service.OpenAIErrorWrapperLocal(errors.New("无权访问该分组"), "group_not_allowed", http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Set("group", group)
|
||||||
|
}
|
||||||
|
c.Set("token_name", "playground-"+group)
|
||||||
|
channel, err := model.CacheGetRandomSatisfiedChannel(group, playgroundRequest.Model, 0)
|
||||||
|
if err != nil {
|
||||||
|
message := fmt.Sprintf("当前分组 %s 下对于模型 %s 无可用渠道", group, playgroundRequest.Model)
|
||||||
|
openaiErr = service.OpenAIErrorWrapperLocal(errors.New(message), "get_playground_channel_failed", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
middleware.SetupContextForSelectedChannel(c, channel, playgroundRequest.Model)
|
||||||
|
Relay(c)
|
||||||
|
}
|
||||||
|
|
||||||
func Relay(c *gin.Context) {
|
func Relay(c *gin.Context) {
|
||||||
relayMode := constant.Path2RelayMode(c.Request.URL.Path)
|
relayMode := constant.Path2RelayMode(c.Request.URL.Path)
|
||||||
requestId := c.GetString(common.RequestIdKey)
|
requestId := c.GetString(common.RequestIdKey)
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/stripe/stripe-go/v76"
|
"github.com/stripe/stripe-go/v79"
|
||||||
"github.com/stripe/stripe-go/v76/webhook"
|
"github.com/stripe/stripe-go/v79/webhook"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -23,7 +23,9 @@ func StripeWebhook(c *gin.Context) {
|
|||||||
|
|
||||||
signature := c.GetHeader("Stripe-Signature")
|
signature := c.GetHeader("Stripe-Signature")
|
||||||
endpointSecret := common.StripeWebhookSecret
|
endpointSecret := common.StripeWebhookSecret
|
||||||
event, err := webhook.ConstructEvent(payload, signature, endpointSecret)
|
event, err := webhook.ConstructEventWithOptions(payload, signature, endpointSecret, webhook.ConstructEventOptions{
|
||||||
|
IgnoreAPIVersionMismatch: true,
|
||||||
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Stripe Webhook验签失败: %v\n", err)
|
log.Printf("Stripe Webhook验签失败: %v\n", err)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -48,6 +49,13 @@ func TelegramBind(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if user.Id == 0 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户已注销",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
user.TelegramId = telegramId
|
user.TelegramId = telegramId
|
||||||
if err := user.Update(false); err != nil {
|
if err := user.Update(false); err != nil {
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
|
|||||||
@@ -123,10 +123,19 @@ func AddToken(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
key, err := common.GenerateKey()
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "生成令牌失败",
|
||||||
|
})
|
||||||
|
common.SysError("failed to generate token key: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
cleanToken := model.Token{
|
cleanToken := model.Token{
|
||||||
UserId: c.GetInt("id"),
|
UserId: c.GetInt("id"),
|
||||||
Name: token.Name,
|
Name: token.Name,
|
||||||
Key: common.GenerateKey(),
|
Key: key,
|
||||||
CreatedTime: common.GetTimestamp(),
|
CreatedTime: common.GetTimestamp(),
|
||||||
AccessedTime: common.GetTimestamp(),
|
AccessedTime: common.GetTimestamp(),
|
||||||
ExpiredTime: token.ExpiredTime,
|
ExpiredTime: token.ExpiredTime,
|
||||||
@@ -134,6 +143,8 @@ func AddToken(c *gin.Context) {
|
|||||||
UnlimitedQuota: token.UnlimitedQuota,
|
UnlimitedQuota: token.UnlimitedQuota,
|
||||||
ModelLimitsEnabled: token.ModelLimitsEnabled,
|
ModelLimitsEnabled: token.ModelLimitsEnabled,
|
||||||
ModelLimits: token.ModelLimits,
|
ModelLimits: token.ModelLimits,
|
||||||
|
AllowIps: token.AllowIps,
|
||||||
|
Group: token.Group,
|
||||||
}
|
}
|
||||||
err = cleanToken.Insert()
|
err = cleanToken.Insert()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -221,6 +232,8 @@ func UpdateToken(c *gin.Context) {
|
|||||||
cleanToken.UnlimitedQuota = token.UnlimitedQuota
|
cleanToken.UnlimitedQuota = token.UnlimitedQuota
|
||||||
cleanToken.ModelLimitsEnabled = token.ModelLimitsEnabled
|
cleanToken.ModelLimitsEnabled = token.ModelLimitsEnabled
|
||||||
cleanToken.ModelLimits = token.ModelLimits
|
cleanToken.ModelLimits = token.ModelLimits
|
||||||
|
cleanToken.AllowIps = token.AllowIps
|
||||||
|
cleanToken.Group = token.Group
|
||||||
}
|
}
|
||||||
err = cleanToken.Update()
|
err = cleanToken.Update()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import "C"
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/stripe/stripe-go/v76"
|
"github.com/stripe/stripe-go/v79"
|
||||||
"github.com/stripe/stripe-go/v76/checkout/session"
|
"github.com/stripe/stripe-go/v79/checkout/session"
|
||||||
"log"
|
"log"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ import (
|
|||||||
"one-api/common"
|
"one-api/common"
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/gin-contrib/sessions"
|
"github.com/gin-contrib/sessions"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"one-api/constant"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LoginRequest struct {
|
type LoginRequest struct {
|
||||||
@@ -66,6 +68,7 @@ func setupLogin(user *model.User, c *gin.Context) {
|
|||||||
session.Set("username", user.Username)
|
session.Set("username", user.Username)
|
||||||
session.Set("role", user.Role)
|
session.Set("role", user.Role)
|
||||||
session.Set("status", user.Status)
|
session.Set("status", user.Status)
|
||||||
|
session.Set("group", user.Group)
|
||||||
session.Set("linuxdo_enable", user.LinuxDoId == "" || user.LinuxDoLevel >= common.LinuxDoMinLevel)
|
session.Set("linuxdo_enable", user.LinuxDoId == "" || user.LinuxDoLevel >= common.LinuxDoMinLevel)
|
||||||
err := session.Save()
|
err := session.Save()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -158,8 +161,9 @@ func Register(c *gin.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": err.Error(),
|
"message": "数据库错误,请稍后重试",
|
||||||
})
|
})
|
||||||
|
common.SysError(fmt.Sprintf("CheckUserExistOrDeleted error: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if exist {
|
if exist {
|
||||||
@@ -187,6 +191,48 @@ func Register(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取插入后的用户ID
|
||||||
|
var insertedUser model.User
|
||||||
|
if err := model.DB.Where("username = ?", cleanUser.Username).First(&insertedUser).Error; err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户注册失败或用户ID获取失败",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 生成默认令牌
|
||||||
|
if constant.GenerateDefaultToken {
|
||||||
|
key, err := common.GenerateKey()
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "生成默认令牌失败",
|
||||||
|
})
|
||||||
|
common.SysError("failed to generate token key: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 生成默认令牌
|
||||||
|
token := model.Token{
|
||||||
|
UserId: insertedUser.Id, // 使用插入后的用户ID
|
||||||
|
Name: cleanUser.Username + "的初始令牌",
|
||||||
|
Key: key,
|
||||||
|
CreatedTime: common.GetTimestamp(),
|
||||||
|
AccessedTime: common.GetTimestamp(),
|
||||||
|
ExpiredTime: -1, // 永不过期
|
||||||
|
RemainQuota: 500000, // 示例额度
|
||||||
|
UnlimitedQuota: true,
|
||||||
|
ModelLimitsEnabled: false,
|
||||||
|
}
|
||||||
|
if err := token.Insert(); err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "创建默认令牌失败",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
"message": "",
|
"message": "",
|
||||||
@@ -277,7 +323,18 @@ func GenerateAccessToken(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user.AccessToken = common.GetUUID()
|
// get rand int 28-32
|
||||||
|
randI := common.GetRandomInt(4)
|
||||||
|
key, err := common.GenerateRandomKey(29 + randI)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "生成失败",
|
||||||
|
})
|
||||||
|
common.SysError("failed to generate key: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user.SetAccessToken(key)
|
||||||
|
|
||||||
if model.DB.Where("access_token = ?", user.AccessToken).First(user).RowsAffected != 0 {
|
if model.DB.Where("access_token = ?", user.AccessToken).First(user).RowsAffected != 0 {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
@@ -597,6 +654,7 @@ func DeleteSelf(c *gin.Context) {
|
|||||||
func CreateUser(c *gin.Context) {
|
func CreateUser(c *gin.Context) {
|
||||||
var user model.User
|
var user model.User
|
||||||
err := json.NewDecoder(c.Request.Body).Decode(&user)
|
err := json.NewDecoder(c.Request.Body).Decode(&user)
|
||||||
|
user.Username = strings.TrimSpace(user.Username)
|
||||||
if err != nil || user.Username == "" || user.Password == "" {
|
if err != nil || user.Username == "" || user.Password == "" {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
@@ -644,8 +702,8 @@ func CreateUser(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ManageRequest struct {
|
type ManageRequest struct {
|
||||||
Username string `json:"username"`
|
Id int `json:"id"`
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ManageUser Only admin user can do this
|
// ManageUser Only admin user can do this
|
||||||
@@ -661,7 +719,7 @@ func ManageUser(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
user := model.User{
|
user := model.User{
|
||||||
Username: req.Username,
|
Id: req.Id,
|
||||||
}
|
}
|
||||||
// Fill attributes
|
// Fill attributes
|
||||||
model.DB.Unscoped().Where(&user).First(&user)
|
model.DB.Unscoped().Where(&user).First(&user)
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ func WeChatAuth(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if user.Id == 0 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户已注销",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if common.RegisterEnabled {
|
if common.RegisterEnabled {
|
||||||
user.Username = "wechat_" + strconv.Itoa(model.GetMaxUserId()+1)
|
user.Username = "wechat_" + strconv.Itoa(model.GetMaxUserId()+1)
|
||||||
|
|||||||
6
dto/playground.go
Normal file
6
dto/playground.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
type PlayGroundRequest struct {
|
||||||
|
Model string `json:"model,omitempty"`
|
||||||
|
Group string `json:"group,omitempty"`
|
||||||
|
}
|
||||||
@@ -3,37 +3,46 @@ package dto
|
|||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
|
|
||||||
type GeneralOpenAIRequest struct {
|
type GeneralOpenAIRequest struct {
|
||||||
Model string `json:"model,omitempty"`
|
Model string `json:"model,omitempty"`
|
||||||
Messages []Message `json:"messages,omitempty"`
|
ReasoningEffort string `json:"reasoning_effort,omitempty"`
|
||||||
Prompt any `json:"prompt,omitempty"`
|
Messages []Message `json:"messages,omitempty"`
|
||||||
BestOf int `json:"best_of,omitempty"`
|
Prompt any `json:"prompt,omitempty"`
|
||||||
Echo bool `json:"echo,omitempty"`
|
BestOf int `json:"best_of,omitempty"`
|
||||||
Stream bool `json:"stream,omitempty"`
|
Echo bool `json:"echo,omitempty"`
|
||||||
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
|
Stream bool `json:"stream,omitempty"`
|
||||||
Suffix string `json:"suffix,omitempty"`
|
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
|
||||||
MaxTokens uint `json:"max_tokens,omitempty"`
|
Suffix string `json:"suffix,omitempty"`
|
||||||
Temperature float64 `json:"temperature,omitempty"`
|
MaxTokens uint `json:"max_tokens,omitempty"`
|
||||||
TopP float64 `json:"top_p,omitempty"`
|
MaxCompletionTokens uint `json:"max_completion_tokens,omitempty"`
|
||||||
TopK int `json:"top_k,omitempty"`
|
Temperature float64 `json:"temperature,omitempty"`
|
||||||
Stop any `json:"stop,omitempty"`
|
TopP float64 `json:"top_p,omitempty"`
|
||||||
N int `json:"n,omitempty"`
|
TopK int `json:"top_k,omitempty"`
|
||||||
Input any `json:"input,omitempty"`
|
Stop any `json:"stop,omitempty"`
|
||||||
Instruction string `json:"instruction,omitempty"`
|
N int `json:"n,omitempty"`
|
||||||
Size string `json:"size,omitempty"`
|
Input any `json:"input,omitempty"`
|
||||||
Functions any `json:"functions,omitempty"`
|
Instruction string `json:"instruction,omitempty"`
|
||||||
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
|
Size string `json:"size,omitempty"`
|
||||||
PresencePenalty float64 `json:"presence_penalty,omitempty"`
|
Functions any `json:"functions,omitempty"`
|
||||||
ResponseFormat any `json:"response_format,omitempty"`
|
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
|
||||||
Seed float64 `json:"seed,omitempty"`
|
PresencePenalty float64 `json:"presence_penalty,omitempty"`
|
||||||
Tools []ToolCall `json:"tools,omitempty"`
|
ResponseFormat any `json:"response_format,omitempty"`
|
||||||
ToolChoice any `json:"tool_choice,omitempty"`
|
Seed float64 `json:"seed,omitempty"`
|
||||||
User string `json:"user,omitempty"`
|
Tools []ToolCall `json:"tools,omitempty"`
|
||||||
LogitBias any `json:"logit_bias,omitempty"`
|
ToolChoice any `json:"tool_choice,omitempty"`
|
||||||
LogProbs any `json:"logprobs,omitempty"`
|
User string `json:"user,omitempty"`
|
||||||
TopLogProbs int `json:"top_logprobs,omitempty"`
|
LogitBias any `json:"logit_bias,omitempty"`
|
||||||
Dimensions int `json:"dimensions,omitempty"`
|
LogProbs any `json:"logprobs,omitempty"`
|
||||||
ParallelToolCalls bool `json:"parallel_Tool_Calls,omitempty"`
|
TopLogProbs int `json:"top_logprobs,omitempty"`
|
||||||
EncodingFormat string `json:"encoding_format,omitempty"`
|
Dimensions int `json:"dimensions,omitempty"`
|
||||||
|
ParallelToolCalls bool `json:"parallel_tool_calls,omitempty"`
|
||||||
|
EncodingFormat any `json:"encoding_format,omitempty"`
|
||||||
|
|
||||||
|
Thinking *Thinking `json:"thinking,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Thinking struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
BudgetTokens int `json:"budget_tokens"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenAITools struct {
|
type OpenAITools struct {
|
||||||
@@ -75,11 +84,12 @@ func (r GeneralOpenAIRequest) ParseInput() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content json.RawMessage `json:"content"`
|
Content json.RawMessage `json:"content"`
|
||||||
Name *string `json:"name,omitempty"`
|
ReasoningContent *string `json:"reasoning_content,omitempty"`
|
||||||
ToolCalls any `json:"tool_calls,omitempty"`
|
Name *string `json:"name,omitempty"`
|
||||||
ToolCallId string `json:"tool_call_id,omitempty"`
|
ToolCalls any `json:"tool_calls,omitempty"`
|
||||||
|
ToolCallId string `json:"tool_call_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MediaMessage struct {
|
type MediaMessage struct {
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ type OpenAITextResponseChoice struct {
|
|||||||
|
|
||||||
type OpenAITextResponse struct {
|
type OpenAITextResponse struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
|
Model string `json:"model"`
|
||||||
Object string `json:"object"`
|
Object string `json:"object"`
|
||||||
Created int64 `json:"created"`
|
Created int64 `json:"created"`
|
||||||
Choices []OpenAITextResponseChoice `json:"choices"`
|
Choices []OpenAITextResponseChoice `json:"choices"`
|
||||||
@@ -61,9 +62,10 @@ type ChatCompletionsStreamResponseChoice struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ChatCompletionsStreamResponseChoiceDelta struct {
|
type ChatCompletionsStreamResponseChoiceDelta struct {
|
||||||
Content *string `json:"content,omitempty"`
|
Content *string `json:"content,omitempty"`
|
||||||
Role string `json:"role,omitempty"`
|
ReasoningContent *string `json:"reasoning_content,omitempty"`
|
||||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
Role string `json:"role,omitempty"`
|
||||||
|
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ChatCompletionsStreamResponseChoiceDelta) SetContentString(s string) {
|
func (c *ChatCompletionsStreamResponseChoiceDelta) SetContentString(s string) {
|
||||||
|
|||||||
31
go.mod
31
go.mod
@@ -3,15 +3,13 @@ module one-api
|
|||||||
// +heroku goVersion go1.18
|
// +heroku goVersion go1.18
|
||||||
go 1.21
|
go 1.21
|
||||||
|
|
||||||
toolchain go1.22.4
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/anknown/ahocorasick v0.0.0-20190904063843-d75dbd5169c0
|
github.com/anknown/ahocorasick v0.0.0-20190904063843-d75dbd5169c0
|
||||||
github.com/aws/aws-sdk-go-v2 v1.26.1
|
github.com/aws/aws-sdk-go-v2 v1.26.1
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.11
|
github.com/aws/aws-sdk-go-v2/credentials v1.17.11
|
||||||
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.7.4
|
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.7.4
|
||||||
github.com/bytedance/gopkg v0.0.0-20220118071334-3db87571198b
|
github.com/bytedance/gopkg v0.0.0-20220118071334-3db87571198b
|
||||||
github.com/gin-contrib/cors v1.4.0
|
github.com/gin-contrib/cors v1.6.0
|
||||||
github.com/gin-contrib/gzip v0.0.6
|
github.com/gin-contrib/gzip v0.0.6
|
||||||
github.com/gin-contrib/sessions v0.0.5
|
github.com/gin-contrib/sessions v0.0.5
|
||||||
github.com/gin-contrib/static v0.0.1
|
github.com/gin-contrib/static v0.0.1
|
||||||
@@ -26,10 +24,10 @@ require (
|
|||||||
github.com/pkoukk/tiktoken-go v0.1.7
|
github.com/pkoukk/tiktoken-go v0.1.7
|
||||||
github.com/samber/lo v1.39.0
|
github.com/samber/lo v1.39.0
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||||
github.com/stripe/stripe-go/v76 v76.21.0
|
github.com/stripe/stripe-go/v79 v79.12.0
|
||||||
golang.org/x/crypto v0.26.0
|
golang.org/x/crypto v0.31.0
|
||||||
golang.org/x/image v0.15.0
|
golang.org/x/image v0.18.0
|
||||||
golang.org/x/net v0.28.0
|
golang.org/x/net v0.33.0
|
||||||
gorm.io/driver/mysql v1.4.3
|
gorm.io/driver/mysql v1.4.3
|
||||||
gorm.io/driver/postgres v1.5.2
|
gorm.io/driver/postgres v1.5.2
|
||||||
gorm.io/driver/sqlite v1.4.3
|
gorm.io/driver/sqlite v1.4.3
|
||||||
@@ -42,9 +40,10 @@ require (
|
|||||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
|
||||||
github.com/aws/smithy-go v1.20.2 // indirect
|
github.com/aws/smithy-go v1.20.2 // indirect
|
||||||
github.com/bytedance/sonic v1.9.1 // indirect
|
github.com/bytedance/sonic v1.11.2 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||||
|
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/dlclark/regexp2 v1.11.0 // indirect
|
github.com/dlclark/regexp2 v1.11.0 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||||
@@ -65,24 +64,24 @@ require (
|
|||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
|
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
|
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
||||||
github.com/stretchr/testify v1.9.0 // indirect
|
github.com/stretchr/testify v1.9.0 // indirect
|
||||||
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
||||||
github.com/tklauser/numcpus v0.6.1 // indirect
|
github.com/tklauser/numcpus v0.6.1 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||||
github.com/yusufpapurcu/wmi v1.2.3 // indirect
|
github.com/yusufpapurcu/wmi v1.2.3 // indirect
|
||||||
golang.org/x/arch v0.3.0 // indirect
|
golang.org/x/arch v0.7.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
|
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
|
||||||
golang.org/x/sync v0.8.0 // indirect
|
golang.org/x/sync v0.10.0 // indirect
|
||||||
golang.org/x/sys v0.24.0 // indirect
|
golang.org/x/sys v0.28.0 // indirect
|
||||||
golang.org/x/text v0.17.0 // indirect
|
golang.org/x/text v0.21.0 // indirect
|
||||||
google.golang.org/protobuf v1.34.2 // indirect
|
google.golang.org/protobuf v1.34.2 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
65
go.sum
65
go.sum
@@ -19,13 +19,18 @@ github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC
|
|||||||
github.com/bytedance/gopkg v0.0.0-20220118071334-3db87571198b h1:LTGVFpNmNHhj0vhOlfgWueFJ32eK9blaIlHR2ciXOT0=
|
github.com/bytedance/gopkg v0.0.0-20220118071334-3db87571198b h1:LTGVFpNmNHhj0vhOlfgWueFJ32eK9blaIlHR2ciXOT0=
|
||||||
github.com/bytedance/gopkg v0.0.0-20220118071334-3db87571198b/go.mod h1:2ZlV9BaUH4+NXIBF0aMdKKAnHTzqH+iMU4KUjAbL23Q=
|
github.com/bytedance/gopkg v0.0.0-20220118071334-3db87571198b/go.mod h1:2ZlV9BaUH4+NXIBF0aMdKKAnHTzqH+iMU4KUjAbL23Q=
|
||||||
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
|
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
|
||||||
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
|
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
|
||||||
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
|
github.com/bytedance/sonic v1.11.2 h1:ywfwo0a/3j9HR8wsYGWsIWl2mvRsI950HyoxiBERw5A=
|
||||||
|
github.com/bytedance/sonic v1.11.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
|
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
|
||||||
|
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
||||||
|
github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0=
|
||||||
|
github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
@@ -38,8 +43,8 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo
|
|||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||||
github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g=
|
github.com/gin-contrib/cors v1.6.0 h1:0Z7D/bVhE6ja07lI8CTjTonp6SB07o8bNuFyRbsBUQg=
|
||||||
github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs=
|
github.com/gin-contrib/cors v1.6.0/go.mod h1:cI+h6iOAyxKRtUtC6iF/Si1KSFvGm/gK+kshxlCi8ro=
|
||||||
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
|
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
|
||||||
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
|
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
|
||||||
github.com/gin-contrib/sessions v0.0.5 h1:CATtfHmLMQrMNpJRgzjWXD7worTh7g7ritsQfmF+0jE=
|
github.com/gin-contrib/sessions v0.0.5 h1:CATtfHmLMQrMNpJRgzjWXD7worTh7g7ritsQfmF+0jE=
|
||||||
@@ -113,8 +118,9 @@ github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
|
|||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
|
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
|
||||||
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||||
|
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||||
@@ -147,8 +153,8 @@ github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042
|
|||||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||||
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
|
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
|
||||||
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
|
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
|
||||||
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
|
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
@@ -173,11 +179,11 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/stripe/stripe-go/v76 v76.21.0 h1:O3GHImHS4oUI3qWMOClHN3zAQF5/oswS/NB7leV1fsU=
|
github.com/stripe/stripe-go/v79 v79.12.0 h1:HQs/kxNEB3gYA7FnkSFkp0kSOeez0fsmCWev6SxftYs=
|
||||||
github.com/stripe/stripe-go/v76 v76.21.0/go.mod h1:rw1MxjlAKKcZ+3FOXgTHgwiOa2ya6CPq6ykpJ0Q6Po4=
|
github.com/stripe/stripe-go/v79 v79.12.0/go.mod h1:cuH6X0zC8peY6f1AubHwgJ/fJSn2dh5pfiCr6CjyKVU=
|
||||||
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
|
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
|
||||||
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
||||||
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
|
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
|
||||||
@@ -188,27 +194,27 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
|
|||||||
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
|
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
|
||||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||||
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
|
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
|
||||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
||||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||||
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
|
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
|
||||||
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
|
||||||
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
||||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||||
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 h1:985EYyeCOxTpcgOTJpflJUwOeEz0CQOdPt73OzpE9F8=
|
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 h1:985EYyeCOxTpcgOTJpflJUwOeEz0CQOdPt73OzpE9F8=
|
||||||
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
|
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
|
||||||
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
|
golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ=
|
||||||
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
|
golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
|
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
||||||
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
|
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/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.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
||||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -217,18 +223,18 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/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.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
|
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
||||||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||||
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
@@ -260,4 +266,5 @@ gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
|
|||||||
gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
|
gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
|
||||||
gorm.io/gorm v1.25.0 h1:+KtYtb2roDz14EQe4bla8CbQlmb9dN3VejSai3lprfU=
|
gorm.io/gorm v1.25.0 h1:+KtYtb2roDz14EQe4bla8CbQlmb9dN3VejSai3lprfU=
|
||||||
gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
|
gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
|
||||||
|
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
||||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||||
|
|||||||
@@ -10,6 +10,17 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func validUserInfo(username string, role int) bool {
|
||||||
|
// check username is empty
|
||||||
|
if strings.TrimSpace(username) == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !common.IsValidateRole(role) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func authHelper(c *gin.Context, minRole int) {
|
func authHelper(c *gin.Context, minRole int) {
|
||||||
session := sessions.Default(c)
|
session := sessions.Default(c)
|
||||||
username := session.Get("username")
|
username := session.Get("username")
|
||||||
@@ -31,6 +42,14 @@ func authHelper(c *gin.Context, minRole int) {
|
|||||||
}
|
}
|
||||||
user := model.ValidateAccessToken(accessToken)
|
user := model.ValidateAccessToken(accessToken)
|
||||||
if user != nil && user.Username != "" {
|
if user != nil && user.Username != "" {
|
||||||
|
if !validUserInfo(user.Username, user.Role) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "无权进行此操作,用户信息无效",
|
||||||
|
})
|
||||||
|
c.Abort()
|
||||||
|
return
|
||||||
|
}
|
||||||
// Token is valid
|
// Token is valid
|
||||||
username = user.Username
|
username = user.Username
|
||||||
role = user.Role
|
role = user.Role
|
||||||
@@ -101,9 +120,19 @@ func authHelper(c *gin.Context, minRole int) {
|
|||||||
c.Abort()
|
c.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !validUserInfo(username.(string), role.(int)) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "无权进行此操作,用户信息无效",
|
||||||
|
})
|
||||||
|
c.Abort()
|
||||||
|
return
|
||||||
|
}
|
||||||
c.Set("username", username)
|
c.Set("username", username)
|
||||||
c.Set("role", role)
|
c.Set("role", role)
|
||||||
c.Set("id", id)
|
c.Set("id", id)
|
||||||
|
c.Set("group", session.Get("group"))
|
||||||
|
c.Set("use_access_token", useAccessToken)
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +223,8 @@ func TokenAuth() func(c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
c.Set("token_model_limit_enabled", false)
|
c.Set("token_model_limit_enabled", false)
|
||||||
}
|
}
|
||||||
|
c.Set("allow_ips", token.GetIpLimitsMap())
|
||||||
|
c.Set("token_group", token.Group)
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
if model.IsAdmin(token.UserId) {
|
if model.IsAdmin(token.UserId) {
|
||||||
c.Set("specific_channel_id", parts[1])
|
c.Set("specific_channel_id", parts[1])
|
||||||
|
|||||||
@@ -22,6 +22,14 @@ type ModelRequest struct {
|
|||||||
|
|
||||||
func Distribute() func(c *gin.Context) {
|
func Distribute() func(c *gin.Context) {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
allowIpsMap := c.GetStringMap("allow_ips")
|
||||||
|
if len(allowIpsMap) != 0 {
|
||||||
|
clientIp := c.ClientIP()
|
||||||
|
if _, ok := allowIpsMap[clientIp]; !ok {
|
||||||
|
abortWithOpenAiMessage(c, http.StatusForbidden, "您的 IP 不在令牌允许访问的列表中")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
userId := c.GetInt("id")
|
userId := c.GetInt("id")
|
||||||
var channel *model.Channel
|
var channel *model.Channel
|
||||||
channelId, ok := c.Get("specific_channel_id")
|
channelId, ok := c.Get("specific_channel_id")
|
||||||
@@ -31,6 +39,20 @@ func Distribute() func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
userGroup, _ := model.CacheGetUserGroup(userId)
|
userGroup, _ := model.CacheGetUserGroup(userId)
|
||||||
|
tokenGroup := c.GetString("token_group")
|
||||||
|
if tokenGroup != "" {
|
||||||
|
// check common.UserUsableGroups[userGroup]
|
||||||
|
if _, ok := common.GetUserUsableGroups(userGroup)[tokenGroup]; !ok {
|
||||||
|
abortWithOpenAiMessage(c, http.StatusForbidden, fmt.Sprintf("令牌分组 %s 已被禁用", tokenGroup))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// check group in common.GroupRatio
|
||||||
|
if _, ok := common.GroupRatio[tokenGroup]; !ok {
|
||||||
|
abortWithOpenAiMessage(c, http.StatusForbidden, fmt.Sprintf("分组 %s 已被弃用", tokenGroup))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userGroup = tokenGroup
|
||||||
|
}
|
||||||
c.Set("group", userGroup)
|
c.Set("group", userGroup)
|
||||||
if ok {
|
if ok {
|
||||||
id, err := strconv.Atoi(channelId.(string))
|
id, err := strconv.Atoi(channelId.(string))
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ func GetEnabledModels() []string {
|
|||||||
return models
|
return models
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetAllEnableAbilities() []Ability {
|
||||||
|
var abilities []Ability
|
||||||
|
DB.Find(&abilities, "enabled = ?", true)
|
||||||
|
return abilities
|
||||||
|
}
|
||||||
|
|
||||||
func getPriority(group string, model string, retry int) (int, error) {
|
func getPriority(group string, model string, retry int) (int, error) {
|
||||||
groupCol := "`group`"
|
groupCol := "`group`"
|
||||||
trueVal := "1"
|
trueVal := "1"
|
||||||
|
|||||||
24
model/log.go
24
model/log.go
@@ -247,7 +247,25 @@ func SumUsedToken(logType int, startTimestamp int64, endTimestamp int64, modelNa
|
|||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteOldLog(targetTimestamp int64) (int64, error) {
|
func DeleteOldLog(ctx context.Context, targetTimestamp int64, limit int) (int64, error) {
|
||||||
result := LOG_DB.Where("created_at < ?", targetTimestamp).Delete(&Log{})
|
var total int64 = 0
|
||||||
return result.RowsAffected, result.Error
|
|
||||||
|
for {
|
||||||
|
if nil != ctx.Err() {
|
||||||
|
return total, ctx.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
result := LOG_DB.Where("created_at < ?", targetTimestamp).Limit(limit).Delete(&Log{})
|
||||||
|
if nil != result.Error {
|
||||||
|
return total, result.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
total += result.RowsAffected
|
||||||
|
|
||||||
|
if result.RowsAffected < int64(limit) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return total, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func createRootAccountIfNeed() error {
|
|||||||
Role: common.RoleRootUser,
|
Role: common.RoleRootUser,
|
||||||
Status: common.UserStatusEnabled,
|
Status: common.UserStatusEnabled,
|
||||||
DisplayName: "Root User",
|
DisplayName: "Root User",
|
||||||
AccessToken: common.GetUUID(),
|
AccessToken: nil,
|
||||||
Quota: 100000000,
|
Quota: 100000000,
|
||||||
}
|
}
|
||||||
DB.Create(&rootUser)
|
DB.Create(&rootUser)
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ func InitOptionMap() {
|
|||||||
common.OptionMap["StripeUnitPrice"] = strconv.FormatFloat(common.StripeUnitPrice, 'f', -1, 64)
|
common.OptionMap["StripeUnitPrice"] = strconv.FormatFloat(common.StripeUnitPrice, 'f', -1, 64)
|
||||||
common.OptionMap["MinTopUp"] = strconv.Itoa(common.MinTopUp)
|
common.OptionMap["MinTopUp"] = strconv.Itoa(common.MinTopUp)
|
||||||
common.OptionMap["TopupGroupRatio"] = common.TopupGroupRatio2JSONString()
|
common.OptionMap["TopupGroupRatio"] = common.TopupGroupRatio2JSONString()
|
||||||
|
common.OptionMap["Chats"] = constant.Chats2JsonString()
|
||||||
common.OptionMap["GitHubClientId"] = ""
|
common.OptionMap["GitHubClientId"] = ""
|
||||||
common.OptionMap["GitHubClientSecret"] = ""
|
common.OptionMap["GitHubClientSecret"] = ""
|
||||||
common.OptionMap["LinuxDoClientId"] = ""
|
common.OptionMap["LinuxDoClientId"] = ""
|
||||||
@@ -90,6 +91,7 @@ func InitOptionMap() {
|
|||||||
common.OptionMap["ModelRatio"] = common.ModelRatio2JSONString()
|
common.OptionMap["ModelRatio"] = common.ModelRatio2JSONString()
|
||||||
common.OptionMap["ModelPrice"] = common.ModelPrice2JSONString()
|
common.OptionMap["ModelPrice"] = common.ModelPrice2JSONString()
|
||||||
common.OptionMap["GroupRatio"] = common.GroupRatio2JSONString()
|
common.OptionMap["GroupRatio"] = common.GroupRatio2JSONString()
|
||||||
|
common.OptionMap["UserUsableGroups"] = common.UserUsableGroups2JSONString()
|
||||||
common.OptionMap["CompletionRatio"] = common.CompletionRatio2JSONString()
|
common.OptionMap["CompletionRatio"] = common.CompletionRatio2JSONString()
|
||||||
common.OptionMap["TopUpLink"] = common.TopUpLink
|
common.OptionMap["TopUpLink"] = common.TopUpLink
|
||||||
common.OptionMap["ChatLink"] = common.ChatLink
|
common.OptionMap["ChatLink"] = common.ChatLink
|
||||||
@@ -251,6 +253,8 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
common.ServerAddress = value
|
common.ServerAddress = value
|
||||||
case "OutProxyUrl":
|
case "OutProxyUrl":
|
||||||
common.OutProxyUrl = value
|
common.OutProxyUrl = value
|
||||||
|
case "Chats":
|
||||||
|
err = constant.UpdateChatsByJsonString(value)
|
||||||
case "StripeApiSecret":
|
case "StripeApiSecret":
|
||||||
common.StripeApiSecret = value
|
common.StripeApiSecret = value
|
||||||
case "StripeWebhookSecret":
|
case "StripeWebhookSecret":
|
||||||
@@ -315,6 +319,8 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
err = common.UpdateModelRatioByJSONString(value)
|
err = common.UpdateModelRatioByJSONString(value)
|
||||||
case "GroupRatio":
|
case "GroupRatio":
|
||||||
err = common.UpdateGroupRatioByJSONString(value)
|
err = common.UpdateGroupRatioByJSONString(value)
|
||||||
|
case "UserUsableGroups":
|
||||||
|
err = common.UpdateUserUsableGroupsByJSONString(value)
|
||||||
case "CompletionRatio":
|
case "CompletionRatio":
|
||||||
err = common.UpdateCompletionRatioByJSONString(value)
|
err = common.UpdateCompletionRatioByJSONString(value)
|
||||||
case "ModelPrice":
|
case "ModelPrice":
|
||||||
|
|||||||
@@ -7,14 +7,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Pricing struct {
|
type Pricing struct {
|
||||||
Available bool `json:"available"`
|
|
||||||
ModelName string `json:"model_name"`
|
ModelName string `json:"model_name"`
|
||||||
QuotaType int `json:"quota_type"`
|
QuotaType int `json:"quota_type"`
|
||||||
ModelRatio float64 `json:"model_ratio"`
|
ModelRatio float64 `json:"model_ratio"`
|
||||||
ModelPrice float64 `json:"model_price"`
|
ModelPrice float64 `json:"model_price"`
|
||||||
OwnerBy string `json:"owner_by"`
|
OwnerBy string `json:"owner_by"`
|
||||||
CompletionRatio float64 `json:"completion_ratio"`
|
CompletionRatio float64 `json:"completion_ratio"`
|
||||||
EnableGroup []string `json:"enable_group,omitempty"`
|
EnableGroup []string `json:"enable_groups,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -23,40 +22,47 @@ var (
|
|||||||
updatePricingLock sync.Mutex
|
updatePricingLock sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetPricing(group string) []Pricing {
|
func GetPricing() []Pricing {
|
||||||
updatePricingLock.Lock()
|
updatePricingLock.Lock()
|
||||||
defer updatePricingLock.Unlock()
|
defer updatePricingLock.Unlock()
|
||||||
|
|
||||||
if time.Since(lastGetPricingTime) > time.Minute*1 || len(pricingMap) == 0 {
|
if time.Since(lastGetPricingTime) > time.Minute*1 || len(pricingMap) == 0 {
|
||||||
updatePricing()
|
updatePricing()
|
||||||
}
|
}
|
||||||
if group != "" {
|
//if group != "" {
|
||||||
userPricingMap := make([]Pricing, 0)
|
// userPricingMap := make([]Pricing, 0)
|
||||||
models := GetGroupModels(group)
|
// models := GetGroupModels(group)
|
||||||
for _, pricing := range pricingMap {
|
// for _, pricing := range pricingMap {
|
||||||
if !common.StringsContains(models, pricing.ModelName) {
|
// if !common.StringsContains(models, pricing.ModelName) {
|
||||||
pricing.Available = false
|
// pricing.Available = false
|
||||||
}
|
// }
|
||||||
userPricingMap = append(userPricingMap, pricing)
|
// userPricingMap = append(userPricingMap, pricing)
|
||||||
}
|
// }
|
||||||
return userPricingMap
|
// return userPricingMap
|
||||||
}
|
//}
|
||||||
return pricingMap
|
return pricingMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func updatePricing() {
|
func updatePricing() {
|
||||||
//modelRatios := common.GetModelRatios()
|
//modelRatios := common.GetModelRatios()
|
||||||
enabledModels := GetEnabledModels()
|
enableAbilities := GetAllEnableAbilities()
|
||||||
allModels := make(map[string]int)
|
modelGroupsMap := make(map[string][]string)
|
||||||
for i, model := range enabledModels {
|
for _, ability := range enableAbilities {
|
||||||
allModels[model] = i
|
groups := modelGroupsMap[ability.Model]
|
||||||
|
if groups == nil {
|
||||||
|
groups = make([]string, 0)
|
||||||
|
}
|
||||||
|
if !common.StringsContains(groups, ability.Group) {
|
||||||
|
groups = append(groups, ability.Group)
|
||||||
|
}
|
||||||
|
modelGroupsMap[ability.Model] = groups
|
||||||
}
|
}
|
||||||
|
|
||||||
pricingMap = make([]Pricing, 0)
|
pricingMap = make([]Pricing, 0)
|
||||||
for model, _ := range allModels {
|
for model, groups := range modelGroupsMap {
|
||||||
pricing := Pricing{
|
pricing := Pricing{
|
||||||
Available: true,
|
ModelName: model,
|
||||||
ModelName: model,
|
EnableGroup: groups,
|
||||||
}
|
}
|
||||||
modelPrice, findPrice := common.GetModelPrice(model, false)
|
modelPrice, findPrice := common.GetModelPrice(model, false)
|
||||||
if findPrice {
|
if findPrice {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
|
relaycommon "one-api/relay/common"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -22,10 +23,34 @@ type Token struct {
|
|||||||
UnlimitedQuota bool `json:"unlimited_quota" gorm:"default:false"`
|
UnlimitedQuota bool `json:"unlimited_quota" gorm:"default:false"`
|
||||||
ModelLimitsEnabled bool `json:"model_limits_enabled" gorm:"default:false"`
|
ModelLimitsEnabled bool `json:"model_limits_enabled" gorm:"default:false"`
|
||||||
ModelLimits string `json:"model_limits" gorm:"type:varchar(1024);default:''"`
|
ModelLimits string `json:"model_limits" gorm:"type:varchar(1024);default:''"`
|
||||||
|
AllowIps *string `json:"allow_ips" gorm:"default:''"`
|
||||||
UsedQuota int `json:"used_quota" gorm:"default:0"` // used quota
|
UsedQuota int `json:"used_quota" gorm:"default:0"` // used quota
|
||||||
|
Group string `json:"group" gorm:"default:''"`
|
||||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (token *Token) GetIpLimitsMap() map[string]any {
|
||||||
|
// delete empty spaces
|
||||||
|
//split with \n
|
||||||
|
ipLimitsMap := make(map[string]any)
|
||||||
|
if token.AllowIps == nil {
|
||||||
|
return ipLimitsMap
|
||||||
|
}
|
||||||
|
cleanIps := strings.ReplaceAll(*token.AllowIps, " ", "")
|
||||||
|
if cleanIps == "" {
|
||||||
|
return ipLimitsMap
|
||||||
|
}
|
||||||
|
ips := strings.Split(cleanIps, "\n")
|
||||||
|
for _, ip := range ips {
|
||||||
|
ip = strings.TrimSpace(ip)
|
||||||
|
ip = strings.ReplaceAll(ip, ",", "")
|
||||||
|
if common.IsIP(ip) {
|
||||||
|
ipLimitsMap[ip] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ipLimitsMap
|
||||||
|
}
|
||||||
|
|
||||||
func GetAllUserTokens(userId int, startIdx int, num int) ([]*Token, error) {
|
func GetAllUserTokens(userId int, startIdx int, num int) ([]*Token, error) {
|
||||||
var tokens []*Token
|
var tokens []*Token
|
||||||
var err error
|
var err error
|
||||||
@@ -129,7 +154,8 @@ func (token *Token) Insert() error {
|
|||||||
// Update Make sure your token's fields is completed, because this will update non-zero values
|
// Update Make sure your token's fields is completed, because this will update non-zero values
|
||||||
func (token *Token) Update() error {
|
func (token *Token) Update() error {
|
||||||
var err error
|
var err error
|
||||||
err = DB.Model(token).Select("name", "status", "expired_time", "remain_quota", "unlimited_quota", "model_limits_enabled", "model_limits").Updates(token).Error
|
err = DB.Model(token).Select("name", "status", "expired_time", "remain_quota", "unlimited_quota",
|
||||||
|
"model_limits_enabled", "model_limits", "allow_ips", "group").Updates(token).Error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,51 +257,56 @@ func decreaseTokenQuota(id int, quota int) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PreConsumeTokenQuota(tokenId int, quota int) (userQuota int, err error) {
|
func PreConsumeTokenQuota(relayInfo *relaycommon.RelayInfo, quota int) (userQuota int, err error) {
|
||||||
if quota < 0 {
|
if quota < 0 {
|
||||||
return 0, errors.New("quota 不能为负数!")
|
return 0, errors.New("quota 不能为负数!")
|
||||||
}
|
}
|
||||||
token, err := GetTokenById(tokenId)
|
if !relayInfo.IsPlayground {
|
||||||
if err != nil {
|
token, err := GetTokenById(relayInfo.TokenId)
|
||||||
return 0, err
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if !token.UnlimitedQuota && token.RemainQuota < quota {
|
||||||
|
return 0, errors.New("令牌额度不足")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !token.UnlimitedQuota && token.RemainQuota < quota {
|
userQuota, err = GetUserQuota(relayInfo.UserId)
|
||||||
return 0, errors.New("令牌额度不足")
|
|
||||||
}
|
|
||||||
userQuota, err = GetUserQuota(token.UserId)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if userQuota < quota {
|
if userQuota < quota {
|
||||||
return 0, errors.New(fmt.Sprintf("用户额度不足,剩余额度为 %d", userQuota))
|
return 0, errors.New(fmt.Sprintf("用户额度不足,剩余额度为 %d", userQuota))
|
||||||
}
|
}
|
||||||
err = DecreaseTokenQuota(tokenId, quota)
|
if !relayInfo.IsPlayground {
|
||||||
if err != nil {
|
err = DecreaseTokenQuota(relayInfo.TokenId, quota)
|
||||||
return 0, err
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err = DecreaseUserQuota(token.UserId, quota)
|
err = DecreaseUserQuota(relayInfo.UserId, quota)
|
||||||
return userQuota - quota, err
|
return userQuota - quota, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostConsumeTokenQuota(tokenId int, userQuota int, quota int, preConsumedQuota int, sendEmail bool) (err error) {
|
func PostConsumeTokenQuota(relayInfo *relaycommon.RelayInfo, userQuota int, quota int, preConsumedQuota int, sendEmail bool) (err error) {
|
||||||
token, err := GetTokenById(tokenId)
|
|
||||||
|
|
||||||
if quota > 0 {
|
if quota > 0 {
|
||||||
err = DecreaseUserQuota(token.UserId, quota)
|
err = DecreaseUserQuota(relayInfo.UserId, quota)
|
||||||
} else {
|
} else {
|
||||||
err = IncreaseUserQuota(token.UserId, -quota)
|
err = IncreaseUserQuota(relayInfo.UserId, -quota)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if quota > 0 {
|
if !relayInfo.IsPlayground {
|
||||||
err = DecreaseTokenQuota(tokenId, quota)
|
if quota > 0 {
|
||||||
} else {
|
err = DecreaseTokenQuota(relayInfo.TokenId, quota)
|
||||||
err = IncreaseTokenQuota(tokenId, -quota)
|
} else {
|
||||||
}
|
err = IncreaseTokenQuota(relayInfo.TokenId, -quota)
|
||||||
if err != nil {
|
}
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sendEmail {
|
if sendEmail {
|
||||||
@@ -284,7 +315,7 @@ func PostConsumeTokenQuota(tokenId int, userQuota int, quota int, preConsumedQuo
|
|||||||
noMoreQuota := userQuota-(quota+preConsumedQuota) <= 0
|
noMoreQuota := userQuota-(quota+preConsumedQuota) <= 0
|
||||||
if quotaTooLow || noMoreQuota {
|
if quotaTooLow || noMoreQuota {
|
||||||
go func() {
|
go func() {
|
||||||
email, err := GetUserEmail(token.UserId)
|
email, err := GetUserEmail(relayInfo.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SysError("failed to fetch user email: " + err.Error())
|
common.SysError("failed to fetch user email: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type User struct {
|
|||||||
WeChatId string `json:"wechat_id" gorm:"column:wechat_id;index"`
|
WeChatId string `json:"wechat_id" gorm:"column:wechat_id;index"`
|
||||||
TelegramId string `json:"telegram_id" gorm:"column:telegram_id;index"`
|
TelegramId string `json:"telegram_id" gorm:"column:telegram_id;index"`
|
||||||
VerificationCode string `json:"verification_code" gorm:"-:all"` // this field is only for Email verification, don't save it to database!
|
VerificationCode string `json:"verification_code" gorm:"-:all"` // this field is only for Email verification, don't save it to database!
|
||||||
AccessToken string `json:"access_token" gorm:"type:char(32);column:access_token;uniqueIndex"` // this token is for system management
|
AccessToken *string `json:"access_token" gorm:"type:char(32);column:access_token;uniqueIndex"` // this token is for system management
|
||||||
Quota int `json:"quota" gorm:"type:int;default:0"`
|
Quota int `json:"quota" gorm:"type:int;default:0"`
|
||||||
UsedQuota int `json:"used_quota" gorm:"type:int;default:0;column:used_quota"` // used quota
|
UsedQuota int `json:"used_quota" gorm:"type:int;default:0;column:used_quota"` // used quota
|
||||||
RequestCount int `json:"request_count" gorm:"type:int;default:0;"` // request number
|
RequestCount int `json:"request_count" gorm:"type:int;default:0;"` // request number
|
||||||
@@ -41,6 +41,17 @@ type User struct {
|
|||||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (user *User) GetAccessToken() string {
|
||||||
|
if user.AccessToken == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return *user.AccessToken
|
||||||
|
}
|
||||||
|
|
||||||
|
func (user *User) SetAccessToken(token string) {
|
||||||
|
user.AccessToken = &token
|
||||||
|
}
|
||||||
|
|
||||||
// CheckUserExistOrDeleted check if user exist or deleted, if not exist, return false, nil, if deleted or exist, return true, nil
|
// CheckUserExistOrDeleted check if user exist or deleted, if not exist, return false, nil, if deleted or exist, return true, nil
|
||||||
func CheckUserExistOrDeleted(username string, email string) (bool, error) {
|
func CheckUserExistOrDeleted(username string, email string) (bool, error) {
|
||||||
var user User
|
var user User
|
||||||
@@ -80,13 +91,18 @@ func SearchUsers(keyword string, group string) ([]*User, error) {
|
|||||||
var users []*User
|
var users []*User
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
groupCol := "`group`"
|
||||||
|
if common.UsingPostgreSQL {
|
||||||
|
groupCol = `"group"`
|
||||||
|
}
|
||||||
|
|
||||||
// 尝试将关键字转换为整数ID
|
// 尝试将关键字转换为整数ID
|
||||||
keywordInt, err := strconv.Atoi(keyword)
|
keywordInt, err := strconv.Atoi(keyword)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// 如果转换成功,按照ID和可选的组别搜索用户
|
// 如果转换成功,按照ID和可选的组别搜索用户
|
||||||
query := DB.Unscoped().Omit("password").Where("`id` = ?", keywordInt)
|
query := DB.Unscoped().Omit("password").Where("id = ?", keywordInt)
|
||||||
if group != "" {
|
if group != "" {
|
||||||
query = query.Where("`group` = ?", group) // 使用反引号包围group
|
query = query.Where(groupCol+" = ?", group) // 使用反引号包围group
|
||||||
}
|
}
|
||||||
err = query.Find(&users).Error
|
err = query.Find(&users).Error
|
||||||
if err != nil || len(users) > 0 {
|
if err != nil || len(users) > 0 {
|
||||||
@@ -97,9 +113,9 @@ func SearchUsers(keyword string, group string) ([]*User, error) {
|
|||||||
err = nil
|
err = nil
|
||||||
|
|
||||||
query := DB.Unscoped().Omit("password")
|
query := DB.Unscoped().Omit("password")
|
||||||
likeCondition := "`username` LIKE ? OR `email` LIKE ? OR `display_name` LIKE ?"
|
likeCondition := "username LIKE ? OR email LIKE ? OR display_name LIKE ?"
|
||||||
if group != "" {
|
if group != "" {
|
||||||
query = query.Where("("+likeCondition+") AND `group` = ?", "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%", group)
|
query = query.Where("("+likeCondition+") AND "+groupCol+" = ?", "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%", group)
|
||||||
} else {
|
} else {
|
||||||
query = query.Where(likeCondition, "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%")
|
query = query.Where(likeCondition, "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%")
|
||||||
}
|
}
|
||||||
@@ -218,7 +234,7 @@ func (user *User) Insert(inviterId int) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
user.Quota = common.QuotaForNewUser
|
user.Quota = common.QuotaForNewUser
|
||||||
user.AccessToken = common.GetUUID()
|
//user.SetAccessToken(common.GetUUID())
|
||||||
user.AffCode = common.GetRandomString(4)
|
user.AffCode = common.GetRandomString(4)
|
||||||
result := DB.Create(user)
|
result := DB.Create(user)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
@@ -312,11 +328,12 @@ func (user *User) ValidateAndFill() (err error) {
|
|||||||
// that means if your field’s value is 0, '', false or other zero values,
|
// that means if your field’s value is 0, '', false or other zero values,
|
||||||
// it won’t be used to build query conditions
|
// it won’t be used to build query conditions
|
||||||
password := user.Password
|
password := user.Password
|
||||||
if user.Username == "" || password == "" {
|
username := strings.TrimSpace(user.Username)
|
||||||
|
if username == "" || password == "" {
|
||||||
return errors.New("用户名或密码为空")
|
return errors.New("用户名或密码为空")
|
||||||
}
|
}
|
||||||
// find buy username or email
|
// find buy username or email
|
||||||
DB.Where("username = ? OR email = ?", user.Username, user.Username).First(user)
|
DB.Where("username = ? OR email = ?", username, username).First(user)
|
||||||
okay := common.ValidatePasswordAndHash(password, user.Password)
|
okay := common.ValidatePasswordAndHash(password, user.Password)
|
||||||
if !okay || user.Status != common.UserStatusEnabled {
|
if !okay || user.Status != common.UserStatusEnabled {
|
||||||
return errors.New("用户名或密码错误,或用户已被封禁")
|
return errors.New("用户名或密码错误,或用户已被封禁")
|
||||||
@@ -364,14 +381,6 @@ func (user *User) FillUserByWeChatId() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) FillUserByUsername() error {
|
|
||||||
if user.Username == "" {
|
|
||||||
return errors.New("username 为空!")
|
|
||||||
}
|
|
||||||
DB.Where(User{Username: user.Username}).First(user)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (user *User) FillUserByTelegramId() error {
|
func (user *User) FillUserByTelegramId() error {
|
||||||
if user.TelegramId == "" {
|
if user.TelegramId == "" {
|
||||||
return errors.New("Telegram id 为空!")
|
return errors.New("Telegram id 为空!")
|
||||||
@@ -384,27 +393,27 @@ func (user *User) FillUserByTelegramId() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsEmailAlreadyTaken(email string) bool {
|
func IsEmailAlreadyTaken(email string) bool {
|
||||||
return DB.Where("email = ?", email).Find(&User{}).RowsAffected == 1
|
return DB.Unscoped().Where("email = ?", email).Find(&User{}).RowsAffected == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsWeChatIdAlreadyTaken(wechatId string) bool {
|
func IsWeChatIdAlreadyTaken(wechatId string) bool {
|
||||||
return DB.Where("wechat_id = ?", wechatId).Find(&User{}).RowsAffected == 1
|
return DB.Unscoped().Where("wechat_id = ?", wechatId).Find(&User{}).RowsAffected == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsGitHubIdAlreadyTaken(githubId string) bool {
|
func IsGitHubIdAlreadyTaken(githubId string) bool {
|
||||||
return DB.Where("github_id = ?", githubId).Find(&User{}).RowsAffected == 1
|
return DB.Unscoped().Where("github_id = ?", githubId).Find(&User{}).RowsAffected == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsLinuxDoIdAlreadyTaken(linuxdoId string) bool {
|
func IsLinuxDoIdAlreadyTaken(linuxdoId string) bool {
|
||||||
return DB.Where("linuxdo_id = ?", linuxdoId).Find(&User{}).RowsAffected == 1
|
return DB.Unscoped().Where("linuxdo_id = ?", linuxdoId).Find(&User{}).RowsAffected == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsUsernameAlreadyTaken(username string) bool {
|
func IsUsernameAlreadyTaken(username string) bool {
|
||||||
return DB.Where("username = ?", username).Find(&User{}).RowsAffected == 1
|
return DB.Unscoped().Where("username = ?", username).Find(&User{}).RowsAffected == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsTelegramIdAlreadyTaken(telegramId string) bool {
|
func IsTelegramIdAlreadyTaken(telegramId string) bool {
|
||||||
return DB.Where("telegram_id = ?", telegramId).Find(&User{}).RowsAffected == 1
|
return DB.Unscoped().Where("telegram_id = ?", telegramId).Find(&User{}).RowsAffected == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResetUserPasswordByEmail(email string, password string) error {
|
func ResetUserPasswordByEmail(email string, password string) error {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"one-api/dto"
|
"one-api/dto"
|
||||||
"one-api/relay/channel/claude"
|
"one-api/relay/channel/claude"
|
||||||
relaycommon "one-api/relay/common"
|
relaycommon "one-api/relay/common"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -31,11 +30,7 @@ func (a *Adaptor) ConvertImageRequest(c *gin.Context, info *relaycommon.RelayInf
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
|
func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
|
||||||
if strings.HasPrefix(info.UpstreamModelName, "claude-3") {
|
a.RequestMode = RequestModeMessage
|
||||||
a.RequestMode = RequestModeMessage
|
|
||||||
} else {
|
|
||||||
a.RequestMode = RequestModeCompletion
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
||||||
@@ -53,11 +48,8 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, info *relaycommon.RelayInfo, re
|
|||||||
|
|
||||||
var claudeReq *claude.ClaudeRequest
|
var claudeReq *claude.ClaudeRequest
|
||||||
var err error
|
var err error
|
||||||
if a.RequestMode == RequestModeCompletion {
|
claudeReq, err = claude.RequestOpenAI2ClaudeMessage(*request)
|
||||||
claudeReq = claude.RequestOpenAI2ClaudeComplete(*request)
|
|
||||||
} else {
|
|
||||||
claudeReq, err = claude.RequestOpenAI2ClaudeMessage(*request)
|
|
||||||
}
|
|
||||||
c.Set("request_model", request.Model)
|
c.Set("request_model", request.Model)
|
||||||
c.Set("converted_request", claudeReq)
|
c.Set("converted_request", claudeReq)
|
||||||
return claudeReq, err
|
return claudeReq, err
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package aws
|
package aws
|
||||||
|
|
||||||
var awsModelIDMap = map[string]string{
|
var awsModelIDMap = map[string]string{
|
||||||
"claude-instant-1.2": "anthropic.claude-instant-v1",
|
"claude-instant-1.2": "anthropic.claude-instant-v1",
|
||||||
"claude-2.0": "anthropic.claude-v2",
|
"claude-2.0": "anthropic.claude-v2",
|
||||||
"claude-2.1": "anthropic.claude-v2:1",
|
"claude-2.1": "anthropic.claude-v2:1",
|
||||||
"claude-3-sonnet-20240229": "anthropic.claude-3-sonnet-20240229-v1:0",
|
"claude-3-sonnet-20240229": "anthropic.claude-3-sonnet-20240229-v1:0",
|
||||||
"claude-3-opus-20240229": "anthropic.claude-3-opus-20240229-v1:0",
|
"claude-3-opus-20240229": "anthropic.claude-3-opus-20240229-v1:0",
|
||||||
"claude-3-haiku-20240307": "anthropic.claude-3-haiku-20240307-v1:0",
|
"claude-3-haiku-20240307": "anthropic.claude-3-haiku-20240307-v1:0",
|
||||||
"claude-3-5-sonnet-20240620": "anthropic.claude-3-5-sonnet-20240620-v1:0",
|
"claude-3-5-sonnet-20240620": "anthropic.claude-3-5-sonnet-20240620-v1:0",
|
||||||
|
"claude-3-5-sonnet-20241022": "anthropic.claude-3-5-sonnet-20241022-v2:0",
|
||||||
}
|
}
|
||||||
|
|
||||||
var ChannelName = "aws"
|
var ChannelName = "aws"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package aws
|
package aws
|
||||||
|
|
||||||
import "one-api/relay/channel/claude"
|
import (
|
||||||
|
"one-api/relay/channel/claude"
|
||||||
|
)
|
||||||
|
|
||||||
type AwsClaudeRequest struct {
|
type AwsClaudeRequest struct {
|
||||||
// AnthropicVersion should be "bedrock-2023-05-31"
|
// AnthropicVersion should be "bedrock-2023-05-31"
|
||||||
@@ -12,4 +14,6 @@ type AwsClaudeRequest struct {
|
|||||||
TopP float64 `json:"top_p,omitempty"`
|
TopP float64 `json:"top_p,omitempty"`
|
||||||
TopK int `json:"top_k,omitempty"`
|
TopK int `json:"top_k,omitempty"`
|
||||||
StopSequences []string `json:"stop_sequences,omitempty"`
|
StopSequences []string `json:"stop_sequences,omitempty"`
|
||||||
|
Tools []claude.Tool `json:"tools,omitempty"`
|
||||||
|
ToolChoice any `json:"tool_choice,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func awsModelID(requestModel string) (string, error) {
|
|||||||
return awsModelID, nil
|
return awsModelID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", errors.Errorf("model %s not found", requestModel)
|
return requestModel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func awsHandler(c *gin.Context, info *relaycommon.RelayInfo, requestMode int) (*relaymodel.OpenAIErrorWithStatusCode, *relaymodel.Usage) {
|
func awsHandler(c *gin.Context, info *relaycommon.RelayInfo, requestMode int) (*relaymodel.OpenAIErrorWithStatusCode, *relaymodel.Usage) {
|
||||||
|
|||||||
@@ -50,11 +50,18 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
|||||||
func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, info *relaycommon.RelayInfo) error {
|
func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, info *relaycommon.RelayInfo) error {
|
||||||
channel.SetupApiRequestHeader(info, c, req)
|
channel.SetupApiRequestHeader(info, c, req)
|
||||||
req.Header.Set("x-api-key", info.ApiKey)
|
req.Header.Set("x-api-key", info.ApiKey)
|
||||||
|
|
||||||
anthropicVersion := c.Request.Header.Get("anthropic-version")
|
anthropicVersion := c.Request.Header.Get("anthropic-version")
|
||||||
if anthropicVersion == "" {
|
if anthropicVersion == "" {
|
||||||
anthropicVersion = "2023-06-01"
|
anthropicVersion = "2023-06-01"
|
||||||
}
|
}
|
||||||
req.Header.Set("anthropic-version", anthropicVersion)
|
req.Header.Set("anthropic-version", anthropicVersion)
|
||||||
|
|
||||||
|
anthropicBeta := c.Request.Header.Get("anthropic-beta")
|
||||||
|
if "" != anthropicBeta {
|
||||||
|
req.Header.Set("anthropic-beta", anthropicBeta)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ var ModelList = []string{
|
|||||||
"claude-3-sonnet-20240229",
|
"claude-3-sonnet-20240229",
|
||||||
"claude-3-opus-20240229",
|
"claude-3-opus-20240229",
|
||||||
"claude-3-haiku-20240307",
|
"claude-3-haiku-20240307",
|
||||||
|
"claude-3-5-haiku-20241022",
|
||||||
"claude-3-5-sonnet-20240620",
|
"claude-3-5-sonnet-20240620",
|
||||||
|
"claude-3-5-sonnet-20241022",
|
||||||
|
"claude-3-7-sonnet-20250219",
|
||||||
|
"claude-3-7-sonnet-20250219-thinking",
|
||||||
}
|
}
|
||||||
|
|
||||||
var ChannelName = "claude"
|
var ChannelName = "claude"
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package claude
|
package claude
|
||||||
|
|
||||||
|
import "one-api/dto"
|
||||||
|
|
||||||
type ClaudeMetadata struct {
|
type ClaudeMetadata struct {
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
}
|
}
|
||||||
@@ -11,6 +13,9 @@ type ClaudeMediaMessage struct {
|
|||||||
Usage *ClaudeUsage `json:"usage,omitempty"`
|
Usage *ClaudeUsage `json:"usage,omitempty"`
|
||||||
StopReason *string `json:"stop_reason,omitempty"`
|
StopReason *string `json:"stop_reason,omitempty"`
|
||||||
PartialJson string `json:"partial_json,omitempty"`
|
PartialJson string `json:"partial_json,omitempty"`
|
||||||
|
Thinking string `json:"thinking,omitempty"`
|
||||||
|
Signature string `json:"signature,omitempty"`
|
||||||
|
Delta string `json:"delta,omitempty"`
|
||||||
// tool_calls
|
// tool_calls
|
||||||
Id string `json:"id,omitempty"`
|
Id string `json:"id,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
@@ -31,9 +36,13 @@ type ClaudeMessage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Tool struct {
|
type Tool struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description,omitempty"`
|
Description any `json:"description,omitempty"`
|
||||||
InputSchema map[string]interface{} `json:"input_schema"`
|
InputSchema map[string]interface{} `json:"input_schema,omitempty"`
|
||||||
|
Type any `json:"type,omitempty"`
|
||||||
|
DisplayHeightPx int `json:"display_height_px,omitempty"`
|
||||||
|
DisplayWidthPx int `json:"display_width_px,omitempty"`
|
||||||
|
DisplayNumber int `json:"display_number,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InputSchema struct {
|
type InputSchema struct {
|
||||||
@@ -54,9 +63,10 @@ type ClaudeRequest struct {
|
|||||||
TopP float64 `json:"top_p,omitempty"`
|
TopP float64 `json:"top_p,omitempty"`
|
||||||
TopK int `json:"top_k,omitempty"`
|
TopK int `json:"top_k,omitempty"`
|
||||||
//ClaudeMetadata `json:"metadata,omitempty"`
|
//ClaudeMetadata `json:"metadata,omitempty"`
|
||||||
Stream bool `json:"stream,omitempty"`
|
Stream bool `json:"stream,omitempty"`
|
||||||
Tools []Tool `json:"tools,omitempty"`
|
Tools []Tool `json:"tools,omitempty"`
|
||||||
ToolChoice any `json:"tool_choice,omitempty"`
|
ToolChoice any `json:"tool_choice,omitempty"`
|
||||||
|
Thinking *dto.Thinking `json:"thinking,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClaudeError struct {
|
type ClaudeError struct {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
@@ -12,6 +11,8 @@ import (
|
|||||||
relaycommon "one-api/relay/common"
|
relaycommon "one-api/relay/common"
|
||||||
"one-api/service"
|
"one-api/service"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func stopReasonClaude2OpenAI(reason string) string {
|
func stopReasonClaude2OpenAI(reason string) string {
|
||||||
@@ -61,24 +62,63 @@ func RequestOpenAI2ClaudeComplete(textRequest dto.GeneralOpenAIRequest) *ClaudeR
|
|||||||
func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*ClaudeRequest, error) {
|
func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*ClaudeRequest, error) {
|
||||||
claudeTools := make([]Tool, 0, len(textRequest.Tools))
|
claudeTools := make([]Tool, 0, len(textRequest.Tools))
|
||||||
|
|
||||||
for _, tool := range textRequest.Tools {
|
if strings.HasSuffix(textRequest.Model, "-thinking") {
|
||||||
if params, ok := tool.Function.Parameters.(map[string]any); ok {
|
textRequest.Model = strings.TrimSuffix(textRequest.Model, "-thinking")
|
||||||
claudeTool := Tool{
|
|
||||||
Name: tool.Function.Name,
|
if textRequest.MaxTokens == 0 {
|
||||||
Description: tool.Function.Description,
|
textRequest.MaxTokens = 4096
|
||||||
}
|
} else if textRequest.MaxTokens < 1280 {
|
||||||
claudeTool.InputSchema = make(map[string]interface{})
|
textRequest.MaxTokens = 1280
|
||||||
claudeTool.InputSchema["type"] = params["type"].(string)
|
|
||||||
claudeTool.InputSchema["properties"] = params["properties"]
|
|
||||||
claudeTool.InputSchema["required"] = params["required"]
|
|
||||||
for s, a := range params {
|
|
||||||
if s == "type" || s == "properties" || s == "required" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
claudeTool.InputSchema[s] = a
|
|
||||||
}
|
|
||||||
claudeTools = append(claudeTools, claudeTool)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textRequest.TopP = 0
|
||||||
|
textRequest.TopK = 0
|
||||||
|
textRequest.Temperature = 0
|
||||||
|
textRequest.Thinking = &dto.Thinking{
|
||||||
|
Type: "enabled",
|
||||||
|
BudgetTokens: int(float64(textRequest.MaxTokens) * 0.8),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tool := range textRequest.Tools {
|
||||||
|
claudeTool := Tool{
|
||||||
|
Name: tool.Function.Name,
|
||||||
|
Description: tool.Function.Description,
|
||||||
|
Type: tool.Type,
|
||||||
|
}
|
||||||
|
|
||||||
|
if "function" != tool.Type {
|
||||||
|
claudeTool.Description = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if params, ok := tool.Function.Parameters.(map[string]any); ok {
|
||||||
|
if "function" == tool.Type {
|
||||||
|
claudeTool.Type = nil
|
||||||
|
|
||||||
|
claudeTool.InputSchema = make(map[string]interface{})
|
||||||
|
claudeTool.InputSchema["type"] = params["type"].(string)
|
||||||
|
claudeTool.InputSchema["properties"] = params["properties"]
|
||||||
|
claudeTool.InputSchema["required"] = params["required"]
|
||||||
|
for s, a := range params {
|
||||||
|
if s == "type" || s == "properties" || s == "required" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
claudeTool.InputSchema[s] = a
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if val, ok := params["display_height_px"]; ok {
|
||||||
|
claudeTool.DisplayHeightPx = int(val.(float64))
|
||||||
|
}
|
||||||
|
if val, ok := params["display_width_px"]; ok {
|
||||||
|
claudeTool.DisplayWidthPx = int(val.(float64))
|
||||||
|
}
|
||||||
|
if val, ok := params["display_number"]; ok {
|
||||||
|
claudeTool.DisplayNumber = int(val.(float64))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
claudeTools = append(claudeTools, claudeTool)
|
||||||
}
|
}
|
||||||
|
|
||||||
claudeRequest := ClaudeRequest{
|
claudeRequest := ClaudeRequest{
|
||||||
@@ -90,6 +130,8 @@ func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*ClaudeR
|
|||||||
TopK: textRequest.TopK,
|
TopK: textRequest.TopK,
|
||||||
Stream: textRequest.Stream,
|
Stream: textRequest.Stream,
|
||||||
Tools: claudeTools,
|
Tools: claudeTools,
|
||||||
|
ToolChoice: textRequest.ToolChoice,
|
||||||
|
Thinking: textRequest.Thinking,
|
||||||
}
|
}
|
||||||
if claudeRequest.MaxTokens == 0 {
|
if claudeRequest.MaxTokens == 0 {
|
||||||
claudeRequest.MaxTokens = 4096
|
claudeRequest.MaxTokens = 4096
|
||||||
@@ -108,13 +150,10 @@ func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*ClaudeR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
formatMessages := make([]dto.Message, 0)
|
formatMessages := make([]dto.Message, 0)
|
||||||
var lastMessage *dto.Message
|
lastMessage := dto.Message{
|
||||||
|
Role: "tool",
|
||||||
|
}
|
||||||
for i, message := range textRequest.Messages {
|
for i, message := range textRequest.Messages {
|
||||||
//if message.Role == "system" {
|
|
||||||
// if i != 0 {
|
|
||||||
// message.Role = "user"
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
if message.Role == "" {
|
if message.Role == "" {
|
||||||
textRequest.Messages[i].Role = "user"
|
textRequest.Messages[i].Role = "user"
|
||||||
}
|
}
|
||||||
@@ -122,7 +161,13 @@ func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*ClaudeR
|
|||||||
Role: message.Role,
|
Role: message.Role,
|
||||||
Content: message.Content,
|
Content: message.Content,
|
||||||
}
|
}
|
||||||
if lastMessage != nil && lastMessage.Role == message.Role {
|
if message.Role == "tool" {
|
||||||
|
fmtMessage.ToolCallId = message.ToolCallId
|
||||||
|
}
|
||||||
|
if message.Role == "assistant" && message.ToolCalls != nil {
|
||||||
|
fmtMessage.ToolCalls = message.ToolCalls
|
||||||
|
}
|
||||||
|
if lastMessage.Role == message.Role && lastMessage.Role != "tool" {
|
||||||
if lastMessage.IsStringContent() && message.IsStringContent() {
|
if lastMessage.IsStringContent() && message.IsStringContent() {
|
||||||
content, _ := json.Marshal(strings.Trim(fmt.Sprintf("%s %s", lastMessage.StringContent(), message.StringContent()), "\""))
|
content, _ := json.Marshal(strings.Trim(fmt.Sprintf("%s %s", lastMessage.StringContent(), message.StringContent()), "\""))
|
||||||
fmtMessage.Content = content
|
fmtMessage.Content = content
|
||||||
@@ -135,7 +180,7 @@ func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*ClaudeR
|
|||||||
fmtMessage.Content = content
|
fmtMessage.Content = content
|
||||||
}
|
}
|
||||||
formatMessages = append(formatMessages, fmtMessage)
|
formatMessages = append(formatMessages, fmtMessage)
|
||||||
lastMessage = &textRequest.Messages[i]
|
lastMessage = fmtMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
claudeMessages := make([]ClaudeMessage, 0)
|
claudeMessages := make([]ClaudeMessage, 0)
|
||||||
@@ -174,7 +219,35 @@ func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*ClaudeR
|
|||||||
claudeMessage := ClaudeMessage{
|
claudeMessage := ClaudeMessage{
|
||||||
Role: message.Role,
|
Role: message.Role,
|
||||||
}
|
}
|
||||||
if message.IsStringContent() {
|
if message.Role == "tool" {
|
||||||
|
if len(claudeMessages) > 0 && claudeMessages[len(claudeMessages)-1].Role == "user" {
|
||||||
|
lastMessage := claudeMessages[len(claudeMessages)-1]
|
||||||
|
if content, ok := lastMessage.Content.(string); ok {
|
||||||
|
lastMessage.Content = []ClaudeMediaMessage{
|
||||||
|
{
|
||||||
|
Type: "text",
|
||||||
|
Text: content,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastMessage.Content = append(lastMessage.Content.([]ClaudeMediaMessage), ClaudeMediaMessage{
|
||||||
|
Type: "tool_result",
|
||||||
|
ToolUseId: message.ToolCallId,
|
||||||
|
Content: message.StringContent(),
|
||||||
|
})
|
||||||
|
claudeMessages[len(claudeMessages)-1] = lastMessage
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
claudeMessage.Role = "user"
|
||||||
|
claudeMessage.Content = []ClaudeMediaMessage{
|
||||||
|
{
|
||||||
|
Type: "tool_result",
|
||||||
|
ToolUseId: message.ToolCallId,
|
||||||
|
Content: message.StringContent(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if message.IsStringContent() && message.ToolCalls == nil {
|
||||||
claudeMessage.Content = message.StringContent()
|
claudeMessage.Content = message.StringContent()
|
||||||
} else {
|
} else {
|
||||||
claudeMediaMessages := make([]ClaudeMediaMessage, 0)
|
claudeMediaMessages := make([]ClaudeMediaMessage, 0)
|
||||||
@@ -207,6 +280,28 @@ func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*ClaudeR
|
|||||||
}
|
}
|
||||||
claudeMediaMessages = append(claudeMediaMessages, claudeMediaMessage)
|
claudeMediaMessages = append(claudeMediaMessages, claudeMediaMessage)
|
||||||
}
|
}
|
||||||
|
if message.ToolCalls != nil {
|
||||||
|
for _, tc := range message.ToolCalls.([]interface{}) {
|
||||||
|
toolCallJSON, _ := json.Marshal(tc)
|
||||||
|
var toolCall dto.ToolCall
|
||||||
|
err := json.Unmarshal(toolCallJSON, &toolCall)
|
||||||
|
if err != nil {
|
||||||
|
common.SysError("tool call is not a dto.ToolCall: " + fmt.Sprintf("%v", tc))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
inputObj := make(map[string]any)
|
||||||
|
if err := json.Unmarshal([]byte(toolCall.Function.Arguments), &inputObj); err != nil {
|
||||||
|
common.SysError("tool call function arguments is not a map[string]any: " + fmt.Sprintf("%v", toolCall.Function.Arguments))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
claudeMediaMessages = append(claudeMediaMessages, ClaudeMediaMessage{
|
||||||
|
Type: "tool_use",
|
||||||
|
Id: toolCall.ID,
|
||||||
|
Name: toolCall.Function.Name,
|
||||||
|
Input: inputObj,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
claudeMessage.Content = claudeMediaMessages
|
claudeMessage.Content = claudeMediaMessages
|
||||||
}
|
}
|
||||||
claudeMessages = append(claudeMessages, claudeMessage)
|
claudeMessages = append(claudeMessages, claudeMessage)
|
||||||
@@ -258,12 +353,19 @@ func StreamResponseClaude2OpenAI(reqMode int, claudeResponse *ClaudeResponse) (*
|
|||||||
if claudeResponse.Delta != nil {
|
if claudeResponse.Delta != nil {
|
||||||
choice.Index = claudeResponse.Index
|
choice.Index = claudeResponse.Index
|
||||||
choice.Delta.SetContentString(claudeResponse.Delta.Text)
|
choice.Delta.SetContentString(claudeResponse.Delta.Text)
|
||||||
if claudeResponse.Delta.Type == "input_json_delta" {
|
switch claudeResponse.Delta.Type {
|
||||||
|
case "input_json_delta":
|
||||||
tools = append(tools, dto.ToolCall{
|
tools = append(tools, dto.ToolCall{
|
||||||
Function: dto.FunctionCall{
|
Function: dto.FunctionCall{
|
||||||
Arguments: claudeResponse.Delta.PartialJson,
|
Arguments: claudeResponse.Delta.PartialJson,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
case "signature_delta":
|
||||||
|
reasoningContent := "\n"
|
||||||
|
choice.Delta.ReasoningContent = &reasoningContent
|
||||||
|
case "thinking_delta":
|
||||||
|
reasoningContent := claudeResponse.Delta.Thinking
|
||||||
|
choice.Delta.ReasoningContent = &reasoningContent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if claudeResponse.Type == "message_delta" {
|
} else if claudeResponse.Type == "message_delta" {
|
||||||
@@ -301,6 +403,8 @@ func ResponseClaude2OpenAI(reqMode int, claudeResponse *ClaudeResponse) *dto.Ope
|
|||||||
if len(claudeResponse.Content) > 0 {
|
if len(claudeResponse.Content) > 0 {
|
||||||
responseText = claudeResponse.Content[0].Text
|
responseText = claudeResponse.Content[0].Text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reasoningContent := ""
|
||||||
tools := make([]dto.ToolCall, 0)
|
tools := make([]dto.ToolCall, 0)
|
||||||
if reqMode == RequestModeCompletion {
|
if reqMode == RequestModeCompletion {
|
||||||
content, _ := json.Marshal(strings.TrimPrefix(claudeResponse.Completion, " "))
|
content, _ := json.Marshal(strings.TrimPrefix(claudeResponse.Completion, " "))
|
||||||
@@ -317,7 +421,8 @@ func ResponseClaude2OpenAI(reqMode int, claudeResponse *ClaudeResponse) *dto.Ope
|
|||||||
} else {
|
} else {
|
||||||
fullTextResponse.Id = claudeResponse.Id
|
fullTextResponse.Id = claudeResponse.Id
|
||||||
for _, message := range claudeResponse.Content {
|
for _, message := range claudeResponse.Content {
|
||||||
if message.Type == "tool_use" {
|
switch message.Type {
|
||||||
|
case "tool_use":
|
||||||
args, _ := json.Marshal(message.Input)
|
args, _ := json.Marshal(message.Input)
|
||||||
tools = append(tools, dto.ToolCall{
|
tools = append(tools, dto.ToolCall{
|
||||||
ID: message.Id,
|
ID: message.Id,
|
||||||
@@ -327,6 +432,10 @@ func ResponseClaude2OpenAI(reqMode int, claudeResponse *ClaudeResponse) *dto.Ope
|
|||||||
Arguments: string(args),
|
Arguments: string(args),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
case "thinking":
|
||||||
|
reasoningContent = message.Thinking
|
||||||
|
case "text":
|
||||||
|
responseText = message.Text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,6 +450,8 @@ func ResponseClaude2OpenAI(reqMode int, claudeResponse *ClaudeResponse) *dto.Ope
|
|||||||
if len(tools) > 0 {
|
if len(tools) > 0 {
|
||||||
choice.Message.ToolCalls = tools
|
choice.Message.ToolCalls = tools
|
||||||
}
|
}
|
||||||
|
choice.Message.ReasoningContent = &reasoningContent
|
||||||
|
fullTextResponse.Model = claudeResponse.Model
|
||||||
choices = append(choices, choice)
|
choices = append(choices, choice)
|
||||||
fullTextResponse.Choices = choices
|
fullTextResponse.Choices = choices
|
||||||
return &fullTextResponse
|
return &fullTextResponse
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ type CohereRequest struct {
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Stream bool `json:"stream"`
|
Stream bool `json:"stream"`
|
||||||
MaxTokens int `json:"max_tokens"`
|
MaxTokens int `json:"max_tokens"`
|
||||||
|
SafetyMode string `json:"safety_mode,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChatHistory struct {
|
type ChatHistory struct {
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ func requestOpenAI2Cohere(textRequest dto.GeneralOpenAIRequest) *CohereRequest {
|
|||||||
Stream: textRequest.Stream,
|
Stream: textRequest.Stream,
|
||||||
MaxTokens: textRequest.GetMaxTokens(),
|
MaxTokens: textRequest.GetMaxTokens(),
|
||||||
}
|
}
|
||||||
|
if common.CohereSafetySetting != "NONE" {
|
||||||
|
cohereReq.SafetyMode = common.CohereSafetySetting
|
||||||
|
}
|
||||||
if cohereReq.MaxTokens == 0 {
|
if cohereReq.MaxTokens == 0 {
|
||||||
cohereReq.MaxTokens = 4000
|
cohereReq.MaxTokens = 4000
|
||||||
}
|
}
|
||||||
@@ -44,6 +47,7 @@ func requestOpenAI2Cohere(textRequest dto.GeneralOpenAIRequest) *CohereRequest {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &cohereReq
|
return &cohereReq
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const (
|
|||||||
|
|
||||||
var ModelList = []string{
|
var ModelList = []string{
|
||||||
"gemini-1.0-pro-latest", "gemini-1.0-pro-001", "gemini-1.5-pro-latest", "gemini-1.5-flash-latest", "gemini-ultra",
|
"gemini-1.0-pro-latest", "gemini-1.0-pro-001", "gemini-1.5-pro-latest", "gemini-1.5-flash-latest", "gemini-ultra",
|
||||||
"gemini-1.0-pro-vision-latest", "gemini-1.0-pro-vision-001",
|
"gemini-1.0-pro-vision-latest", "gemini-1.0-pro-vision-001", "gemini-1.5-pro-exp-0827", "gemini-1.5-flash-exp-0827",
|
||||||
}
|
}
|
||||||
|
|
||||||
var ChannelName = "google gemini"
|
var ChannelName = "google gemini"
|
||||||
|
|||||||
@@ -17,11 +17,25 @@ type OllamaRequest struct {
|
|||||||
PresencePenalty float64 `json:"presence_penalty,omitempty"`
|
PresencePenalty float64 `json:"presence_penalty,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Options struct {
|
||||||
|
Seed int `json:"seed,omitempty"`
|
||||||
|
Temperature float64 `json:"temperature,omitempty"`
|
||||||
|
TopK int `json:"top_k,omitempty"`
|
||||||
|
TopP float64 `json:"top_p,omitempty"`
|
||||||
|
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
|
||||||
|
PresencePenalty float64 `json:"presence_penalty,omitempty"`
|
||||||
|
NumPredict int `json:"num_predict,omitempty"`
|
||||||
|
NumCtx int `json:"num_ctx,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type OllamaEmbeddingRequest struct {
|
type OllamaEmbeddingRequest struct {
|
||||||
Model string `json:"model,omitempty"`
|
Model string `json:"model,omitempty"`
|
||||||
Prompt any `json:"prompt,omitempty"`
|
Input []string `json:"input"`
|
||||||
|
Options *Options `json:"options,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OllamaEmbeddingResponse struct {
|
type OllamaEmbeddingResponse struct {
|
||||||
Embedding any `json:"embedding,omitempty"`
|
Embedding any `json:"embedding,omitempty"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
Model string `json:"model"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"one-api/dto"
|
"one-api/dto"
|
||||||
"one-api/service"
|
"one-api/service"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func requestOpenAI2Ollama(request dto.GeneralOpenAIRequest) *OllamaRequest {
|
func requestOpenAI2Ollama(request dto.GeneralOpenAIRequest) *OllamaRequest {
|
||||||
@@ -45,8 +44,15 @@ func requestOpenAI2Ollama(request dto.GeneralOpenAIRequest) *OllamaRequest {
|
|||||||
|
|
||||||
func requestOpenAI2Embeddings(request dto.GeneralOpenAIRequest) *OllamaEmbeddingRequest {
|
func requestOpenAI2Embeddings(request dto.GeneralOpenAIRequest) *OllamaEmbeddingRequest {
|
||||||
return &OllamaEmbeddingRequest{
|
return &OllamaEmbeddingRequest{
|
||||||
Model: request.Model,
|
Model: request.Model,
|
||||||
Prompt: strings.Join(request.ParseInput(), " "),
|
Input: request.ParseInput(),
|
||||||
|
Options: &Options{
|
||||||
|
Seed: int(request.Seed),
|
||||||
|
Temperature: request.Temperature,
|
||||||
|
TopP: request.TopP,
|
||||||
|
FrequencyPenalty: request.FrequencyPenalty,
|
||||||
|
PresencePenalty: request.PresencePenalty,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +70,9 @@ func ollamaEmbeddingHandler(c *gin.Context, resp *http.Response, promptTokens in
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return service.OpenAIErrorWrapper(err, "unmarshal_response_body_failed", http.StatusInternalServerError), nil
|
return service.OpenAIErrorWrapper(err, "unmarshal_response_body_failed", http.StatusInternalServerError), nil
|
||||||
}
|
}
|
||||||
|
if ollamaEmbeddingResponse.Error != "" {
|
||||||
|
return service.OpenAIErrorWrapper(err, "ollama_error", resp.StatusCode), nil
|
||||||
|
}
|
||||||
data := make([]dto.OpenAIEmbeddingResponseItem, 0, 1)
|
data := make([]dto.OpenAIEmbeddingResponseItem, 0, 1)
|
||||||
data = append(data, dto.OpenAIEmbeddingResponseItem{
|
data = append(data, dto.OpenAIEmbeddingResponseItem{
|
||||||
Embedding: ollamaEmbeddingResponse.Embedding,
|
Embedding: ollamaEmbeddingResponse.Embedding,
|
||||||
|
|||||||
@@ -78,6 +78,12 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, info *relaycommon.RelayInfo, re
|
|||||||
if info.ChannelType != common.ChannelTypeOpenAI {
|
if info.ChannelType != common.ChannelTypeOpenAI {
|
||||||
request.StreamOptions = nil
|
request.StreamOptions = nil
|
||||||
}
|
}
|
||||||
|
if "o1" == request.Model || strings.HasPrefix(request.Model, "o1-") {
|
||||||
|
if request.MaxCompletionTokens == 0 && request.MaxTokens != 0 {
|
||||||
|
request.MaxCompletionTokens = request.MaxTokens
|
||||||
|
request.MaxTokens = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
return request, nil
|
return request, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ var ModelList = []string{
|
|||||||
"gpt-4-turbo-preview", "gpt-4-turbo", "gpt-4-turbo-2024-04-09",
|
"gpt-4-turbo-preview", "gpt-4-turbo", "gpt-4-turbo-2024-04-09",
|
||||||
"gpt-4-vision-preview",
|
"gpt-4-vision-preview",
|
||||||
"chatgpt-4o-latest",
|
"chatgpt-4o-latest",
|
||||||
"gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06",
|
"gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06", "gpt-4o-2024-08-06",
|
||||||
"gpt-4o-mini", "gpt-4o-mini-2024-07-18",
|
"gpt-4o-mini", "gpt-4o-mini-2024-07-18",
|
||||||
|
"o1-preview", "o1-preview-2024-09-12",
|
||||||
|
"o1-mini", "o1-mini-2024-09-12",
|
||||||
"text-embedding-ada-002", "text-embedding-3-small", "text-embedding-3-large",
|
"text-embedding-ada-002", "text-embedding-3-small", "text-embedding-3-large",
|
||||||
"text-curie-001", "text-babbage-001", "text-ada-001", "text-davinci-002", "text-davinci-003",
|
"text-curie-001", "text-babbage-001", "text-ada-001", "text-davinci-002", "text-davinci-003",
|
||||||
"text-moderation-latest", "text-moderation-stable",
|
"text-moderation-latest", "text-moderation-stable",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ type RelayInfo struct {
|
|||||||
setFirstResponse bool
|
setFirstResponse bool
|
||||||
ApiType int
|
ApiType int
|
||||||
IsStream bool
|
IsStream bool
|
||||||
|
IsPlayground bool
|
||||||
RelayMode int
|
RelayMode int
|
||||||
UpstreamModelName string
|
UpstreamModelName string
|
||||||
OriginModelName string
|
OriginModelName string
|
||||||
@@ -65,6 +66,11 @@ func GenRelayInfo(c *gin.Context) *RelayInfo {
|
|||||||
ApiKey: strings.TrimPrefix(c.Request.Header.Get("Authorization"), "Bearer "),
|
ApiKey: strings.TrimPrefix(c.Request.Header.Get("Authorization"), "Bearer "),
|
||||||
Organization: c.GetString("channel_organization"),
|
Organization: c.GetString("channel_organization"),
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(c.Request.URL.Path, "/pg") {
|
||||||
|
info.IsPlayground = true
|
||||||
|
info.RequestURLPath = strings.TrimPrefix(info.RequestURLPath, "/pg")
|
||||||
|
info.RequestURLPath = "/v1" + info.RequestURLPath
|
||||||
|
}
|
||||||
if info.BaseUrl == "" {
|
if info.BaseUrl == "" {
|
||||||
info.BaseUrl = common.ChannelBaseURLs[channelType]
|
info.BaseUrl = common.ChannelBaseURLs[channelType]
|
||||||
}
|
}
|
||||||
@@ -146,3 +152,20 @@ func GenTaskRelayInfo(c *gin.Context) *TaskRelayInfo {
|
|||||||
}
|
}
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (info *TaskRelayInfo) ToRelayInfo() *RelayInfo {
|
||||||
|
return &RelayInfo{
|
||||||
|
ChannelType: info.ChannelType,
|
||||||
|
ChannelId: info.ChannelId,
|
||||||
|
TokenId: info.TokenId,
|
||||||
|
UserId: info.UserId,
|
||||||
|
Group: info.Group,
|
||||||
|
StartTime: info.StartTime,
|
||||||
|
ApiType: info.ApiType,
|
||||||
|
RelayMode: info.RelayMode,
|
||||||
|
UpstreamModelName: info.UpstreamModelName,
|
||||||
|
RequestURLPath: info.RequestURLPath,
|
||||||
|
ApiKey: info.ApiKey,
|
||||||
|
BaseUrl: info.BaseUrl,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ const (
|
|||||||
|
|
||||||
func Path2RelayMode(path string) int {
|
func Path2RelayMode(path string) int {
|
||||||
relayMode := RelayModeUnknown
|
relayMode := RelayModeUnknown
|
||||||
if strings.HasPrefix(path, "/v1/chat/completions") {
|
if strings.HasPrefix(path, "/v1/chat/completions") || strings.HasPrefix(path, "/pg/chat/completions") {
|
||||||
relayMode = RelayModeChatCompletions
|
relayMode = RelayModeChatCompletions
|
||||||
} else if strings.HasPrefix(path, "/v1/completions") {
|
} else if strings.HasPrefix(path, "/v1/completions") {
|
||||||
relayMode = RelayModeCompletions
|
relayMode = RelayModeCompletions
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func AudioHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
|
|||||||
preConsumedQuota = 0
|
preConsumedQuota = 0
|
||||||
}
|
}
|
||||||
if preConsumedQuota > 0 {
|
if preConsumedQuota > 0 {
|
||||||
userQuota, err = model.PreConsumeTokenQuota(relayInfo.TokenId, preConsumedQuota)
|
userQuota, err = model.PreConsumeTokenQuota(relayInfo, preConsumedQuota)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return service.OpenAIErrorWrapperLocal(err, "pre_consume_token_quota_failed", http.StatusForbidden)
|
return service.OpenAIErrorWrapperLocal(err, "pre_consume_token_quota_failed", http.StatusForbidden)
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ func AudioHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
|
|||||||
statusCodeMappingStr := c.GetString("status_code_mapping")
|
statusCodeMappingStr := c.GetString("status_code_mapping")
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
returnPreConsumedQuota(c, relayInfo.TokenId, userQuota, preConsumedQuota)
|
returnPreConsumedQuota(c, relayInfo, userQuota, preConsumedQuota)
|
||||||
openaiErr := service.RelayErrorHandler(resp)
|
openaiErr := service.RelayErrorHandler(resp)
|
||||||
// reset status code 重置状态码
|
// reset status code 重置状态码
|
||||||
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
||||||
@@ -136,7 +136,7 @@ func AudioHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
|
|||||||
|
|
||||||
usage, openaiErr := adaptor.DoResponse(c, resp, relayInfo)
|
usage, openaiErr := adaptor.DoResponse(c, resp, relayInfo)
|
||||||
if openaiErr != nil {
|
if openaiErr != nil {
|
||||||
returnPreConsumedQuota(c, relayInfo.TokenId, userQuota, preConsumedQuota)
|
returnPreConsumedQuota(c, relayInfo, userQuota, preConsumedQuota)
|
||||||
// reset status code 重置状态码
|
// reset status code 重置状态码
|
||||||
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
||||||
return openaiErr
|
return openaiErr
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"one-api/constant"
|
"one-api/constant"
|
||||||
"one-api/dto"
|
"one-api/dto"
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
|
relaycommon "one-api/relay/common"
|
||||||
relayconstant "one-api/relay/constant"
|
relayconstant "one-api/relay/constant"
|
||||||
"one-api/service"
|
"one-api/service"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -146,6 +147,7 @@ func RelaySwapFace(c *gin.Context) *dto.MidjourneyResponse {
|
|||||||
userId := c.GetInt("id")
|
userId := c.GetInt("id")
|
||||||
group := c.GetString("group")
|
group := c.GetString("group")
|
||||||
channelId := c.GetInt("channel_id")
|
channelId := c.GetInt("channel_id")
|
||||||
|
relayInfo := relaycommon.GenRelayInfo(c)
|
||||||
var swapFaceRequest dto.SwapFaceRequest
|
var swapFaceRequest dto.SwapFaceRequest
|
||||||
err := common.UnmarshalBodyReusable(c, &swapFaceRequest)
|
err := common.UnmarshalBodyReusable(c, &swapFaceRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -191,7 +193,7 @@ func RelaySwapFace(c *gin.Context) *dto.MidjourneyResponse {
|
|||||||
}
|
}
|
||||||
defer func(ctx context.Context) {
|
defer func(ctx context.Context) {
|
||||||
if mjResp.StatusCode == 200 && mjResp.Response.Code == 1 {
|
if mjResp.StatusCode == 200 && mjResp.Response.Code == 1 {
|
||||||
err := model.PostConsumeTokenQuota(tokenId, userQuota, quota, 0, true)
|
err := model.PostConsumeTokenQuota(relayInfo, userQuota, quota, 0, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SysError("error consuming token remain quota: " + err.Error())
|
common.SysError("error consuming token remain quota: " + err.Error())
|
||||||
}
|
}
|
||||||
@@ -356,6 +358,7 @@ func RelayMidjourneySubmit(c *gin.Context, relayMode int) *dto.MidjourneyRespons
|
|||||||
userId := c.GetInt("id")
|
userId := c.GetInt("id")
|
||||||
group := c.GetString("group")
|
group := c.GetString("group")
|
||||||
channelId := c.GetInt("channel_id")
|
channelId := c.GetInt("channel_id")
|
||||||
|
relayInfo := relaycommon.GenRelayInfo(c)
|
||||||
consumeQuota := true
|
consumeQuota := true
|
||||||
var midjRequest dto.MidjourneyRequest
|
var midjRequest dto.MidjourneyRequest
|
||||||
err := common.UnmarshalBodyReusable(c, &midjRequest)
|
err := common.UnmarshalBodyReusable(c, &midjRequest)
|
||||||
@@ -495,7 +498,7 @@ func RelayMidjourneySubmit(c *gin.Context, relayMode int) *dto.MidjourneyRespons
|
|||||||
|
|
||||||
defer func(ctx context.Context) {
|
defer func(ctx context.Context) {
|
||||||
if consumeQuota && midjResponseWithStatus.StatusCode == 200 {
|
if consumeQuota && midjResponseWithStatus.StatusCode == 200 {
|
||||||
err := model.PostConsumeTokenQuota(tokenId, userQuota, quota, 0, true)
|
err := model.PostConsumeTokenQuota(relayInfo, userQuota, quota, 0, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SysError("error consuming token remain quota: " + err.Error())
|
common.SysError("error consuming token remain quota: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// map model name
|
// map model name
|
||||||
|
isModelMapped := false
|
||||||
modelMapping := c.GetString("model_mapping")
|
modelMapping := c.GetString("model_mapping")
|
||||||
//isModelMapped := false
|
//isModelMapped := false
|
||||||
if modelMapping != "" && modelMapping != "{}" {
|
if modelMapping != "" && modelMapping != "{}" {
|
||||||
@@ -85,6 +86,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
|
|||||||
return service.OpenAIErrorWrapperLocal(err, "unmarshal_model_mapping_failed", http.StatusInternalServerError)
|
return service.OpenAIErrorWrapperLocal(err, "unmarshal_model_mapping_failed", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
if modelMap[textRequest.Model] != "" {
|
if modelMap[textRequest.Model] != "" {
|
||||||
|
isModelMapped = true
|
||||||
textRequest.Model = modelMap[textRequest.Model]
|
textRequest.Model = modelMap[textRequest.Model]
|
||||||
// set upstream model name
|
// set upstream model name
|
||||||
//isModelMapped = true
|
//isModelMapped = true
|
||||||
@@ -159,15 +161,23 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
|
|||||||
adaptor.Init(relayInfo)
|
adaptor.Init(relayInfo)
|
||||||
var requestBody io.Reader
|
var requestBody io.Reader
|
||||||
|
|
||||||
convertedRequest, err := adaptor.ConvertRequest(c, relayInfo, textRequest)
|
if relayInfo.ChannelType == common.ChannelTypeOpenAI && !isModelMapped {
|
||||||
if err != nil {
|
body, err := common.GetRequestBody(c)
|
||||||
return service.OpenAIErrorWrapperLocal(err, "convert_request_failed", http.StatusInternalServerError)
|
if err != nil {
|
||||||
|
return service.OpenAIErrorWrapperLocal(err, "get_request_body_failed", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
requestBody = bytes.NewBuffer(body)
|
||||||
|
} else {
|
||||||
|
convertedRequest, err := adaptor.ConvertRequest(c, relayInfo, textRequest)
|
||||||
|
if err != nil {
|
||||||
|
return service.OpenAIErrorWrapperLocal(err, "convert_request_failed", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
jsonData, err := json.Marshal(convertedRequest)
|
||||||
|
if err != nil {
|
||||||
|
return service.OpenAIErrorWrapperLocal(err, "json_marshal_failed", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
requestBody = bytes.NewBuffer(jsonData)
|
||||||
}
|
}
|
||||||
jsonData, err := json.Marshal(convertedRequest)
|
|
||||||
if err != nil {
|
|
||||||
return service.OpenAIErrorWrapperLocal(err, "json_marshal_failed", http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
requestBody = bytes.NewBuffer(jsonData)
|
|
||||||
|
|
||||||
statusCodeMappingStr := c.GetString("status_code_mapping")
|
statusCodeMappingStr := c.GetString("status_code_mapping")
|
||||||
resp, err := adaptor.DoRequest(c, relayInfo, requestBody)
|
resp, err := adaptor.DoRequest(c, relayInfo, requestBody)
|
||||||
@@ -178,7 +188,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
|
|||||||
if resp != nil {
|
if resp != nil {
|
||||||
relayInfo.IsStream = relayInfo.IsStream || strings.HasPrefix(resp.Header.Get("Content-Type"), "text/event-stream")
|
relayInfo.IsStream = relayInfo.IsStream || strings.HasPrefix(resp.Header.Get("Content-Type"), "text/event-stream")
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
returnPreConsumedQuota(c, relayInfo.TokenId, userQuota, preConsumedQuota)
|
returnPreConsumedQuota(c, relayInfo, userQuota, preConsumedQuota)
|
||||||
openaiErr := service.RelayErrorHandler(resp)
|
openaiErr := service.RelayErrorHandler(resp)
|
||||||
// reset status code 重置状态码
|
// reset status code 重置状态码
|
||||||
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
||||||
@@ -188,7 +198,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
|
|||||||
|
|
||||||
usage, openaiErr := adaptor.DoResponse(c, resp, relayInfo)
|
usage, openaiErr := adaptor.DoResponse(c, resp, relayInfo)
|
||||||
if openaiErr != nil {
|
if openaiErr != nil {
|
||||||
returnPreConsumedQuota(c, relayInfo.TokenId, userQuota, preConsumedQuota)
|
returnPreConsumedQuota(c, relayInfo, userQuota, preConsumedQuota)
|
||||||
// reset status code 重置状态码
|
// reset status code 重置状态码
|
||||||
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
||||||
return openaiErr
|
return openaiErr
|
||||||
@@ -275,7 +285,7 @@ func preConsumeQuota(c *gin.Context, preConsumedQuota int, relayInfo *relaycommo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if preConsumedQuota > 0 {
|
if preConsumedQuota > 0 {
|
||||||
userQuota, err = model.PreConsumeTokenQuota(relayInfo.TokenId, preConsumedQuota)
|
userQuota, err = model.PreConsumeTokenQuota(relayInfo, preConsumedQuota)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, service.OpenAIErrorWrapperLocal(err, "pre_consume_token_quota_failed", http.StatusForbidden)
|
return 0, 0, service.OpenAIErrorWrapperLocal(err, "pre_consume_token_quota_failed", http.StatusForbidden)
|
||||||
}
|
}
|
||||||
@@ -283,11 +293,11 @@ func preConsumeQuota(c *gin.Context, preConsumedQuota int, relayInfo *relaycommo
|
|||||||
return preConsumedQuota, userQuota, nil
|
return preConsumedQuota, userQuota, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func returnPreConsumedQuota(c *gin.Context, tokenId int, userQuota int, preConsumedQuota int) {
|
func returnPreConsumedQuota(c *gin.Context, relayInfo *relaycommon.RelayInfo, userQuota int, preConsumedQuota int) {
|
||||||
if preConsumedQuota != 0 {
|
if preConsumedQuota != 0 {
|
||||||
go func(ctx context.Context) {
|
go func(ctx context.Context) {
|
||||||
// return pre-consumed quota
|
// return pre-consumed quota
|
||||||
err := model.PostConsumeTokenQuota(tokenId, userQuota, -preConsumedQuota, 0, false)
|
err := model.PostConsumeTokenQuota(relayInfo, userQuota, -preConsumedQuota, 0, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SysError("error return pre-consumed quota: " + err.Error())
|
common.SysError("error return pre-consumed quota: " + err.Error())
|
||||||
}
|
}
|
||||||
@@ -345,7 +355,7 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, modelN
|
|||||||
//}
|
//}
|
||||||
quotaDelta := quota - preConsumedQuota
|
quotaDelta := quota - preConsumedQuota
|
||||||
if quotaDelta != 0 {
|
if quotaDelta != 0 {
|
||||||
err := model.PostConsumeTokenQuota(relayInfo.TokenId, userQuota, quotaDelta, preConsumedQuota, true)
|
err := model.PostConsumeTokenQuota(relayInfo, userQuota, quotaDelta, preConsumedQuota, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogError(ctx, "error consuming token remain quota: "+err.Error())
|
common.LogError(ctx, "error consuming token remain quota: "+err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func RerankHelper(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode
|
|||||||
}
|
}
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
returnPreConsumedQuota(c, relayInfo.TokenId, userQuota, preConsumedQuota)
|
returnPreConsumedQuota(c, relayInfo, userQuota, preConsumedQuota)
|
||||||
openaiErr := service.RelayErrorHandler(resp)
|
openaiErr := service.RelayErrorHandler(resp)
|
||||||
// reset status code 重置状态码
|
// reset status code 重置状态码
|
||||||
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
||||||
@@ -111,7 +111,7 @@ func RerankHelper(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode
|
|||||||
|
|
||||||
usage, openaiErr := adaptor.DoResponse(c, resp, relayInfo)
|
usage, openaiErr := adaptor.DoResponse(c, resp, relayInfo)
|
||||||
if openaiErr != nil {
|
if openaiErr != nil {
|
||||||
returnPreConsumedQuota(c, relayInfo.TokenId, userQuota, preConsumedQuota)
|
returnPreConsumedQuota(c, relayInfo, userQuota, preConsumedQuota)
|
||||||
// reset status code 重置状态码
|
// reset status code 重置状态码
|
||||||
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
service.ResetStatusCode(openaiErr, statusCodeMappingStr)
|
||||||
return openaiErr
|
return openaiErr
|
||||||
|
|||||||
@@ -111,7 +111,8 @@ func RelayTaskSubmit(c *gin.Context, relayMode int) (taskErr *dto.TaskError) {
|
|||||||
defer func(ctx context.Context) {
|
defer func(ctx context.Context) {
|
||||||
// release quota
|
// release quota
|
||||||
if relayInfo.ConsumeQuota && taskErr == nil {
|
if relayInfo.ConsumeQuota && taskErr == nil {
|
||||||
err := model.PostConsumeTokenQuota(relayInfo.TokenId, userQuota, quota, 0, true)
|
|
||||||
|
err := model.PostConsumeTokenQuota(relayInfo.ToRelayInfo(), userQuota, quota, 0, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SysError("error consuming token remain quota: " + err.Error())
|
common.SysError("error consuming token remain quota: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,10 +41,12 @@ func SetApiRouter(router *gin.Engine) {
|
|||||||
userRoute.POST("/login", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Login)
|
userRoute.POST("/login", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Login)
|
||||||
//userRoute.POST("/tokenlog", middleware.CriticalRateLimit(), controller.TokenLog)
|
//userRoute.POST("/tokenlog", middleware.CriticalRateLimit(), controller.TokenLog)
|
||||||
userRoute.GET("/logout", controller.Logout)
|
userRoute.GET("/logout", controller.Logout)
|
||||||
|
userRoute.GET("/groups", controller.GetUserGroups)
|
||||||
|
|
||||||
selfRoute := userRoute.Group("/")
|
selfRoute := userRoute.Group("/")
|
||||||
selfRoute.Use(middleware.UserAuth())
|
selfRoute.Use(middleware.UserAuth())
|
||||||
{
|
{
|
||||||
|
selfRoute.GET("/self/groups", controller.GetUserGroups)
|
||||||
selfRoute.GET("/self", controller.GetSelf)
|
selfRoute.GET("/self", controller.GetSelf)
|
||||||
selfRoute.GET("/models", controller.GetUserModels)
|
selfRoute.GET("/models", controller.GetUserModels)
|
||||||
selfRoute.PUT("/self", controller.UpdateSelf)
|
selfRoute.PUT("/self", controller.UpdateSelf)
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ func SetRelayRouter(router *gin.Engine) {
|
|||||||
modelsRouter.GET("", controller.ListModels)
|
modelsRouter.GET("", controller.ListModels)
|
||||||
modelsRouter.GET("/:model", controller.RetrieveModel)
|
modelsRouter.GET("/:model", controller.RetrieveModel)
|
||||||
}
|
}
|
||||||
|
playgroundRouter := router.Group("/pg")
|
||||||
|
playgroundRouter.Use(middleware.UserAuth())
|
||||||
|
{
|
||||||
|
playgroundRouter.POST("/chat/completions", controller.Playground)
|
||||||
|
}
|
||||||
relayV1Router := router.Group("/v1")
|
relayV1Router := router.Group("/v1")
|
||||||
relayV1Router.Use(middleware.TokenAuth(), middleware.Distribute())
|
relayV1Router.Use(middleware.TokenAuth(), middleware.Distribute())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,6 +73,15 @@ func ShouldDisableChannel(channelType int, err *relaymodel.OpenAIErrorWithStatus
|
|||||||
} else if strings.HasPrefix(err.Error.Message, "Permission denied") {
|
} else if strings.HasPrefix(err.Error.Message, "Permission denied") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(err.Error.Message, "The security token included in the request is invalid") { // anthropic
|
||||||
|
return true
|
||||||
|
} else if strings.Contains(err.Error.Message, "Operation not allowed") {
|
||||||
|
return true
|
||||||
|
} else if strings.Contains(err.Error.Message, "Your account is not authorized") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ func InitTokenEncoders() {
|
|||||||
tokenEncoderMap[model] = gpt35TokenEncoder
|
tokenEncoderMap[model] = gpt35TokenEncoder
|
||||||
} else if strings.HasPrefix(model, "gpt-4o") {
|
} else if strings.HasPrefix(model, "gpt-4o") {
|
||||||
tokenEncoderMap[model] = gpt4oTokenEncoder
|
tokenEncoderMap[model] = gpt4oTokenEncoder
|
||||||
|
} else if strings.HasPrefix(model, "chatgpt-4o") {
|
||||||
|
tokenEncoderMap[model] = gpt4oTokenEncoder
|
||||||
|
} else if "o1" == model || strings.HasPrefix(model, "o1") {
|
||||||
|
tokenEncoderMap[model] = gpt4oTokenEncoder
|
||||||
} else if strings.HasPrefix(model, "gpt-4") {
|
} else if strings.HasPrefix(model, "gpt-4") {
|
||||||
tokenEncoderMap[model] = gpt4TokenEncoder
|
tokenEncoderMap[model] = gpt4TokenEncoder
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@douyinfe/semi-icons": "^2.46.1",
|
"@douyinfe/semi-icons": "^2.63.1",
|
||||||
"@douyinfe/semi-ui": "^2.55.3",
|
"@douyinfe/semi-ui": "^2.63.1",
|
||||||
"@visactor/react-vchart": "~1.8.8",
|
"@visactor/react-vchart": "~1.8.8",
|
||||||
"@visactor/vchart": "~1.8.8",
|
"@visactor/vchart": "~1.8.8",
|
||||||
"@visactor/vchart-semi-theme": "~1.8.8",
|
"@visactor/vchart-semi-theme": "~1.8.8",
|
||||||
@@ -22,7 +22,8 @@
|
|||||||
"react-toastify": "^9.0.8",
|
"react-toastify": "^9.0.8",
|
||||||
"react-turnstile": "^1.0.5",
|
"react-turnstile": "^1.0.5",
|
||||||
"semantic-ui-offline": "^2.5.0",
|
"semantic-ui-offline": "^2.5.0",
|
||||||
"semantic-ui-react": "^2.1.3"
|
"semantic-ui-react": "^2.1.3",
|
||||||
|
"sse": "github:mpetazzoni/sse.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
@@ -54,7 +55,7 @@
|
|||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
"prettier": "^3.0.0",
|
"prettier": "^3.0.0",
|
||||||
"typescript": "4.4.2",
|
"typescript": "4.4.2",
|
||||||
"vite": "^5.2.0"
|
"vite": "^5.4.14"
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
|
|||||||
4752
web/pnpm-lock.yaml
generated
4752
web/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
414
web/src/App.js
414
web/src/App.js
@@ -21,11 +21,12 @@ import Redemption from './pages/Redemption';
|
|||||||
import TopUp from './pages/TopUp';
|
import TopUp from './pages/TopUp';
|
||||||
import Log from './pages/Log';
|
import Log from './pages/Log';
|
||||||
import Chat from './pages/Chat';
|
import Chat from './pages/Chat';
|
||||||
|
import Chat2Link from './pages/Chat2Link';
|
||||||
import { Layout } from '@douyinfe/semi-ui';
|
import { Layout } from '@douyinfe/semi-ui';
|
||||||
import Midjourney from './pages/Midjourney';
|
import Midjourney from './pages/Midjourney';
|
||||||
import Pricing from './pages/Pricing/index.js';
|
import Pricing from './pages/Pricing/index.js';
|
||||||
import Task from './pages/Task/index.js';
|
import Task from './pages/Task/index.js';
|
||||||
// import Detail from './pages/Detail';
|
import Playground from './components/Playground.js';
|
||||||
|
|
||||||
const Home = lazy(() => import('./pages/Home'));
|
const Home = lazy(() => import('./pages/Home'));
|
||||||
const Detail = lazy(() => import('./pages/Detail'));
|
const Detail = lazy(() => import('./pages/Detail'));
|
||||||
@@ -59,215 +60,232 @@ function App() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<>
|
||||||
<Layout.Content>
|
<Routes>
|
||||||
<Routes>
|
<Route
|
||||||
<Route
|
path='/'
|
||||||
path='/'
|
element={
|
||||||
element={
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<Home />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/channel'
|
||||||
|
element={
|
||||||
|
<PrivateRoute>
|
||||||
|
<Channel />
|
||||||
|
</PrivateRoute>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/channel/edit/:id'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<EditChannel />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/channel/add'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<EditChannel />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/token'
|
||||||
|
element={
|
||||||
|
<PrivateRoute>
|
||||||
|
<Token />
|
||||||
|
</PrivateRoute>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/playground'
|
||||||
|
element={
|
||||||
|
<PrivateRoute>
|
||||||
|
<Playground />
|
||||||
|
</PrivateRoute>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/redemption'
|
||||||
|
element={
|
||||||
|
<PrivateRoute>
|
||||||
|
<Redemption />
|
||||||
|
</PrivateRoute>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/user'
|
||||||
|
element={
|
||||||
|
<PrivateRoute>
|
||||||
|
<User />
|
||||||
|
</PrivateRoute>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/user/edit/:id'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<EditUser />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/user/edit'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<EditUser />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/user/reset'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<PasswordResetConfirm />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/login'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<LoginForm />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/register'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<RegisterForm />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/reset'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<PasswordResetForm />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/oauth/github'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<GitHubOAuth />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/oauth/linuxdo'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<LinuxDoOAuth />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/setting'
|
||||||
|
element={
|
||||||
|
<PrivateRoute>
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
<Home />
|
<Setting />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
</PrivateRoute>
|
||||||
/>
|
}
|
||||||
<Route
|
/>
|
||||||
path='/channel'
|
<Route
|
||||||
element={
|
path='/topup'
|
||||||
<PrivateRoute>
|
element={
|
||||||
<Channel />
|
<PrivateRoute>
|
||||||
</PrivateRoute>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/channel/edit/:id'
|
|
||||||
element={
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
<EditChannel />
|
<TopUp />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
</PrivateRoute>
|
||||||
/>
|
}
|
||||||
<Route
|
/>
|
||||||
path='/channel/add'
|
<Route
|
||||||
element={
|
path='/log'
|
||||||
|
element={
|
||||||
|
<PrivateRoute>
|
||||||
|
<Log />
|
||||||
|
</PrivateRoute>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/detail'
|
||||||
|
element={
|
||||||
|
<PrivateRoute>
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
<EditChannel />
|
<Detail />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
</PrivateRoute>
|
||||||
/>
|
}
|
||||||
<Route
|
/>
|
||||||
path='/token'
|
<Route
|
||||||
element={
|
path='/midjourney'
|
||||||
<PrivateRoute>
|
element={
|
||||||
<Token />
|
<PrivateRoute>
|
||||||
</PrivateRoute>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/redemption'
|
|
||||||
element={
|
|
||||||
<PrivateRoute>
|
|
||||||
<Redemption />
|
|
||||||
</PrivateRoute>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/user'
|
|
||||||
element={
|
|
||||||
<PrivateRoute>
|
|
||||||
<User />
|
|
||||||
</PrivateRoute>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/user/edit/:id'
|
|
||||||
element={
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
<EditUser />
|
<Midjourney />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
</PrivateRoute>
|
||||||
/>
|
}
|
||||||
<Route
|
/>
|
||||||
path='/user/edit'
|
<Route
|
||||||
element={
|
path='/task'
|
||||||
|
element={
|
||||||
|
<PrivateRoute>
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
<EditUser />
|
<Task />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
</PrivateRoute>
|
||||||
/>
|
}
|
||||||
<Route
|
/>
|
||||||
path='/user/reset'
|
<Route
|
||||||
element={
|
path='/pricing'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<Pricing />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/about'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<About />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/chat/:id?'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<Chat />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
{/* 方便使用chat2link直接跳转聊天... */}
|
||||||
|
<Route
|
||||||
|
path='/chat2link'
|
||||||
|
element={
|
||||||
|
<PrivateRoute>
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
<PasswordResetConfirm />
|
<Chat2Link />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
</PrivateRoute>
|
||||||
/>
|
}
|
||||||
<Route
|
/>
|
||||||
path='/login'
|
<Route path='*' element={<NotFound />} />
|
||||||
element={
|
</Routes>
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
</>
|
||||||
<LoginForm />
|
|
||||||
</Suspense>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/register'
|
|
||||||
element={
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<RegisterForm />
|
|
||||||
</Suspense>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/reset'
|
|
||||||
element={
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<PasswordResetForm />
|
|
||||||
</Suspense>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/oauth/github'
|
|
||||||
element={
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<GitHubOAuth />
|
|
||||||
</Suspense>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/oauth/linuxdo'
|
|
||||||
element={
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<LinuxDoOAuth />
|
|
||||||
</Suspense>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/setting'
|
|
||||||
element={
|
|
||||||
<PrivateRoute>
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<Setting />
|
|
||||||
</Suspense>
|
|
||||||
</PrivateRoute>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/topup'
|
|
||||||
element={
|
|
||||||
<PrivateRoute>
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<TopUp />
|
|
||||||
</Suspense>
|
|
||||||
</PrivateRoute>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/log'
|
|
||||||
element={
|
|
||||||
<PrivateRoute>
|
|
||||||
<Log />
|
|
||||||
</PrivateRoute>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/detail'
|
|
||||||
element={
|
|
||||||
<PrivateRoute>
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<Detail />
|
|
||||||
</Suspense>
|
|
||||||
</PrivateRoute>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/midjourney'
|
|
||||||
element={
|
|
||||||
<PrivateRoute>
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<Midjourney />
|
|
||||||
</Suspense>
|
|
||||||
</PrivateRoute>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/task'
|
|
||||||
element={
|
|
||||||
<PrivateRoute>
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<Task />
|
|
||||||
</Suspense>
|
|
||||||
</PrivateRoute>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/pricing'
|
|
||||||
element={
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<Pricing />
|
|
||||||
</Suspense>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/about'
|
|
||||||
element={
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<About />
|
|
||||||
</Suspense>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/chat'
|
|
||||||
element={
|
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
|
||||||
<Chat />
|
|
||||||
</Suspense>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route path='*' element={<NotFound />} />
|
|
||||||
</Routes>
|
|
||||||
</Layout.Content>
|
|
||||||
</Layout>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react';
|
|||||||
import { getFooterHTML, getSystemName } from '../helpers';
|
import { getFooterHTML, getSystemName } from '../helpers';
|
||||||
import { Layout, Tooltip } from '@douyinfe/semi-ui';
|
import { Layout, Tooltip } from '@douyinfe/semi-ui';
|
||||||
|
|
||||||
const Footer = () => {
|
const FooterBar = () => {
|
||||||
const systemName = getSystemName();
|
const systemName = getSystemName();
|
||||||
const [footer, setFooter] = useState(getFooterHTML());
|
const [footer, setFooter] = useState(getFooterHTML());
|
||||||
let remainCheckTimes = 5;
|
let remainCheckTimes = 5;
|
||||||
@@ -52,21 +52,17 @@ const Footer = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<div style={{ textAlign: 'center' }}>
|
||||||
<Layout.Content style={{ textAlign: 'center' }}>
|
{footer ? (
|
||||||
{footer ? (
|
<div
|
||||||
<Tooltip content={defaultFooter}>
|
className='custom-footer'
|
||||||
<div
|
dangerouslySetInnerHTML={{ __html: footer }}
|
||||||
className='custom-footer'
|
></div>
|
||||||
dangerouslySetInnerHTML={{ __html: footer }}
|
) : (
|
||||||
></div>
|
defaultFooter
|
||||||
</Tooltip>
|
)}
|
||||||
) : (
|
</div>
|
||||||
defaultFooter
|
|
||||||
)}
|
|
||||||
</Layout.Content>
|
|
||||||
</Layout>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Footer;
|
export default FooterBar;
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import React, { useContext, useEffect, useState } from 'react';
|
import React, { useContext, useEffect, useState } from 'react';
|
||||||
import { Dimmer, Loader, Segment } from 'semantic-ui-react';
|
import { Dimmer, Loader, Segment } from 'semantic-ui-react';
|
||||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import { API, showError, showSuccess } from '../helpers';
|
import { API, showError, showSuccess, updateAPI } from '../helpers';
|
||||||
import { UserContext } from '../context/User';
|
import { UserContext } from '../context/User';
|
||||||
|
import { setUserData } from '../helpers/data.js';
|
||||||
|
|
||||||
const GitHubOAuth = () => {
|
const GitHubOAuth = () => {
|
||||||
const [searchParams, setSearchParams] = useSearchParams();
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
@@ -28,8 +29,10 @@ const GitHubOAuth = () => {
|
|||||||
} else {
|
} else {
|
||||||
userDispatch({ type: 'login', payload: data });
|
userDispatch({ type: 'login', payload: data });
|
||||||
localStorage.setItem('user', JSON.stringify(data));
|
localStorage.setItem('user', JSON.stringify(data));
|
||||||
|
setUserData(data);
|
||||||
|
updateAPI();
|
||||||
showSuccess('登录成功!');
|
showSuccess('登录成功!');
|
||||||
navigate('/');
|
navigate('/token');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showError(message);
|
showError(message);
|
||||||
|
|||||||
@@ -3,14 +3,23 @@ import { Link, useNavigate } from 'react-router-dom';
|
|||||||
import { UserContext } from '../context/User';
|
import { UserContext } from '../context/User';
|
||||||
import { useSetTheme, useTheme } from '../context/Theme';
|
import { useSetTheme, useTheme } from '../context/Theme';
|
||||||
|
|
||||||
import { API, getLogo, getSystemName, showSuccess } from '../helpers';
|
import { API, getLogo, getSystemName, isMobile, showSuccess } from '../helpers';
|
||||||
import '../index.css';
|
import '../index.css';
|
||||||
|
|
||||||
import fireworks from 'react-fireworks';
|
import fireworks from 'react-fireworks';
|
||||||
|
|
||||||
import { IconHelpCircle, IconKey, IconUser } from '@douyinfe/semi-icons';
|
import {
|
||||||
|
IconHelpCircle,
|
||||||
|
IconHome,
|
||||||
|
IconHomeStroked,
|
||||||
|
IconKey,
|
||||||
|
IconNoteMoneyStroked,
|
||||||
|
IconPriceTag,
|
||||||
|
IconUser,
|
||||||
|
} from '@douyinfe/semi-icons';
|
||||||
import { Avatar, Dropdown, Layout, Nav, Switch } from '@douyinfe/semi-ui';
|
import { Avatar, Dropdown, Layout, Nav, Switch } from '@douyinfe/semi-ui';
|
||||||
import { stringToColor } from '../helpers/render';
|
import { stringToColor } from '../helpers/render';
|
||||||
|
import Text from '@douyinfe/semi-ui/lib/es/typography/text';
|
||||||
|
|
||||||
// HeaderBar Buttons
|
// HeaderBar Buttons
|
||||||
let headerButtons = [
|
let headerButtons = [
|
||||||
@@ -22,6 +31,21 @@ let headerButtons = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let buttons = [
|
||||||
|
{
|
||||||
|
text: '首页',
|
||||||
|
itemKey: 'home',
|
||||||
|
to: '/',
|
||||||
|
// icon: <IconHomeStroked />,
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// text: 'Playground',
|
||||||
|
// itemKey: 'playground',
|
||||||
|
// to: '/playground',
|
||||||
|
// // icon: <IconNoteMoneyStroked />,
|
||||||
|
// },
|
||||||
|
];
|
||||||
|
|
||||||
if (localStorage.getItem('chat_link')) {
|
if (localStorage.getItem('chat_link')) {
|
||||||
headerButtons.splice(1, 0, {
|
headerButtons.splice(1, 0, {
|
||||||
name: '聊天',
|
name: '聊天',
|
||||||
@@ -90,6 +114,7 @@ const HeaderBar = () => {
|
|||||||
about: '/about',
|
about: '/about',
|
||||||
login: '/login',
|
login: '/login',
|
||||||
register: '/register',
|
register: '/register',
|
||||||
|
home: '/',
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
@@ -103,6 +128,23 @@ const HeaderBar = () => {
|
|||||||
selectedKeys={[]}
|
selectedKeys={[]}
|
||||||
// items={headerButtons}
|
// items={headerButtons}
|
||||||
onSelect={(key) => {}}
|
onSelect={(key) => {}}
|
||||||
|
header={
|
||||||
|
isMobile()
|
||||||
|
? {
|
||||||
|
logo: (
|
||||||
|
<img
|
||||||
|
src={logo}
|
||||||
|
alt='logo'
|
||||||
|
style={{ marginRight: '0.75em' }}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
logo: <img src={logo} alt='logo' />,
|
||||||
|
text: systemName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
items={buttons}
|
||||||
footer={
|
footer={
|
||||||
<>
|
<>
|
||||||
{isNewYear && (
|
{isNewYear && (
|
||||||
@@ -121,15 +163,19 @@ const HeaderBar = () => {
|
|||||||
</Dropdown>
|
</Dropdown>
|
||||||
)}
|
)}
|
||||||
<Nav.Item itemKey={'about'} icon={<IconHelpCircle />} />
|
<Nav.Item itemKey={'about'} icon={<IconHelpCircle />} />
|
||||||
<Switch
|
<>
|
||||||
checkedText='🌞'
|
{!isMobile() && (
|
||||||
size={'large'}
|
<Switch
|
||||||
checked={theme === 'dark'}
|
checkedText='🌞'
|
||||||
uncheckedText='🌙'
|
size={'large'}
|
||||||
onChange={(checked) => {
|
checked={theme === 'dark'}
|
||||||
setTheme(checked);
|
uncheckedText='🌙'
|
||||||
}}
|
onChange={(checked) => {
|
||||||
/>
|
setTheme(checked);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
{userState.user ? (
|
{userState.user ? (
|
||||||
<>
|
<>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
@@ -155,7 +201,7 @@ const HeaderBar = () => {
|
|||||||
<Nav.Item
|
<Nav.Item
|
||||||
itemKey={'login'}
|
itemKey={'login'}
|
||||||
text={'登录'}
|
text={'登录'}
|
||||||
icon={<IconKey />}
|
// icon={<IconKey />}
|
||||||
/>
|
/>
|
||||||
<Nav.Item
|
<Nav.Item
|
||||||
itemKey={'register'}
|
itemKey={'register'}
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ const LoginForm = () => {
|
|||||||
if (success) {
|
if (success) {
|
||||||
userDispatch({ type: 'login', payload: data });
|
userDispatch({ type: 'login', payload: data });
|
||||||
localStorage.setItem('user', JSON.stringify(data));
|
localStorage.setItem('user', JSON.stringify(data));
|
||||||
|
setUserData(data);
|
||||||
|
updateAPI();
|
||||||
navigate('/');
|
navigate('/');
|
||||||
showSuccess('登录成功!');
|
showSuccess('登录成功!');
|
||||||
setShowWeChatLoginModal(false);
|
setShowWeChatLoginModal(false);
|
||||||
@@ -151,6 +153,8 @@ const LoginForm = () => {
|
|||||||
userDispatch({ type: 'login', payload: data });
|
userDispatch({ type: 'login', payload: data });
|
||||||
localStorage.setItem('user', JSON.stringify(data));
|
localStorage.setItem('user', JSON.stringify(data));
|
||||||
showSuccess('登录成功!');
|
showSuccess('登录成功!');
|
||||||
|
setUserData(data);
|
||||||
|
updateAPI();
|
||||||
navigate('/');
|
navigate('/');
|
||||||
} else {
|
} else {
|
||||||
showError(message);
|
showError(message);
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ const LogsTable = () => {
|
|||||||
title: '类型',
|
title: '类型',
|
||||||
dataIndex: 'type',
|
dataIndex: 'type',
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return <div>{renderType(text)}</div>;
|
return <>{renderType(text)}</>;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -258,7 +258,7 @@ const LogsTable = () => {
|
|||||||
dataIndex: 'model_name',
|
dataIndex: 'model_name',
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return record.type === 0 || record.type === 2 ? (
|
return record.type === 0 || record.type === 2 ? (
|
||||||
<div>
|
<>
|
||||||
<Tag
|
<Tag
|
||||||
color={stringToColor(text)}
|
color={stringToColor(text)}
|
||||||
size='large'
|
size='large'
|
||||||
@@ -269,7 +269,7 @@ const LogsTable = () => {
|
|||||||
{' '}
|
{' '}
|
||||||
{text}{' '}
|
{text}{' '}
|
||||||
</Tag>
|
</Tag>
|
||||||
</div>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
);
|
);
|
||||||
@@ -282,22 +282,22 @@ const LogsTable = () => {
|
|||||||
if (record.is_stream) {
|
if (record.is_stream) {
|
||||||
let other = getLogOther(record.other);
|
let other = getLogOther(record.other);
|
||||||
return (
|
return (
|
||||||
<div>
|
<>
|
||||||
<Space>
|
<Space>
|
||||||
{renderUseTime(text)}
|
{renderUseTime(text)}
|
||||||
{renderFirstUseTime(other.frt)}
|
{renderFirstUseTime(other.frt)}
|
||||||
{renderIsStream(record.is_stream)}
|
{renderIsStream(record.is_stream)}
|
||||||
</Space>
|
</Space>
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<div>
|
<>
|
||||||
<Space>
|
<Space>
|
||||||
{renderUseTime(text)}
|
{renderUseTime(text)}
|
||||||
{renderIsStream(record.is_stream)}
|
{renderIsStream(record.is_stream)}
|
||||||
</Space>
|
</Space>
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -307,7 +307,7 @@ const LogsTable = () => {
|
|||||||
dataIndex: 'prompt_tokens',
|
dataIndex: 'prompt_tokens',
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return record.type === 0 || record.type === 2 ? (
|
return record.type === 0 || record.type === 2 ? (
|
||||||
<div>{<span> {text} </span>}</div>
|
<>{<span> {text} </span>}</>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
);
|
);
|
||||||
@@ -319,7 +319,7 @@ const LogsTable = () => {
|
|||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return parseInt(text) > 0 &&
|
return parseInt(text) > 0 &&
|
||||||
(record.type === 0 || record.type === 2) ? (
|
(record.type === 0 || record.type === 2) ? (
|
||||||
<div>{<span> {text} </span>}</div>
|
<>{<span> {text} </span>}</>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
);
|
);
|
||||||
@@ -330,7 +330,7 @@ const LogsTable = () => {
|
|||||||
dataIndex: 'quota',
|
dataIndex: 'quota',
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return record.type === 0 || record.type === 2 ? (
|
return record.type === 0 || record.type === 2 ? (
|
||||||
<div>{renderQuota(text, 6)}</div>
|
<>{renderQuota(text, 6)}</>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useContext, useEffect, useRef, useMemo, useState } from 'react';
|
import React, { useContext, useEffect, useRef, useMemo, useState } from 'react';
|
||||||
import { API, copy, showError, showSuccess } from '../helpers';
|
import { API, copy, showError, showInfo, showSuccess } from '../helpers';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Banner,
|
Banner,
|
||||||
@@ -83,6 +83,7 @@ const ModelPricing = () => {
|
|||||||
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
||||||
const [modalImageUrl, setModalImageUrl] = useState('');
|
const [modalImageUrl, setModalImageUrl] = useState('');
|
||||||
const [isModalOpenurl, setIsModalOpenurl] = useState(false);
|
const [isModalOpenurl, setIsModalOpenurl] = useState(false);
|
||||||
|
const [selectedGroup, setSelectedGroup] = useState('default');
|
||||||
|
|
||||||
const rowSelection = useMemo(
|
const rowSelection = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
@@ -116,7 +117,8 @@ const ModelPricing = () => {
|
|||||||
title: '可用性',
|
title: '可用性',
|
||||||
dataIndex: 'available',
|
dataIndex: 'available',
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return renderAvailable(text);
|
// if record.enable_groups contains selectedGroup, then available is true
|
||||||
|
return renderAvailable(record.enable_groups.includes(selectedGroup));
|
||||||
},
|
},
|
||||||
sorter: (a, b) => a.available - b.available,
|
sorter: (a, b) => a.available - b.available,
|
||||||
},
|
},
|
||||||
@@ -162,6 +164,44 @@ const ModelPricing = () => {
|
|||||||
},
|
},
|
||||||
sorter: (a, b) => a.quota_type - b.quota_type,
|
sorter: (a, b) => a.quota_type - b.quota_type,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '可用分组',
|
||||||
|
dataIndex: 'enable_groups',
|
||||||
|
render: (text, record, index) => {
|
||||||
|
// enable_groups is a string array
|
||||||
|
return (
|
||||||
|
<Space>
|
||||||
|
{text.map((group) => {
|
||||||
|
if (group === selectedGroup) {
|
||||||
|
return (
|
||||||
|
<Tag color='blue' size='large' prefixIcon={<IconVerify />}>
|
||||||
|
{group}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<Tag
|
||||||
|
color='blue'
|
||||||
|
size='large'
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedGroup(group);
|
||||||
|
showInfo(
|
||||||
|
'当前查看的分组为:' +
|
||||||
|
group +
|
||||||
|
',倍率为:' +
|
||||||
|
groupRatio[group],
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{group}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})}
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: () => (
|
title: () => (
|
||||||
<span style={{ display: 'flex', alignItems: 'center' }}>
|
<span style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
@@ -203,6 +243,8 @@ const ModelPricing = () => {
|
|||||||
<Text>
|
<Text>
|
||||||
补全:{record.quota_type === 0 ? completionRatio : '无'}
|
补全:{record.quota_type === 0 ? completionRatio : '无'}
|
||||||
</Text>
|
</Text>
|
||||||
|
<br />
|
||||||
|
<Text>分组:{groupRatio[selectedGroup]}</Text>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
return <div>{content}</div>;
|
return <div>{content}</div>;
|
||||||
@@ -215,12 +257,13 @@ const ModelPricing = () => {
|
|||||||
let content = text;
|
let content = text;
|
||||||
if (record.quota_type === 0) {
|
if (record.quota_type === 0) {
|
||||||
// 这里的 *2 是因为 1倍率=0.002刀,请勿删除
|
// 这里的 *2 是因为 1倍率=0.002刀,请勿删除
|
||||||
let inputRatioPrice = record.model_ratio * 2 * record.group_ratio;
|
let inputRatioPrice =
|
||||||
|
record.model_ratio * 2 * groupRatio[selectedGroup];
|
||||||
let completionRatioPrice =
|
let completionRatioPrice =
|
||||||
record.model_ratio *
|
record.model_ratio *
|
||||||
record.completion_ratio *
|
record.completion_ratio *
|
||||||
2 *
|
2 *
|
||||||
record.group_ratio;
|
groupRatio[selectedGroup];
|
||||||
content = (
|
content = (
|
||||||
<>
|
<>
|
||||||
<Text>提示 ${inputRatioPrice} / 1M tokens</Text>
|
<Text>提示 ${inputRatioPrice} / 1M tokens</Text>
|
||||||
@@ -229,7 +272,7 @@ const ModelPricing = () => {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let price = parseFloat(text) * record.group_ratio;
|
let price = parseFloat(text) * groupRatio[selectedGroup];
|
||||||
content = <>模型价格:${price}</>;
|
content = <>模型价格:${price}</>;
|
||||||
}
|
}
|
||||||
return <div>{content}</div>;
|
return <div>{content}</div>;
|
||||||
@@ -240,12 +283,12 @@ const ModelPricing = () => {
|
|||||||
const [models, setModels] = useState([]);
|
const [models, setModels] = useState([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [userState, userDispatch] = useContext(UserContext);
|
const [userState, userDispatch] = useContext(UserContext);
|
||||||
const [groupRatio, setGroupRatio] = useState(1);
|
const [groupRatio, setGroupRatio] = useState({});
|
||||||
|
|
||||||
const setModelsFormat = (models, groupRatio) => {
|
const setModelsFormat = (models, groupRatio) => {
|
||||||
for (let i = 0; i < models.length; i++) {
|
for (let i = 0; i < models.length; i++) {
|
||||||
models[i].key = models[i].model_name;
|
models[i].key = models[i].model_name;
|
||||||
models[i].group_ratio = groupRatio;
|
models[i].group_ratio = groupRatio[models[i].model_name];
|
||||||
}
|
}
|
||||||
// sort by quota_type
|
// sort by quota_type
|
||||||
models.sort((a, b) => {
|
models.sort((a, b) => {
|
||||||
@@ -278,6 +321,7 @@ const ModelPricing = () => {
|
|||||||
const { success, message, data, group_ratio } = res.data;
|
const { success, message, data, group_ratio } = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
setGroupRatio(group_ratio);
|
setGroupRatio(group_ratio);
|
||||||
|
setSelectedGroup(userState.user ? userState.user.group : 'default');
|
||||||
setModelsFormat(data, group_ratio);
|
setModelsFormat(data, group_ratio);
|
||||||
} else {
|
} else {
|
||||||
showError(message);
|
showError(message);
|
||||||
@@ -310,14 +354,14 @@ const ModelPricing = () => {
|
|||||||
type='success'
|
type='success'
|
||||||
fullMode={false}
|
fullMode={false}
|
||||||
closeIcon='null'
|
closeIcon='null'
|
||||||
description={`您的分组为:${userState.user.group},分组倍率为:${groupRatio}`}
|
description={`您的默认分组为:${userState.user.group},分组倍率为:${groupRatio[userState.user.group]}`}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Banner
|
<Banner
|
||||||
type='warning'
|
type='warning'
|
||||||
fullMode={false}
|
fullMode={false}
|
||||||
closeIcon='null'
|
closeIcon='null'
|
||||||
description={`您还未登陆,显示的价格为默认分组倍率: ${groupRatio}`}
|
description={`您还未登陆,显示的价格为默认分组倍率: ${groupRatio['default']}`}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<br />
|
<br />
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import SettingsCreditLimit from '../pages/Setting/Operation/SettingsCreditLimit.
|
|||||||
import SettingsMagnification from '../pages/Setting/Operation/SettingsMagnification.js';
|
import SettingsMagnification from '../pages/Setting/Operation/SettingsMagnification.js';
|
||||||
|
|
||||||
import { API, showError, showSuccess } from '../helpers';
|
import { API, showError, showSuccess } from '../helpers';
|
||||||
|
import SettingsChats from '../pages/Setting/Operation/SettingsChats.js';
|
||||||
|
|
||||||
const OperationSetting = () => {
|
const OperationSetting = () => {
|
||||||
let [inputs, setInputs] = useState({
|
let [inputs, setInputs] = useState({
|
||||||
@@ -23,6 +24,7 @@ const OperationSetting = () => {
|
|||||||
CompletionRatio: '',
|
CompletionRatio: '',
|
||||||
ModelPrice: '',
|
ModelPrice: '',
|
||||||
GroupRatio: '',
|
GroupRatio: '',
|
||||||
|
UserUsableGroups: '',
|
||||||
TopUpLink: '',
|
TopUpLink: '',
|
||||||
ChatLink: '',
|
ChatLink: '',
|
||||||
ChatLink2: '', // 添加的新状态变量
|
ChatLink2: '', // 添加的新状态变量
|
||||||
@@ -49,6 +51,7 @@ const OperationSetting = () => {
|
|||||||
DataExportInterval: 5,
|
DataExportInterval: 5,
|
||||||
DefaultCollapseSidebar: false, // 默认折叠侧边栏
|
DefaultCollapseSidebar: false, // 默认折叠侧边栏
|
||||||
RetryTimes: 0,
|
RetryTimes: 0,
|
||||||
|
Chats: '[]',
|
||||||
});
|
});
|
||||||
|
|
||||||
let [loading, setLoading] = useState(false);
|
let [loading, setLoading] = useState(false);
|
||||||
@@ -62,6 +65,7 @@ const OperationSetting = () => {
|
|||||||
if (
|
if (
|
||||||
item.key === 'ModelRatio' ||
|
item.key === 'ModelRatio' ||
|
||||||
item.key === 'GroupRatio' ||
|
item.key === 'GroupRatio' ||
|
||||||
|
item.key === 'UserUsableGroups' ||
|
||||||
item.key === 'CompletionRatio' ||
|
item.key === 'CompletionRatio' ||
|
||||||
item.key === 'ModelPrice'
|
item.key === 'ModelPrice'
|
||||||
) {
|
) {
|
||||||
@@ -129,6 +133,10 @@ const OperationSetting = () => {
|
|||||||
<Card style={{ marginTop: '10px' }}>
|
<Card style={{ marginTop: '10px' }}>
|
||||||
<SettingsCreditLimit options={inputs} refresh={onRefresh} />
|
<SettingsCreditLimit options={inputs} refresh={onRefresh} />
|
||||||
</Card>
|
</Card>
|
||||||
|
{/* 聊天设置 */}
|
||||||
|
<Card style={{ marginTop: '10px' }}>
|
||||||
|
<SettingsChats options={inputs} refresh={onRefresh} />
|
||||||
|
</Card>
|
||||||
{/* 倍率设置 */}
|
{/* 倍率设置 */}
|
||||||
<Card style={{ marginTop: '10px' }}>
|
<Card style={{ marginTop: '10px' }}>
|
||||||
<SettingsMagnification options={inputs} refresh={onRefresh} />
|
<SettingsMagnification options={inputs} refresh={onRefresh} />
|
||||||
|
|||||||
357
web/src/components/Playground.js
Normal file
357
web/src/components/Playground.js
Normal file
@@ -0,0 +1,357 @@
|
|||||||
|
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
||||||
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
|
import { UserContext } from '../context/User';
|
||||||
|
import { API, getUserIdFromLocalStorage, showError } from '../helpers';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
Chat,
|
||||||
|
Input,
|
||||||
|
Layout,
|
||||||
|
Select,
|
||||||
|
Slider,
|
||||||
|
TextArea,
|
||||||
|
Typography,
|
||||||
|
} from '@douyinfe/semi-ui';
|
||||||
|
import { SSE } from 'sse';
|
||||||
|
|
||||||
|
const defaultMessage = [
|
||||||
|
{
|
||||||
|
role: 'user',
|
||||||
|
id: '2',
|
||||||
|
createAt: 1715676751919,
|
||||||
|
content: '你好',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'assistant',
|
||||||
|
id: '3',
|
||||||
|
createAt: 1715676751919,
|
||||||
|
content: '你好,请问有什么可以帮助您的吗?',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
let id = 4;
|
||||||
|
function getId() {
|
||||||
|
return `${id++}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Playground = () => {
|
||||||
|
const [inputs, setInputs] = useState({
|
||||||
|
model: 'gpt-4o-mini',
|
||||||
|
group: '',
|
||||||
|
max_tokens: 0,
|
||||||
|
temperature: 0,
|
||||||
|
});
|
||||||
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
|
const [userState, userDispatch] = useContext(UserContext);
|
||||||
|
const [status, setStatus] = useState({});
|
||||||
|
const [systemPrompt, setSystemPrompt] = useState(
|
||||||
|
'You are a helpful assistant. You can help me by answering my questions. You can also ask me questions.',
|
||||||
|
);
|
||||||
|
const [message, setMessage] = useState(defaultMessage);
|
||||||
|
const [models, setModels] = useState([]);
|
||||||
|
const [groups, setGroups] = useState([]);
|
||||||
|
|
||||||
|
const handleInputChange = (name, value) => {
|
||||||
|
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (searchParams.get('expired')) {
|
||||||
|
showError('未登录或登录已过期,请重新登录!');
|
||||||
|
}
|
||||||
|
let status = localStorage.getItem('status');
|
||||||
|
if (status) {
|
||||||
|
status = JSON.parse(status);
|
||||||
|
setStatus(status);
|
||||||
|
}
|
||||||
|
loadModels();
|
||||||
|
loadGroups();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const loadModels = async () => {
|
||||||
|
let res = await API.get(`/api/user/models`);
|
||||||
|
const { success, message, data } = res.data;
|
||||||
|
if (success) {
|
||||||
|
let localModelOptions = data.map((model) => ({
|
||||||
|
label: model,
|
||||||
|
value: model,
|
||||||
|
}));
|
||||||
|
setModels(localModelOptions);
|
||||||
|
} else {
|
||||||
|
showError(message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadGroups = async () => {
|
||||||
|
let res = await API.get(`/api/user/self/groups`);
|
||||||
|
const { success, message, data } = res.data;
|
||||||
|
if (success) {
|
||||||
|
// return data is a map, key is group name, value is group description
|
||||||
|
// label is group description, value is group name
|
||||||
|
let localGroupOptions = Object.keys(data).map((group) => ({
|
||||||
|
label: data[group],
|
||||||
|
value: group,
|
||||||
|
}));
|
||||||
|
// handleInputChange('group', localGroupOptions[0].value);
|
||||||
|
|
||||||
|
if (localGroupOptions.length > 0) {
|
||||||
|
} else {
|
||||||
|
localGroupOptions = [
|
||||||
|
{
|
||||||
|
label: '用户分组',
|
||||||
|
value: '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
setGroups(localGroupOptions);
|
||||||
|
}
|
||||||
|
setGroups(localGroupOptions);
|
||||||
|
handleInputChange('group', localGroupOptions[0].value);
|
||||||
|
} else {
|
||||||
|
showError(message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const commonOuterStyle = {
|
||||||
|
border: '1px solid var(--semi-color-border)',
|
||||||
|
borderRadius: '16px',
|
||||||
|
margin: '0px 8px',
|
||||||
|
};
|
||||||
|
|
||||||
|
const getSystemMessage = () => {
|
||||||
|
if (systemPrompt !== '') {
|
||||||
|
return {
|
||||||
|
role: 'system',
|
||||||
|
id: '1',
|
||||||
|
createAt: 1715676751919,
|
||||||
|
content: systemPrompt,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let handleSSE = (payload) => {
|
||||||
|
let source = new SSE('/pg/chat/completions', {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'New-Api-User': getUserIdFromLocalStorage(),
|
||||||
|
},
|
||||||
|
method: 'POST',
|
||||||
|
payload: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
source.addEventListener('message', (e) => {
|
||||||
|
if (e.data !== '[DONE]') {
|
||||||
|
let payload = JSON.parse(e.data);
|
||||||
|
// console.log("Payload: ", payload);
|
||||||
|
if (payload.choices.length === 0) {
|
||||||
|
source.close();
|
||||||
|
completeMessage();
|
||||||
|
} else {
|
||||||
|
let text = payload.choices[0].delta.content;
|
||||||
|
if (text) {
|
||||||
|
generateMockResponse(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
completeMessage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
source.addEventListener('error', (e) => {
|
||||||
|
generateMockResponse(e.data);
|
||||||
|
completeMessage('error');
|
||||||
|
});
|
||||||
|
|
||||||
|
source.addEventListener('readystatechange', (e) => {
|
||||||
|
if (e.readyState >= 2) {
|
||||||
|
if (source.status === undefined) {
|
||||||
|
source.close();
|
||||||
|
completeMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
source.stream();
|
||||||
|
};
|
||||||
|
|
||||||
|
const onMessageSend = useCallback(
|
||||||
|
(content, attachment) => {
|
||||||
|
console.log('attachment: ', attachment);
|
||||||
|
setMessage((prevMessage) => {
|
||||||
|
const newMessage = [
|
||||||
|
...prevMessage,
|
||||||
|
{
|
||||||
|
role: 'user',
|
||||||
|
content: content,
|
||||||
|
createAt: Date.now(),
|
||||||
|
id: getId(),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 将 getPayload 移到这里
|
||||||
|
const getPayload = () => {
|
||||||
|
let systemMessage = getSystemMessage();
|
||||||
|
let messages = newMessage.map((item) => {
|
||||||
|
return {
|
||||||
|
role: item.role,
|
||||||
|
content: item.content,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
if (systemMessage) {
|
||||||
|
messages.unshift(systemMessage);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
messages: messages,
|
||||||
|
stream: true,
|
||||||
|
model: inputs.model,
|
||||||
|
group: inputs.group,
|
||||||
|
max_tokens: parseInt(inputs.max_tokens),
|
||||||
|
temperature: inputs.temperature,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// 使用更新后的消息状态调用 handleSSE
|
||||||
|
handleSSE(getPayload());
|
||||||
|
newMessage.push({
|
||||||
|
role: 'assistant',
|
||||||
|
content: '',
|
||||||
|
createAt: Date.now(),
|
||||||
|
id: getId(),
|
||||||
|
status: 'loading',
|
||||||
|
});
|
||||||
|
return newMessage;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[getSystemMessage],
|
||||||
|
);
|
||||||
|
|
||||||
|
const completeMessage = useCallback((status = 'complete') => {
|
||||||
|
// console.log("Complete Message: ", status)
|
||||||
|
setMessage((prevMessage) => {
|
||||||
|
const lastMessage = prevMessage[prevMessage.length - 1];
|
||||||
|
// only change the status if the last message is not complete and not error
|
||||||
|
if (lastMessage.status === 'complete' || lastMessage.status === 'error') {
|
||||||
|
return prevMessage;
|
||||||
|
}
|
||||||
|
return [...prevMessage.slice(0, -1), { ...lastMessage, status: status }];
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const generateMockResponse = useCallback((content) => {
|
||||||
|
// console.log("Generate Mock Response: ", content);
|
||||||
|
setMessage((message) => {
|
||||||
|
const lastMessage = message[message.length - 1];
|
||||||
|
let newMessage = { ...lastMessage };
|
||||||
|
if (
|
||||||
|
lastMessage.status === 'loading' ||
|
||||||
|
lastMessage.status === 'incomplete'
|
||||||
|
) {
|
||||||
|
newMessage = {
|
||||||
|
...newMessage,
|
||||||
|
content: (lastMessage.content || '') + content,
|
||||||
|
status: 'incomplete',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return [...message.slice(0, -1), newMessage];
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Layout style={{ height: '100%' }}>
|
||||||
|
<Layout.Sider>
|
||||||
|
<Card style={commonOuterStyle}>
|
||||||
|
<div style={{ marginTop: 10 }}>
|
||||||
|
<Typography.Text strong>分组:</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<Select
|
||||||
|
placeholder={'请选择分组'}
|
||||||
|
name='group'
|
||||||
|
required
|
||||||
|
selection
|
||||||
|
onChange={(value) => {
|
||||||
|
handleInputChange('group', value);
|
||||||
|
}}
|
||||||
|
value={inputs.group}
|
||||||
|
autoComplete='new-password'
|
||||||
|
optionList={groups}
|
||||||
|
/>
|
||||||
|
<div style={{ marginTop: 10 }}>
|
||||||
|
<Typography.Text strong>模型:</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<Select
|
||||||
|
placeholder={'请选择模型'}
|
||||||
|
name='model'
|
||||||
|
required
|
||||||
|
selection
|
||||||
|
filter
|
||||||
|
onChange={(value) => {
|
||||||
|
handleInputChange('model', value);
|
||||||
|
}}
|
||||||
|
value={inputs.model}
|
||||||
|
autoComplete='new-password'
|
||||||
|
optionList={models}
|
||||||
|
/>
|
||||||
|
<div style={{ marginTop: 10 }}>
|
||||||
|
<Typography.Text strong>Temperature:</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<Slider
|
||||||
|
step={0.1}
|
||||||
|
min={0.1}
|
||||||
|
max={1}
|
||||||
|
value={inputs.temperature}
|
||||||
|
onChange={(value) => {
|
||||||
|
handleInputChange('temperature', value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div style={{ marginTop: 10 }}>
|
||||||
|
<Typography.Text strong>MaxTokens:</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<Input
|
||||||
|
placeholder='MaxTokens'
|
||||||
|
name='max_tokens'
|
||||||
|
required
|
||||||
|
autoComplete='new-password'
|
||||||
|
defaultValue={0}
|
||||||
|
value={inputs.max_tokens}
|
||||||
|
onChange={(value) => {
|
||||||
|
handleInputChange('max_tokens', value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div style={{ marginTop: 10 }}>
|
||||||
|
<Typography.Text strong>System:</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<TextArea
|
||||||
|
placeholder='System Prompt'
|
||||||
|
name='system'
|
||||||
|
required
|
||||||
|
autoComplete='new-password'
|
||||||
|
autosize
|
||||||
|
defaultValue={systemPrompt}
|
||||||
|
// value={systemPrompt}
|
||||||
|
onChange={(value) => {
|
||||||
|
setSystemPrompt(value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</Layout.Sider>
|
||||||
|
<Layout.Content>
|
||||||
|
<div style={{ height: '100%' }}>
|
||||||
|
<Chat
|
||||||
|
chatBoxRenderConfig={{
|
||||||
|
renderChatBoxAction: () => {
|
||||||
|
return <div></div>;
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
style={commonOuterStyle}
|
||||||
|
chats={message}
|
||||||
|
onMessageSend={onMessageSend}
|
||||||
|
showClearContext
|
||||||
|
onClear={() => {
|
||||||
|
setMessage([]);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Layout.Content>
|
||||||
|
</Layout>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Playground;
|
||||||
796
web/src/components/SafetySetting.js
Normal file
796
web/src/components/SafetySetting.js
Normal file
@@ -0,0 +1,796 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Divider,
|
||||||
|
Form,
|
||||||
|
Grid,
|
||||||
|
Header,
|
||||||
|
Message,
|
||||||
|
Modal,
|
||||||
|
} from 'semantic-ui-react';
|
||||||
|
import { API, removeTrailingSlash, showError, verifyJSON } from '../helpers';
|
||||||
|
|
||||||
|
import { useTheme } from '../context/Theme';
|
||||||
|
|
||||||
|
const SafetySetting = () => {
|
||||||
|
let [inputs, setInputs] = useState({
|
||||||
|
PasswordLoginEnabled: '',
|
||||||
|
PasswordRegisterEnabled: '',
|
||||||
|
EmailVerificationEnabled: '',
|
||||||
|
GitHubOAuthEnabled: '',
|
||||||
|
GitHubClientId: '',
|
||||||
|
GitHubClientSecret: '',
|
||||||
|
Notice: '',
|
||||||
|
SMTPServer: '',
|
||||||
|
SMTPPort: '',
|
||||||
|
SMTPAccount: '',
|
||||||
|
SMTPFrom: '',
|
||||||
|
SMTPToken: '',
|
||||||
|
ServerAddress: '',
|
||||||
|
WorkerUrl: '',
|
||||||
|
WorkerValidKey: '',
|
||||||
|
EpayId: '',
|
||||||
|
EpayKey: '',
|
||||||
|
Price: 7.3,
|
||||||
|
MinTopUp: 1,
|
||||||
|
TopupGroupRatio: '',
|
||||||
|
PayAddress: '',
|
||||||
|
CustomCallbackAddress: '',
|
||||||
|
Footer: '',
|
||||||
|
WeChatAuthEnabled: '',
|
||||||
|
WeChatServerAddress: '',
|
||||||
|
WeChatServerToken: '',
|
||||||
|
WeChatAccountQRCodeImageURL: '',
|
||||||
|
TurnstileCheckEnabled: '',
|
||||||
|
TurnstileSiteKey: '',
|
||||||
|
TurnstileSecretKey: '',
|
||||||
|
RegisterEnabled: '',
|
||||||
|
EmailDomainRestrictionEnabled: '',
|
||||||
|
EmailAliasRestrictionEnabled: '',
|
||||||
|
SMTPSSLEnabled: '',
|
||||||
|
EmailDomainWhitelist: [],
|
||||||
|
// telegram login
|
||||||
|
TelegramOAuthEnabled: '',
|
||||||
|
TelegramBotToken: '',
|
||||||
|
TelegramBotName: '',
|
||||||
|
});
|
||||||
|
const [originInputs, setOriginInputs] = useState({});
|
||||||
|
let [loading, setLoading] = useState(false);
|
||||||
|
const [EmailDomainWhitelist, setEmailDomainWhitelist] = useState([]);
|
||||||
|
const [restrictedDomainInput, setRestrictedDomainInput] = useState('');
|
||||||
|
const [showPasswordWarningModal, setShowPasswordWarningModal] =
|
||||||
|
useState(false);
|
||||||
|
|
||||||
|
const theme = useTheme();
|
||||||
|
const isDark = theme === 'dark';
|
||||||
|
|
||||||
|
const getOptions = async () => {
|
||||||
|
const res = await API.get('/api/option/');
|
||||||
|
const { success, message, data } = res.data;
|
||||||
|
if (success) {
|
||||||
|
let newInputs = {};
|
||||||
|
data.forEach((item) => {
|
||||||
|
if (item.key === 'TopupGroupRatio') {
|
||||||
|
item.value = JSON.stringify(JSON.parse(item.value), null, 2);
|
||||||
|
}
|
||||||
|
newInputs[item.key] = item.value;
|
||||||
|
});
|
||||||
|
setInputs({
|
||||||
|
...newInputs,
|
||||||
|
EmailDomainWhitelist: newInputs.EmailDomainWhitelist.split(','),
|
||||||
|
});
|
||||||
|
setOriginInputs(newInputs);
|
||||||
|
|
||||||
|
setEmailDomainWhitelist(
|
||||||
|
newInputs.EmailDomainWhitelist.split(',').map((item) => {
|
||||||
|
return { key: item, text: item, value: item };
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
showError(message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getOptions().then();
|
||||||
|
}, []);
|
||||||
|
useEffect(() => {}, [inputs.EmailDomainWhitelist]);
|
||||||
|
|
||||||
|
const updateOption = async (key, value) => {
|
||||||
|
setLoading(true);
|
||||||
|
switch (key) {
|
||||||
|
case 'PasswordLoginEnabled':
|
||||||
|
case 'PasswordRegisterEnabled':
|
||||||
|
case 'EmailVerificationEnabled':
|
||||||
|
case 'GitHubOAuthEnabled':
|
||||||
|
case 'WeChatAuthEnabled':
|
||||||
|
case 'TelegramOAuthEnabled':
|
||||||
|
case 'TurnstileCheckEnabled':
|
||||||
|
case 'EmailDomainRestrictionEnabled':
|
||||||
|
case 'EmailAliasRestrictionEnabled':
|
||||||
|
case 'SMTPSSLEnabled':
|
||||||
|
case 'RegisterEnabled':
|
||||||
|
value = inputs[key] === 'true' ? 'false' : 'true';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const res = await API.put('/api/option/', {
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
});
|
||||||
|
const { success, message } = res.data;
|
||||||
|
if (success) {
|
||||||
|
if (key === 'EmailDomainWhitelist') {
|
||||||
|
value = value.split(',');
|
||||||
|
}
|
||||||
|
if (key === 'Price') {
|
||||||
|
value = parseFloat(value);
|
||||||
|
}
|
||||||
|
setInputs((inputs) => ({
|
||||||
|
...inputs,
|
||||||
|
[key]: value,
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
showError(message);
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleInputChange = async (e, { name, value }) => {
|
||||||
|
if (name === 'PasswordLoginEnabled' && inputs[name] === 'true') {
|
||||||
|
// block disabling password login
|
||||||
|
setShowPasswordWarningModal(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
name === 'Notice' ||
|
||||||
|
(name.startsWith('SMTP') && name !== 'SMTPSSLEnabled') ||
|
||||||
|
name === 'ServerAddress' ||
|
||||||
|
name === 'WorkerUrl' ||
|
||||||
|
name === 'WorkerValidKey' ||
|
||||||
|
name === 'EpayId' ||
|
||||||
|
name === 'EpayKey' ||
|
||||||
|
name === 'Price' ||
|
||||||
|
name === 'PayAddress' ||
|
||||||
|
name === 'GitHubClientId' ||
|
||||||
|
name === 'GitHubClientSecret' ||
|
||||||
|
name === 'WeChatServerAddress' ||
|
||||||
|
name === 'WeChatServerToken' ||
|
||||||
|
name === 'WeChatAccountQRCodeImageURL' ||
|
||||||
|
name === 'TurnstileSiteKey' ||
|
||||||
|
name === 'TurnstileSecretKey' ||
|
||||||
|
name === 'EmailDomainWhitelist' ||
|
||||||
|
name === 'TopupGroupRatio' ||
|
||||||
|
name === 'TelegramBotToken' ||
|
||||||
|
name === 'TelegramBotName'
|
||||||
|
) {
|
||||||
|
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
||||||
|
} else {
|
||||||
|
await updateOption(name, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitServerAddress = async () => {
|
||||||
|
let ServerAddress = removeTrailingSlash(inputs.ServerAddress);
|
||||||
|
await updateOption('ServerAddress', ServerAddress);
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitWorker = async () => {
|
||||||
|
let WorkerUrl = removeTrailingSlash(inputs.WorkerUrl);
|
||||||
|
await updateOption('WorkerUrl', WorkerUrl);
|
||||||
|
if (inputs.WorkerValidKey !== '') {
|
||||||
|
await updateOption('WorkerValidKey', inputs.WorkerValidKey);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitPayAddress = async () => {
|
||||||
|
if (inputs.ServerAddress === '') {
|
||||||
|
showError('请先填写服务器地址');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (originInputs['TopupGroupRatio'] !== inputs.TopupGroupRatio) {
|
||||||
|
if (!verifyJSON(inputs.TopupGroupRatio)) {
|
||||||
|
showError('充值分组倍率不是合法的 JSON 字符串');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await updateOption('TopupGroupRatio', inputs.TopupGroupRatio);
|
||||||
|
}
|
||||||
|
let PayAddress = removeTrailingSlash(inputs.PayAddress);
|
||||||
|
await updateOption('PayAddress', PayAddress);
|
||||||
|
if (inputs.EpayId !== '') {
|
||||||
|
await updateOption('EpayId', inputs.EpayId);
|
||||||
|
}
|
||||||
|
if (inputs.EpayKey !== undefined && inputs.EpayKey !== '') {
|
||||||
|
await updateOption('EpayKey', inputs.EpayKey);
|
||||||
|
}
|
||||||
|
await updateOption('Price', '' + inputs.Price);
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitSMTP = async () => {
|
||||||
|
if (originInputs['SMTPServer'] !== inputs.SMTPServer) {
|
||||||
|
await updateOption('SMTPServer', inputs.SMTPServer);
|
||||||
|
}
|
||||||
|
if (originInputs['SMTPAccount'] !== inputs.SMTPAccount) {
|
||||||
|
await updateOption('SMTPAccount', inputs.SMTPAccount);
|
||||||
|
}
|
||||||
|
if (originInputs['SMTPFrom'] !== inputs.SMTPFrom) {
|
||||||
|
await updateOption('SMTPFrom', inputs.SMTPFrom);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
originInputs['SMTPPort'] !== inputs.SMTPPort &&
|
||||||
|
inputs.SMTPPort !== ''
|
||||||
|
) {
|
||||||
|
await updateOption('SMTPPort', inputs.SMTPPort);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
originInputs['SMTPToken'] !== inputs.SMTPToken &&
|
||||||
|
inputs.SMTPToken !== ''
|
||||||
|
) {
|
||||||
|
await updateOption('SMTPToken', inputs.SMTPToken);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitEmailDomainWhitelist = async () => {
|
||||||
|
if (
|
||||||
|
originInputs['EmailDomainWhitelist'] !==
|
||||||
|
inputs.EmailDomainWhitelist.join(',') &&
|
||||||
|
inputs.SMTPToken !== ''
|
||||||
|
) {
|
||||||
|
await updateOption(
|
||||||
|
'EmailDomainWhitelist',
|
||||||
|
inputs.EmailDomainWhitelist.join(','),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitWeChat = async () => {
|
||||||
|
if (originInputs['WeChatServerAddress'] !== inputs.WeChatServerAddress) {
|
||||||
|
await updateOption(
|
||||||
|
'WeChatServerAddress',
|
||||||
|
removeTrailingSlash(inputs.WeChatServerAddress),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
originInputs['WeChatAccountQRCodeImageURL'] !==
|
||||||
|
inputs.WeChatAccountQRCodeImageURL
|
||||||
|
) {
|
||||||
|
await updateOption(
|
||||||
|
'WeChatAccountQRCodeImageURL',
|
||||||
|
inputs.WeChatAccountQRCodeImageURL,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
originInputs['WeChatServerToken'] !== inputs.WeChatServerToken &&
|
||||||
|
inputs.WeChatServerToken !== ''
|
||||||
|
) {
|
||||||
|
await updateOption('WeChatServerToken', inputs.WeChatServerToken);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitGitHubOAuth = async () => {
|
||||||
|
if (originInputs['GitHubClientId'] !== inputs.GitHubClientId) {
|
||||||
|
await updateOption('GitHubClientId', inputs.GitHubClientId);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
originInputs['GitHubClientSecret'] !== inputs.GitHubClientSecret &&
|
||||||
|
inputs.GitHubClientSecret !== ''
|
||||||
|
) {
|
||||||
|
await updateOption('GitHubClientSecret', inputs.GitHubClientSecret);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitTelegramSettings = async () => {
|
||||||
|
// await updateOption('TelegramOAuthEnabled', inputs.TelegramOAuthEnabled);
|
||||||
|
await updateOption('TelegramBotToken', inputs.TelegramBotToken);
|
||||||
|
await updateOption('TelegramBotName', inputs.TelegramBotName);
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitTurnstile = async () => {
|
||||||
|
if (originInputs['TurnstileSiteKey'] !== inputs.TurnstileSiteKey) {
|
||||||
|
await updateOption('TurnstileSiteKey', inputs.TurnstileSiteKey);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
originInputs['TurnstileSecretKey'] !== inputs.TurnstileSecretKey &&
|
||||||
|
inputs.TurnstileSecretKey !== ''
|
||||||
|
) {
|
||||||
|
await updateOption('TurnstileSecretKey', inputs.TurnstileSecretKey);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitNewRestrictedDomain = () => {
|
||||||
|
const localDomainList = inputs.EmailDomainWhitelist;
|
||||||
|
if (
|
||||||
|
restrictedDomainInput !== '' &&
|
||||||
|
!localDomainList.includes(restrictedDomainInput)
|
||||||
|
) {
|
||||||
|
setRestrictedDomainInput('');
|
||||||
|
setInputs({
|
||||||
|
...inputs,
|
||||||
|
EmailDomainWhitelist: [...localDomainList, restrictedDomainInput],
|
||||||
|
});
|
||||||
|
setEmailDomainWhitelist([
|
||||||
|
...EmailDomainWhitelist,
|
||||||
|
{
|
||||||
|
key: restrictedDomainInput,
|
||||||
|
text: restrictedDomainInput,
|
||||||
|
value: restrictedDomainInput,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Grid columns={1}>
|
||||||
|
<Grid.Column>
|
||||||
|
<Form loading={loading} inverted={isDark}>
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
通用设置
|
||||||
|
</Header>
|
||||||
|
<Form.Group widths='equal'>
|
||||||
|
<Form.Input
|
||||||
|
label='服务器地址'
|
||||||
|
placeholder='例如:https://yourdomain.com'
|
||||||
|
value={inputs.ServerAddress}
|
||||||
|
name='ServerAddress'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitServerAddress}>
|
||||||
|
更新服务器地址
|
||||||
|
</Form.Button>
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
代理设置(支持{' '}
|
||||||
|
<a
|
||||||
|
href='https://github.com/Calcium-Ion/new-api-worker'
|
||||||
|
target='_blank'
|
||||||
|
rel='noreferrer'
|
||||||
|
>
|
||||||
|
new-api-worker
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
</Header>
|
||||||
|
<Form.Group widths='equal'>
|
||||||
|
<Form.Input
|
||||||
|
label='Worker地址,不填写则不启用代理'
|
||||||
|
placeholder='例如:https://workername.yourdomain.workers.dev'
|
||||||
|
value={inputs.WorkerUrl}
|
||||||
|
name='WorkerUrl'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='Worker密钥,根据你部署的 Worker 填写'
|
||||||
|
placeholder='例如:your_secret_key'
|
||||||
|
value={inputs.WorkerValidKey}
|
||||||
|
name='WorkerValidKey'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitWorker}>更新Worker设置</Form.Button>
|
||||||
|
<Divider />
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
支付设置(当前仅支持易支付接口,默认使用上方服务器地址作为回调地址!)
|
||||||
|
</Header>
|
||||||
|
<Form.Group widths='equal'>
|
||||||
|
<Form.Input
|
||||||
|
label='支付地址,不填写则不启用在线支付'
|
||||||
|
placeholder='例如:https://yourdomain.com'
|
||||||
|
value={inputs.PayAddress}
|
||||||
|
name='PayAddress'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='易支付商户ID'
|
||||||
|
placeholder='例如:0001'
|
||||||
|
value={inputs.EpayId}
|
||||||
|
name='EpayId'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='易支付商户密钥'
|
||||||
|
placeholder='敏感信息不会发送到前端显示'
|
||||||
|
value={inputs.EpayKey}
|
||||||
|
name='EpayKey'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group widths='equal'>
|
||||||
|
<Form.Input
|
||||||
|
label='回调地址,不填写则使用上方服务器地址作为回调地址'
|
||||||
|
placeholder='例如:https://yourdomain.com'
|
||||||
|
value={inputs.CustomCallbackAddress}
|
||||||
|
name='CustomCallbackAddress'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='充值价格(x元/美金)'
|
||||||
|
placeholder='例如:7,就是7元/美金'
|
||||||
|
value={inputs.Price}
|
||||||
|
name='Price'
|
||||||
|
min={0}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='最低充值美元数量(以美金为单位,如果使用额度请自行换算!)'
|
||||||
|
placeholder='例如:2,就是最低充值2$'
|
||||||
|
value={inputs.MinTopUp}
|
||||||
|
name='MinTopUp'
|
||||||
|
min={1}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group widths='equal'>
|
||||||
|
<Form.TextArea
|
||||||
|
label='充值分组倍率'
|
||||||
|
name='TopupGroupRatio'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
style={{ minHeight: 250, fontFamily: 'JetBrains Mono, Consolas' }}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.TopupGroupRatio}
|
||||||
|
placeholder='为一个 JSON 文本,键为组名称,值为倍率'
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitPayAddress}>更新支付设置</Form.Button>
|
||||||
|
<Divider />
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
配置登录注册
|
||||||
|
</Header>
|
||||||
|
<Form.Group inline>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.PasswordLoginEnabled === 'true'}
|
||||||
|
label='允许通过密码进行登录'
|
||||||
|
name='PasswordLoginEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
{showPasswordWarningModal && (
|
||||||
|
<Modal
|
||||||
|
open={showPasswordWarningModal}
|
||||||
|
onClose={() => setShowPasswordWarningModal(false)}
|
||||||
|
size={'tiny'}
|
||||||
|
style={{ maxWidth: '450px' }}
|
||||||
|
>
|
||||||
|
<Modal.Header>警告</Modal.Header>
|
||||||
|
<Modal.Content>
|
||||||
|
<p>
|
||||||
|
取消密码登录将导致所有未绑定其他登录方式的用户(包括管理员)无法通过密码登录,确认取消?
|
||||||
|
</p>
|
||||||
|
</Modal.Content>
|
||||||
|
<Modal.Actions>
|
||||||
|
<Button onClick={() => setShowPasswordWarningModal(false)}>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color='yellow'
|
||||||
|
onClick={async () => {
|
||||||
|
setShowPasswordWarningModal(false);
|
||||||
|
await updateOption('PasswordLoginEnabled', 'false');
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
确定
|
||||||
|
</Button>
|
||||||
|
</Modal.Actions>
|
||||||
|
</Modal>
|
||||||
|
)}
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.PasswordRegisterEnabled === 'true'}
|
||||||
|
label='允许通过密码进行注册'
|
||||||
|
name='PasswordRegisterEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.EmailVerificationEnabled === 'true'}
|
||||||
|
label='通过密码注册时需要进行邮箱验证'
|
||||||
|
name='EmailVerificationEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.GitHubOAuthEnabled === 'true'}
|
||||||
|
label='允许通过 GitHub 账户登录 & 注册'
|
||||||
|
name='GitHubOAuthEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.WeChatAuthEnabled === 'true'}
|
||||||
|
label='允许通过微信登录 & 注册'
|
||||||
|
name='WeChatAuthEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.TelegramOAuthEnabled === 'true'}
|
||||||
|
label='允许通过 Telegram 进行登录'
|
||||||
|
name='TelegramOAuthEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group inline>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.RegisterEnabled === 'true'}
|
||||||
|
label='允许新用户注册(此项为否时,新用户将无法以任何方式进行注册)'
|
||||||
|
name='RegisterEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.TurnstileCheckEnabled === 'true'}
|
||||||
|
label='启用 Turnstile 用户校验'
|
||||||
|
name='TurnstileCheckEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Divider />
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
配置邮箱域名白名单
|
||||||
|
<Header.Subheader>
|
||||||
|
用以防止恶意用户利用临时邮箱批量注册
|
||||||
|
</Header.Subheader>
|
||||||
|
</Header>
|
||||||
|
<Form.Group widths={3}>
|
||||||
|
<Form.Checkbox
|
||||||
|
label='启用邮箱域名白名单'
|
||||||
|
name='EmailDomainRestrictionEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
checked={inputs.EmailDomainRestrictionEnabled === 'true'}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group widths={3}>
|
||||||
|
<Form.Checkbox
|
||||||
|
label='启用邮箱别名限制(例如:ab.cd@gmail.com)'
|
||||||
|
name='EmailAliasRestrictionEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
checked={inputs.EmailAliasRestrictionEnabled === 'true'}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group widths={2}>
|
||||||
|
<Form.Dropdown
|
||||||
|
label='允许的邮箱域名'
|
||||||
|
placeholder='允许的邮箱域名'
|
||||||
|
name='EmailDomainWhitelist'
|
||||||
|
required
|
||||||
|
fluid
|
||||||
|
multiple
|
||||||
|
selection
|
||||||
|
onChange={handleInputChange}
|
||||||
|
value={inputs.EmailDomainWhitelist}
|
||||||
|
autoComplete='new-password'
|
||||||
|
options={EmailDomainWhitelist}
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='添加新的允许的邮箱域名'
|
||||||
|
action={
|
||||||
|
<Button
|
||||||
|
type='button'
|
||||||
|
onClick={() => {
|
||||||
|
submitNewRestrictedDomain();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
填入
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
submitNewRestrictedDomain();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
autoComplete='new-password'
|
||||||
|
placeholder='输入新的允许的邮箱域名'
|
||||||
|
value={restrictedDomainInput}
|
||||||
|
onChange={(e, { value }) => {
|
||||||
|
setRestrictedDomainInput(value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitEmailDomainWhitelist}>
|
||||||
|
保存邮箱域名白名单设置
|
||||||
|
</Form.Button>
|
||||||
|
<Divider />
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
配置 SMTP
|
||||||
|
<Header.Subheader>用以支持系统的邮件发送</Header.Subheader>
|
||||||
|
</Header>
|
||||||
|
<Form.Group widths={3}>
|
||||||
|
<Form.Input
|
||||||
|
label='SMTP 服务器地址'
|
||||||
|
name='SMTPServer'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.SMTPServer}
|
||||||
|
placeholder='例如:smtp.qq.com'
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='SMTP 端口'
|
||||||
|
name='SMTPPort'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.SMTPPort}
|
||||||
|
placeholder='默认: 587'
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='SMTP 账户'
|
||||||
|
name='SMTPAccount'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.SMTPAccount}
|
||||||
|
placeholder='通常是邮箱地址'
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group widths={3}>
|
||||||
|
<Form.Input
|
||||||
|
label='SMTP 发送者邮箱'
|
||||||
|
name='SMTPFrom'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.SMTPFrom}
|
||||||
|
placeholder='通常和邮箱地址保持一致'
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='SMTP 访问凭证'
|
||||||
|
name='SMTPToken'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
type='password'
|
||||||
|
autoComplete='new-password'
|
||||||
|
checked={inputs.RegisterEnabled === 'true'}
|
||||||
|
placeholder='敏感信息不会发送到前端显示'
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Group widths={3}>
|
||||||
|
<Form.Checkbox
|
||||||
|
label='启用SMTP SSL(465端口强制开启)'
|
||||||
|
name='SMTPSSLEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
checked={inputs.SMTPSSLEnabled === 'true'}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitSMTP}>保存 SMTP 设置</Form.Button>
|
||||||
|
<Divider />
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
配置 GitHub OAuth App
|
||||||
|
<Header.Subheader>
|
||||||
|
用以支持通过 GitHub 进行登录注册,
|
||||||
|
<a
|
||||||
|
href='https://github.com/settings/developers'
|
||||||
|
target='_blank'
|
||||||
|
rel='noreferrer'
|
||||||
|
>
|
||||||
|
点击此处
|
||||||
|
</a>
|
||||||
|
管理你的 GitHub OAuth App
|
||||||
|
</Header.Subheader>
|
||||||
|
</Header>
|
||||||
|
<Message>
|
||||||
|
Homepage URL 填 <code>{inputs.ServerAddress}</code>
|
||||||
|
,Authorization callback URL 填{' '}
|
||||||
|
<code>{`${inputs.ServerAddress}/oauth/github`}</code>
|
||||||
|
</Message>
|
||||||
|
<Form.Group widths={3}>
|
||||||
|
<Form.Input
|
||||||
|
label='GitHub Client ID'
|
||||||
|
name='GitHubClientId'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.GitHubClientId}
|
||||||
|
placeholder='输入你注册的 GitHub OAuth APP 的 ID'
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='GitHub Client Secret'
|
||||||
|
name='GitHubClientSecret'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
type='password'
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.GitHubClientSecret}
|
||||||
|
placeholder='敏感信息不会发送到前端显示'
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitGitHubOAuth}>
|
||||||
|
保存 GitHub OAuth 设置
|
||||||
|
</Form.Button>
|
||||||
|
<Divider />
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
配置 WeChat Server
|
||||||
|
<Header.Subheader>
|
||||||
|
用以支持通过微信进行登录注册,
|
||||||
|
<a
|
||||||
|
href='https://github.com/songquanpeng/wechat-server'
|
||||||
|
target='_blank'
|
||||||
|
rel='noreferrer'
|
||||||
|
>
|
||||||
|
点击此处
|
||||||
|
</a>
|
||||||
|
了解 WeChat Server
|
||||||
|
</Header.Subheader>
|
||||||
|
</Header>
|
||||||
|
<Form.Group widths={3}>
|
||||||
|
<Form.Input
|
||||||
|
label='WeChat Server 服务器地址'
|
||||||
|
name='WeChatServerAddress'
|
||||||
|
placeholder='例如:https://yourdomain.com'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.WeChatServerAddress}
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='WeChat Server 访问凭证'
|
||||||
|
name='WeChatServerToken'
|
||||||
|
type='password'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.WeChatServerToken}
|
||||||
|
placeholder='敏感信息不会发送到前端显示'
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='微信公众号二维码图片链接'
|
||||||
|
name='WeChatAccountQRCodeImageURL'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.WeChatAccountQRCodeImageURL}
|
||||||
|
placeholder='输入一个图片链接'
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitWeChat}>
|
||||||
|
保存 WeChat Server 设置
|
||||||
|
</Form.Button>
|
||||||
|
<Divider />
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
配置 Telegram 登录
|
||||||
|
</Header>
|
||||||
|
<Form.Group inline>
|
||||||
|
<Form.Input
|
||||||
|
label='Telegram Bot Token'
|
||||||
|
name='TelegramBotToken'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
value={inputs.TelegramBotToken}
|
||||||
|
placeholder='输入你的 Telegram Bot Token'
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='Telegram Bot 名称'
|
||||||
|
name='TelegramBotName'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
value={inputs.TelegramBotName}
|
||||||
|
placeholder='输入你的 Telegram Bot 名称'
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitTelegramSettings}>
|
||||||
|
保存 Telegram 登录设置
|
||||||
|
</Form.Button>
|
||||||
|
<Divider />
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
配置 Turnstile
|
||||||
|
<Header.Subheader>
|
||||||
|
用以支持用户校验,
|
||||||
|
<a
|
||||||
|
href='https://dash.cloudflare.com/'
|
||||||
|
target='_blank'
|
||||||
|
rel='noreferrer'
|
||||||
|
>
|
||||||
|
点击此处
|
||||||
|
</a>
|
||||||
|
管理你的 Turnstile Sites,推荐选择 Invisible Widget Type
|
||||||
|
</Header.Subheader>
|
||||||
|
</Header>
|
||||||
|
<Form.Group widths={3}>
|
||||||
|
<Form.Input
|
||||||
|
label='Turnstile Site Key'
|
||||||
|
name='TurnstileSiteKey'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.TurnstileSiteKey}
|
||||||
|
placeholder='输入你注册的 Turnstile Site Key'
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='Turnstile Secret Key'
|
||||||
|
name='TurnstileSecretKey'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
type='password'
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.TurnstileSecretKey}
|
||||||
|
placeholder='敏感信息不会发送到前端显示'
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitTurnstile}>
|
||||||
|
保存 Turnstile 设置
|
||||||
|
</Form.Button>
|
||||||
|
</Form>
|
||||||
|
</Grid.Column>
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SystemSetting;
|
||||||
@@ -17,8 +17,10 @@ import {
|
|||||||
IconCalendarClock,
|
IconCalendarClock,
|
||||||
IconChecklistStroked,
|
IconChecklistStroked,
|
||||||
IconComment,
|
IconComment,
|
||||||
|
IconCommentStroked,
|
||||||
IconCreditCard,
|
IconCreditCard,
|
||||||
IconGift,
|
IconGift,
|
||||||
|
IconHelpCircle,
|
||||||
IconHistogram,
|
IconHistogram,
|
||||||
IconHome,
|
IconHome,
|
||||||
IconImage,
|
IconImage,
|
||||||
@@ -28,8 +30,10 @@ import {
|
|||||||
IconSetting,
|
IconSetting,
|
||||||
IconUser,
|
IconUser,
|
||||||
} from '@douyinfe/semi-icons';
|
} from '@douyinfe/semi-icons';
|
||||||
import { Layout, Nav } from '@douyinfe/semi-ui';
|
import { Avatar, Dropdown, Layout, Nav, Switch } from '@douyinfe/semi-ui';
|
||||||
import { setStatusData } from '../helpers/data.js';
|
import { setStatusData } from '../helpers/data.js';
|
||||||
|
import { stringToColor } from '../helpers/render.js';
|
||||||
|
import { useSetTheme, useTheme } from '../context/Theme/index.js';
|
||||||
|
|
||||||
// HeaderBar Buttons
|
// HeaderBar Buttons
|
||||||
|
|
||||||
@@ -39,11 +43,11 @@ const SiderBar = () => {
|
|||||||
const defaultIsCollapsed =
|
const defaultIsCollapsed =
|
||||||
isMobile() || localStorage.getItem('default_collapse_sidebar') === 'true';
|
isMobile() || localStorage.getItem('default_collapse_sidebar') === 'true';
|
||||||
|
|
||||||
let navigate = useNavigate();
|
|
||||||
const [selectedKeys, setSelectedKeys] = useState(['home']);
|
const [selectedKeys, setSelectedKeys] = useState(['home']);
|
||||||
const systemName = getSystemName();
|
|
||||||
const logo = getLogo();
|
|
||||||
const [isCollapsed, setIsCollapsed] = useState(defaultIsCollapsed);
|
const [isCollapsed, setIsCollapsed] = useState(defaultIsCollapsed);
|
||||||
|
const [chatItems, setChatItems] = useState([]);
|
||||||
|
const theme = useTheme();
|
||||||
|
const setTheme = useSetTheme();
|
||||||
|
|
||||||
const routerMap = {
|
const routerMap = {
|
||||||
home: '/',
|
home: '/',
|
||||||
@@ -60,15 +64,22 @@ const SiderBar = () => {
|
|||||||
detail: '/detail',
|
detail: '/detail',
|
||||||
pricing: '/pricing',
|
pricing: '/pricing',
|
||||||
task: '/task',
|
task: '/task',
|
||||||
|
playground: '/playground',
|
||||||
};
|
};
|
||||||
|
|
||||||
const headerButtons = useMemo(
|
const headerButtons = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
text: '首页',
|
text: 'Playground',
|
||||||
itemKey: 'home',
|
itemKey: 'playground',
|
||||||
to: '/',
|
to: '/playground',
|
||||||
icon: <IconHome />,
|
icon: <IconCommentStroked />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: '模型价格',
|
||||||
|
itemKey: 'pricing',
|
||||||
|
to: '/pricing',
|
||||||
|
icon: <IconPriceTag />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: '渠道',
|
text: '渠道',
|
||||||
@@ -80,11 +91,12 @@ const SiderBar = () => {
|
|||||||
{
|
{
|
||||||
text: '聊天',
|
text: '聊天',
|
||||||
itemKey: 'chat',
|
itemKey: 'chat',
|
||||||
to: '/chat',
|
// to: '/chat',
|
||||||
|
items: chatItems,
|
||||||
icon: <IconComment />,
|
icon: <IconComment />,
|
||||||
className: localStorage.getItem('chat_link')
|
// className: localStorage.getItem('chat_link')
|
||||||
? 'semi-navigation-item-normal'
|
// ? 'semi-navigation-item-normal'
|
||||||
: 'tableHiddle',
|
// : 'tableHiddle',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: '令牌',
|
text: '令牌',
|
||||||
@@ -105,12 +117,6 @@ const SiderBar = () => {
|
|||||||
to: '/topup',
|
to: '/topup',
|
||||||
icon: <IconCreditCard />,
|
icon: <IconCreditCard />,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
text: '模型价格',
|
|
||||||
itemKey: 'pricing',
|
|
||||||
to: '/pricing',
|
|
||||||
icon: <IconPriceTag />,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
text: '用户管理',
|
text: '用户管理',
|
||||||
itemKey: 'user',
|
itemKey: 'user',
|
||||||
@@ -172,6 +178,7 @@ const SiderBar = () => {
|
|||||||
localStorage.getItem('enable_drawing'),
|
localStorage.getItem('enable_drawing'),
|
||||||
localStorage.getItem('enable_task'),
|
localStorage.getItem('enable_task'),
|
||||||
localStorage.getItem('chat_link'),
|
localStorage.getItem('chat_link'),
|
||||||
|
chatItems,
|
||||||
isAdmin(),
|
isAdmin(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -202,52 +209,101 @@ const SiderBar = () => {
|
|||||||
localKey = 'home';
|
localKey = 'home';
|
||||||
}
|
}
|
||||||
setSelectedKeys([localKey]);
|
setSelectedKeys([localKey]);
|
||||||
|
let chatLink = localStorage.getItem('chat_link');
|
||||||
|
if (!chatLink) {
|
||||||
|
let chats = localStorage.getItem('chats');
|
||||||
|
if (chats) {
|
||||||
|
// console.log(chats);
|
||||||
|
try {
|
||||||
|
chats = JSON.parse(chats);
|
||||||
|
if (Array.isArray(chats)) {
|
||||||
|
let chatItems = [];
|
||||||
|
for (let i = 0; i < chats.length; i++) {
|
||||||
|
let chat = {};
|
||||||
|
for (let key in chats[i]) {
|
||||||
|
chat.text = key;
|
||||||
|
chat.itemKey = 'chat' + i;
|
||||||
|
chat.to = '/chat/' + i;
|
||||||
|
}
|
||||||
|
// setRouterMap({ ...routerMap, chat: '/chat/' + i })
|
||||||
|
chatItems.push(chat);
|
||||||
|
}
|
||||||
|
setChatItems(chatItems);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
showError('聊天数据解析失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Layout>
|
<Nav
|
||||||
<div style={{ height: '100%' }}>
|
style={{ maxWidth: 220, height: '100%' }}
|
||||||
<Nav
|
defaultIsCollapsed={
|
||||||
// bodyStyle={{ maxWidth: 200 }}
|
isMobile() ||
|
||||||
style={{ maxWidth: 200 }}
|
localStorage.getItem('default_collapse_sidebar') === 'true'
|
||||||
defaultIsCollapsed={
|
}
|
||||||
isMobile() ||
|
isCollapsed={isCollapsed}
|
||||||
localStorage.getItem('default_collapse_sidebar') === 'true'
|
onCollapseChange={(collapsed) => {
|
||||||
|
setIsCollapsed(collapsed);
|
||||||
|
}}
|
||||||
|
selectedKeys={selectedKeys}
|
||||||
|
renderWrapper={({ itemElement, isSubNav, isInSubNav, props }) => {
|
||||||
|
let chatLink = localStorage.getItem('chat_link');
|
||||||
|
if (!chatLink) {
|
||||||
|
let chats = localStorage.getItem('chats');
|
||||||
|
if (chats) {
|
||||||
|
chats = JSON.parse(chats);
|
||||||
|
if (Array.isArray(chats) && chats.length > 0) {
|
||||||
|
for (let i = 0; i < chats.length; i++) {
|
||||||
|
routerMap['chat' + i] = '/chat/' + i;
|
||||||
|
}
|
||||||
|
if (chats.length > 1) {
|
||||||
|
// delete /chat
|
||||||
|
if (routerMap['chat']) {
|
||||||
|
delete routerMap['chat'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// rename /chat to /chat/0
|
||||||
|
routerMap['chat'] = '/chat/0';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
isCollapsed={isCollapsed}
|
}
|
||||||
onCollapseChange={(collapsed) => {
|
return (
|
||||||
setIsCollapsed(collapsed);
|
<Link
|
||||||
}}
|
style={{ textDecoration: 'none' }}
|
||||||
selectedKeys={selectedKeys}
|
to={routerMap[props.itemKey]}
|
||||||
renderWrapper={({ itemElement, isSubNav, isInSubNav, props }) => {
|
>
|
||||||
return (
|
{itemElement}
|
||||||
<Link
|
</Link>
|
||||||
style={{ textDecoration: 'none' }}
|
);
|
||||||
to={routerMap[props.itemKey]}
|
}}
|
||||||
>
|
items={headerButtons}
|
||||||
{itemElement}
|
onSelect={(key) => {
|
||||||
</Link>
|
setSelectedKeys([key.itemKey]);
|
||||||
);
|
}}
|
||||||
}}
|
footer={
|
||||||
items={headerButtons}
|
<>
|
||||||
onSelect={(key) => {
|
{isMobile() && (
|
||||||
setSelectedKeys([key.itemKey]);
|
<Switch
|
||||||
}}
|
checkedText='🌞'
|
||||||
header={{
|
size={'small'}
|
||||||
logo: (
|
checked={theme === 'dark'}
|
||||||
<img src={logo} alt='logo' style={{ marginRight: '0.75em' }} />
|
uncheckedText='🌙'
|
||||||
),
|
onChange={(checked) => {
|
||||||
text: systemName,
|
setTheme(checked);
|
||||||
}}
|
}}
|
||||||
// footer={{
|
/>
|
||||||
// text: '© 2021 NekoAPI',
|
)}
|
||||||
// }}
|
</>
|
||||||
>
|
}
|
||||||
<Nav.Footer collapseButton={true}></Nav.Footer>
|
>
|
||||||
</Nav>
|
<Nav.Footer collapseButton={true}></Nav.Footer>
|
||||||
</div>
|
</Nav>
|
||||||
</Layout>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from '../helpers';
|
} from '../helpers';
|
||||||
|
|
||||||
import { ITEMS_PER_PAGE } from '../constants';
|
import { ITEMS_PER_PAGE } from '../constants';
|
||||||
import { renderQuota } from '../helpers/render';
|
import { renderGroup, renderQuota } from '../helpers/render';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
Modal,
|
Modal,
|
||||||
Popconfirm,
|
Popconfirm,
|
||||||
Popover,
|
Popover,
|
||||||
|
Space,
|
||||||
SplitButtonGroup,
|
SplitButtonGroup,
|
||||||
Table,
|
Table,
|
||||||
Tag,
|
Tag,
|
||||||
@@ -24,17 +25,6 @@ import {
|
|||||||
import { IconTreeTriangleDown } from '@douyinfe/semi-icons';
|
import { IconTreeTriangleDown } from '@douyinfe/semi-icons';
|
||||||
import EditToken from '../pages/Token/EditToken';
|
import EditToken from '../pages/Token/EditToken';
|
||||||
|
|
||||||
const COPY_OPTIONS = [
|
|
||||||
{ key: 'next', text: 'ChatGPT Next Web', value: 'next' },
|
|
||||||
{ key: 'ama', text: 'ChatGPT Web & Midjourney', value: 'ama' },
|
|
||||||
{ key: 'opencat', text: 'OpenCat', value: 'opencat' },
|
|
||||||
];
|
|
||||||
|
|
||||||
const OPEN_LINK_OPTIONS = [
|
|
||||||
{ key: 'ama', text: 'ChatGPT Web & Midjourney', value: 'ama' },
|
|
||||||
{ key: 'opencat', text: 'OpenCat', value: 'opencat' },
|
|
||||||
];
|
|
||||||
|
|
||||||
function renderTimestamp(timestamp) {
|
function renderTimestamp(timestamp) {
|
||||||
return <>{timestamp2string(timestamp)}</>;
|
return <>{timestamp2string(timestamp)}</>;
|
||||||
}
|
}
|
||||||
@@ -87,28 +77,6 @@ function renderStatus(status, model_limits_enabled = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TokensTable = () => {
|
const TokensTable = () => {
|
||||||
const link_menu = [
|
|
||||||
{
|
|
||||||
node: 'item',
|
|
||||||
key: 'next',
|
|
||||||
name: 'ChatGPT Next Web',
|
|
||||||
onClick: () => {
|
|
||||||
onOpenLink('next');
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ node: 'item', key: 'ama', name: 'AMA 问天', value: 'ama' },
|
|
||||||
{
|
|
||||||
node: 'item',
|
|
||||||
key: 'next-mj',
|
|
||||||
name: 'ChatGPT Web & Midjourney',
|
|
||||||
value: 'next-mj',
|
|
||||||
onClick: () => {
|
|
||||||
onOpenLink('next-mj');
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ node: 'item', key: 'opencat', name: 'OpenCat', value: 'opencat' },
|
|
||||||
];
|
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
title: '名称',
|
title: '名称',
|
||||||
@@ -119,7 +87,14 @@ const TokensTable = () => {
|
|||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
key: 'status',
|
key: 'status',
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return <div>{renderStatus(text, record.model_limits_enabled)}</div>;
|
return (
|
||||||
|
<div>
|
||||||
|
<Space>
|
||||||
|
{renderStatus(text, record.model_limits_enabled)}
|
||||||
|
{renderGroup(record.group)}
|
||||||
|
</Space>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -169,149 +144,174 @@ const TokensTable = () => {
|
|||||||
{
|
{
|
||||||
title: '',
|
title: '',
|
||||||
dataIndex: 'operate',
|
dataIndex: 'operate',
|
||||||
render: (text, record, index) => (
|
render: (text, record, index) => {
|
||||||
<div>
|
let chats = localStorage.getItem('chats');
|
||||||
<Popover
|
let chatsArray = [];
|
||||||
content={'sk-' + record.key}
|
let chatLink = localStorage.getItem('chat_link');
|
||||||
style={{ padding: 20 }}
|
let mjLink = localStorage.getItem('chat_link2');
|
||||||
position='top'
|
let shouldUseCustom = true;
|
||||||
>
|
if (chatLink) {
|
||||||
<Button theme='light' type='tertiary' style={{ marginRight: 1 }}>
|
shouldUseCustom = false;
|
||||||
查看
|
chatLink += `/#/?settings={"key":"{key}","url":"{address}"}`;
|
||||||
</Button>
|
chatsArray.push({
|
||||||
</Popover>
|
node: 'item',
|
||||||
<Button
|
key: 'default',
|
||||||
theme='light'
|
name: 'ChatGPT Next Web',
|
||||||
type='secondary'
|
onClick: () => {
|
||||||
style={{ marginRight: 1 }}
|
onOpenLink('default', chatLink, record);
|
||||||
onClick={async (text) => {
|
},
|
||||||
await copyText('sk-' + record.key);
|
});
|
||||||
}}
|
}
|
||||||
>
|
if (mjLink) {
|
||||||
复制
|
shouldUseCustom = false;
|
||||||
</Button>
|
mjLink += `/#/?settings={"key":"{key}","url":"{address}"}`;
|
||||||
<SplitButtonGroup
|
chatsArray.push({
|
||||||
style={{ marginRight: 1 }}
|
node: 'item',
|
||||||
aria-label='项目操作按钮组'
|
key: 'mj',
|
||||||
>
|
name: 'ChatGPT Next Midjourney',
|
||||||
<Button
|
onClick: () => {
|
||||||
theme='light'
|
onOpenLink('mj', mjLink, record);
|
||||||
style={{ color: 'rgba(var(--semi-teal-7), 1)' }}
|
},
|
||||||
onClick={() => {
|
});
|
||||||
onOpenLink('next', record.key);
|
}
|
||||||
}}
|
if (shouldUseCustom) {
|
||||||
|
try {
|
||||||
|
// console.log(chats);
|
||||||
|
chats = JSON.parse(chats);
|
||||||
|
// check chats is array
|
||||||
|
if (Array.isArray(chats)) {
|
||||||
|
for (let i = 0; i < chats.length; i++) {
|
||||||
|
let chat = {};
|
||||||
|
chat.node = 'item';
|
||||||
|
// c is a map
|
||||||
|
// chat.key = chats[i].name;
|
||||||
|
// console.log(chats[i])
|
||||||
|
for (let key in chats[i]) {
|
||||||
|
if (chats[i].hasOwnProperty(key)) {
|
||||||
|
chat.key = i;
|
||||||
|
chat.name = key;
|
||||||
|
chat.onClick = () => {
|
||||||
|
onOpenLink(key, chats[i][key], record);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chatsArray.push(chat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
showError('聊天链接配置错误,请联系管理员');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Popover
|
||||||
|
content={'sk-' + record.key}
|
||||||
|
style={{ padding: 20 }}
|
||||||
|
position='top'
|
||||||
>
|
>
|
||||||
聊天
|
<Button theme='light' type='tertiary' style={{ marginRight: 1 }}>
|
||||||
</Button>
|
查看
|
||||||
<Dropdown
|
</Button>
|
||||||
trigger='click'
|
</Popover>
|
||||||
position='bottomRight'
|
|
||||||
menu={[
|
|
||||||
{
|
|
||||||
node: 'item',
|
|
||||||
key: 'next',
|
|
||||||
disabled: !localStorage.getItem('chat_link'),
|
|
||||||
name: 'ChatGPT Next Web',
|
|
||||||
onClick: () => {
|
|
||||||
onOpenLink('next', record.key);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
node: 'item',
|
|
||||||
key: 'next-mj',
|
|
||||||
disabled: !localStorage.getItem('chat_link2'),
|
|
||||||
name: 'ChatGPT Web & Midjourney',
|
|
||||||
onClick: () => {
|
|
||||||
onOpenLink('next-mj', record.key);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
node: 'item',
|
|
||||||
key: 'lobe',
|
|
||||||
name: 'Lobe Chat',
|
|
||||||
onClick: () => {
|
|
||||||
onOpenLink('lobe', record.key);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
node: 'item',
|
|
||||||
key: 'ama',
|
|
||||||
name: 'AMA 问天(BotGem)',
|
|
||||||
onClick: () => {
|
|
||||||
onOpenLink('ama', record.key);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
node: 'item',
|
|
||||||
key: 'opencat',
|
|
||||||
name: 'OpenCat',
|
|
||||||
onClick: () => {
|
|
||||||
onOpenLink('opencat', record.key);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
style={{
|
|
||||||
padding: '8px 4px',
|
|
||||||
color: 'rgba(var(--semi-teal-7), 1)',
|
|
||||||
}}
|
|
||||||
type='primary'
|
|
||||||
icon={<IconTreeTriangleDown />}
|
|
||||||
></Button>
|
|
||||||
</Dropdown>
|
|
||||||
</SplitButtonGroup>
|
|
||||||
<Popconfirm
|
|
||||||
title='确定是否要删除此令牌?'
|
|
||||||
content='此修改将不可逆'
|
|
||||||
okType={'danger'}
|
|
||||||
position={'left'}
|
|
||||||
onConfirm={() => {
|
|
||||||
manageToken(record.id, 'delete', record).then(() => {
|
|
||||||
removeRecord(record.key);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Button theme='light' type='danger' style={{ marginRight: 1 }}>
|
|
||||||
删除
|
|
||||||
</Button>
|
|
||||||
</Popconfirm>
|
|
||||||
{record.status === 1 ? (
|
|
||||||
<Button
|
|
||||||
theme='light'
|
|
||||||
type='warning'
|
|
||||||
style={{ marginRight: 1 }}
|
|
||||||
onClick={async () => {
|
|
||||||
manageToken(record.id, 'disable', record);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
禁用
|
|
||||||
</Button>
|
|
||||||
) : (
|
|
||||||
<Button
|
<Button
|
||||||
theme='light'
|
theme='light'
|
||||||
type='secondary'
|
type='secondary'
|
||||||
style={{ marginRight: 1 }}
|
style={{ marginRight: 1 }}
|
||||||
onClick={async () => {
|
onClick={async (text) => {
|
||||||
manageToken(record.id, 'enable', record);
|
await copyText('sk-' + record.key);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
启用
|
复制
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
<SplitButtonGroup
|
||||||
<Button
|
style={{ marginRight: 1 }}
|
||||||
theme='light'
|
aria-label='项目操作按钮组'
|
||||||
type='tertiary'
|
>
|
||||||
style={{ marginRight: 1 }}
|
<Button
|
||||||
onClick={() => {
|
theme='light'
|
||||||
setEditingToken(record);
|
style={{ color: 'rgba(var(--semi-teal-7), 1)' }}
|
||||||
setShowEdit(true);
|
onClick={() => {
|
||||||
}}
|
if (chatsArray.length === 0) {
|
||||||
>
|
showError('请联系管理员配置聊天链接');
|
||||||
编辑
|
} else {
|
||||||
</Button>
|
onOpenLink(
|
||||||
</div>
|
'default',
|
||||||
),
|
chats[0][Object.keys(chats[0])[0]],
|
||||||
|
record,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
聊天
|
||||||
|
</Button>
|
||||||
|
<Dropdown
|
||||||
|
trigger='click'
|
||||||
|
position='bottomRight'
|
||||||
|
menu={chatsArray}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
style={{
|
||||||
|
padding: '8px 4px',
|
||||||
|
color: 'rgba(var(--semi-teal-7), 1)',
|
||||||
|
}}
|
||||||
|
type='primary'
|
||||||
|
icon={<IconTreeTriangleDown />}
|
||||||
|
></Button>
|
||||||
|
</Dropdown>
|
||||||
|
</SplitButtonGroup>
|
||||||
|
<Popconfirm
|
||||||
|
title='确定是否要删除此令牌?'
|
||||||
|
content='此修改将不可逆'
|
||||||
|
okType={'danger'}
|
||||||
|
position={'left'}
|
||||||
|
onConfirm={() => {
|
||||||
|
manageToken(record.id, 'delete', record).then(() => {
|
||||||
|
removeRecord(record.key);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button theme='light' type='danger' style={{ marginRight: 1 }}>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
{record.status === 1 ? (
|
||||||
|
<Button
|
||||||
|
theme='light'
|
||||||
|
type='warning'
|
||||||
|
style={{ marginRight: 1 }}
|
||||||
|
onClick={async () => {
|
||||||
|
manageToken(record.id, 'disable', record);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
禁用
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
theme='light'
|
||||||
|
type='secondary'
|
||||||
|
style={{ marginRight: 1 }}
|
||||||
|
onClick={async () => {
|
||||||
|
manageToken(record.id, 'enable', record);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
启用
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
theme='light'
|
||||||
|
type='tertiary'
|
||||||
|
style={{ marginRight: 1 }}
|
||||||
|
onClick={() => {
|
||||||
|
setEditingToken(record);
|
||||||
|
setShowEdit(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -325,8 +325,7 @@ const TokensTable = () => {
|
|||||||
const [searchKeyword, setSearchKeyword] = useState('');
|
const [searchKeyword, setSearchKeyword] = useState('');
|
||||||
const [searchToken, setSearchToken] = useState('');
|
const [searchToken, setSearchToken] = useState('');
|
||||||
const [searching, setSearching] = useState(false);
|
const [searching, setSearching] = useState(false);
|
||||||
const [showTopUpModal, setShowTopUpModal] = useState(false);
|
const [chats, setChats] = useState([]);
|
||||||
const [targetTokenIdx, setTargetTokenIdx] = useState(0);
|
|
||||||
const [editingToken, setEditingToken] = useState({
|
const [editingToken, setEditingToken] = useState({
|
||||||
id: undefined,
|
id: undefined,
|
||||||
});
|
});
|
||||||
@@ -371,16 +370,6 @@ const TokensTable = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onPaginationChange = (e, { activePage }) => {
|
|
||||||
(async () => {
|
|
||||||
if (activePage === Math.ceil(tokens.length / pageSize) + 1) {
|
|
||||||
// In this case we have to load more data and then append them.
|
|
||||||
await loadTokens(activePage - 1);
|
|
||||||
}
|
|
||||||
setActivePage(activePage);
|
|
||||||
})();
|
|
||||||
};
|
|
||||||
|
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
await loadTokens(activePage - 1);
|
await loadTokens(activePage - 1);
|
||||||
};
|
};
|
||||||
@@ -397,7 +386,8 @@ const TokensTable = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onOpenLink = async (type, key) => {
|
const onOpenLink = async (type, url, record) => {
|
||||||
|
// console.log(type, url, key);
|
||||||
let status = localStorage.getItem('status');
|
let status = localStorage.getItem('status');
|
||||||
let serverAddress = '';
|
let serverAddress = '';
|
||||||
if (status) {
|
if (status) {
|
||||||
@@ -408,36 +398,39 @@ const TokensTable = () => {
|
|||||||
serverAddress = window.location.origin;
|
serverAddress = window.location.origin;
|
||||||
}
|
}
|
||||||
let encodedServerAddress = encodeURIComponent(serverAddress);
|
let encodedServerAddress = encodeURIComponent(serverAddress);
|
||||||
const chatLink = localStorage.getItem('chat_link');
|
url = url.replace('{address}', encodedServerAddress);
|
||||||
const mjLink = localStorage.getItem('chat_link2');
|
url = url.replace('{key}', 'sk-' + record.key);
|
||||||
let defaultUrl;
|
// console.log(url);
|
||||||
|
// const chatLink = localStorage.getItem('chat_link');
|
||||||
if (chatLink) {
|
// const mjLink = localStorage.getItem('chat_link2');
|
||||||
defaultUrl =
|
// let defaultUrl;
|
||||||
chatLink + `/#/?settings={"key":"sk-${key}","url":"${serverAddress}"}`;
|
//
|
||||||
}
|
// if (chatLink) {
|
||||||
let url;
|
// defaultUrl =
|
||||||
switch (type) {
|
// chatLink + `/#/?settings={"key":"sk-${key}","url":"${serverAddress}"}`;
|
||||||
case 'ama':
|
// }
|
||||||
url = `ama://set-api-key?server=${encodedServerAddress}&key=sk-${key}`;
|
// let url;
|
||||||
break;
|
// switch (type) {
|
||||||
case 'opencat':
|
// case 'ama':
|
||||||
url = `opencat://team/join?domain=${encodedServerAddress}&token=sk-${key}`;
|
// url = `ama://set-api-key?server=${encodedServerAddress}&key=sk-${key}`;
|
||||||
break;
|
// break;
|
||||||
case 'lobe':
|
// case 'opencat':
|
||||||
url = `https://chat-preview.lobehub.com/?settings={"keyVaults":{"openai":{"apiKey":"sk-${key}","baseURL":"${encodedServerAddress}/v1"}}}`;
|
// url = `opencat://team/join?domain=${encodedServerAddress}&token=sk-${key}`;
|
||||||
break;
|
// break;
|
||||||
case 'next-mj':
|
// case 'lobe':
|
||||||
url =
|
// url = `https://chat-preview.lobehub.com/?settings={"keyVaults":{"openai":{"apiKey":"sk-${key}","baseURL":"${encodedServerAddress}/v1"}}}`;
|
||||||
mjLink + `/#/?settings={"key":"sk-${key}","url":"${serverAddress}"}`;
|
// break;
|
||||||
break;
|
// case 'next-mj':
|
||||||
default:
|
// url =
|
||||||
if (!chatLink) {
|
// mjLink + `/#/?settings={"key":"sk-${key}","url":"${serverAddress}"}`;
|
||||||
showError('管理员未设置聊天链接');
|
// break;
|
||||||
return;
|
// default:
|
||||||
}
|
// if (!chatLink) {
|
||||||
url = defaultUrl;
|
// showError('管理员未设置聊天链接');
|
||||||
}
|
// return;
|
||||||
|
// }
|
||||||
|
// url = defaultUrl;
|
||||||
|
// }
|
||||||
|
|
||||||
window.open(url, '_blank');
|
window.open(url, '_blank');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ const UsersTable = () => {
|
|||||||
title='确定?'
|
title='确定?'
|
||||||
okType={'warning'}
|
okType={'warning'}
|
||||||
onConfirm={() => {
|
onConfirm={() => {
|
||||||
manageUser(record.username, 'promote', record);
|
manageUser(record.id, 'promote', record);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button theme='light' type='warning' style={{ marginRight: 1 }}>
|
<Button theme='light' type='warning' style={{ marginRight: 1 }}>
|
||||||
@@ -162,7 +162,7 @@ const UsersTable = () => {
|
|||||||
title='确定?'
|
title='确定?'
|
||||||
okType={'warning'}
|
okType={'warning'}
|
||||||
onConfirm={() => {
|
onConfirm={() => {
|
||||||
manageUser(record.username, 'demote', record);
|
manageUser(record.id, 'demote', record);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
@@ -179,7 +179,7 @@ const UsersTable = () => {
|
|||||||
type='warning'
|
type='warning'
|
||||||
style={{ marginRight: 1 }}
|
style={{ marginRight: 1 }}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
manageUser(record.username, 'disable', record);
|
manageUser(record.id, 'disable', record);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
禁用
|
禁用
|
||||||
@@ -190,7 +190,7 @@ const UsersTable = () => {
|
|||||||
type='secondary'
|
type='secondary'
|
||||||
style={{ marginRight: 1 }}
|
style={{ marginRight: 1 }}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
manageUser(record.username, 'enable', record);
|
manageUser(record.id, 'enable', record);
|
||||||
}}
|
}}
|
||||||
disabled={record.status === 3}
|
disabled={record.status === 3}
|
||||||
>
|
>
|
||||||
@@ -214,7 +214,7 @@ const UsersTable = () => {
|
|||||||
okType={'danger'}
|
okType={'danger'}
|
||||||
position={'left'}
|
position={'left'}
|
||||||
onConfirm={() => {
|
onConfirm={() => {
|
||||||
manageUser(record.username, 'delete', record).then(() => {
|
manageUser(record.id, 'delete', record).then(() => {
|
||||||
removeRecord(record.id);
|
removeRecord(record.id);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
@@ -303,9 +303,9 @@ const UsersTable = () => {
|
|||||||
fetchGroups().then();
|
fetchGroups().then();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const manageUser = async (username, action, record) => {
|
const manageUser = async (userId, action, record) => {
|
||||||
const res = await API.post('/api/user/manage', {
|
const res = await API.post('/api/user/manage', {
|
||||||
username,
|
id: userId,
|
||||||
action,
|
action,
|
||||||
});
|
});
|
||||||
const { success, message } = res.data;
|
const { success, message } = res.data;
|
||||||
|
|||||||
68
web/src/components/fetchTokenKeys.js
Normal file
68
web/src/components/fetchTokenKeys.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
// src/hooks/useTokenKeys.js
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { API, showError } from '../helpers';
|
||||||
|
|
||||||
|
async function fetchTokenKeys() {
|
||||||
|
try {
|
||||||
|
const response = await API.get('/api/token/?p=0&size=100');
|
||||||
|
const { success, data } = response.data;
|
||||||
|
if (success) {
|
||||||
|
const activeTokens = data.filter((token) => token.status === 1);
|
||||||
|
return activeTokens.map((token) => token.key);
|
||||||
|
} else {
|
||||||
|
throw new Error('Failed to fetch token keys');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching token keys:', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getServerAddress() {
|
||||||
|
let status = localStorage.getItem('status');
|
||||||
|
let serverAddress = '';
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
try {
|
||||||
|
status = JSON.parse(status);
|
||||||
|
serverAddress = status.server_address || '';
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to parse status from localStorage:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!serverAddress) {
|
||||||
|
serverAddress = window.location.origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
return serverAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useTokenKeys(id) {
|
||||||
|
const [keys, setKeys] = useState([]);
|
||||||
|
// const [chatLink, setChatLink] = useState('');
|
||||||
|
const [serverAddress, setServerAddress] = useState('');
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadAllData = async () => {
|
||||||
|
const fetchedKeys = await fetchTokenKeys();
|
||||||
|
if (fetchedKeys.length === 0) {
|
||||||
|
showError('当前没有可用的启用令牌,请确认是否有令牌处于启用状态!');
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.href = '/token';
|
||||||
|
}, 1500); // 延迟 1.5 秒后跳转
|
||||||
|
}
|
||||||
|
setKeys(fetchedKeys);
|
||||||
|
setIsLoading(false);
|
||||||
|
// setChatLink(link);
|
||||||
|
|
||||||
|
const address = getServerAddress();
|
||||||
|
setServerAddress(address);
|
||||||
|
};
|
||||||
|
|
||||||
|
loadAllData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return { keys, serverAddress, isLoading };
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ export function setStatusData(data) {
|
|||||||
localStorage.setItem('enable_drawing', data.enable_drawing);
|
localStorage.setItem('enable_drawing', data.enable_drawing);
|
||||||
localStorage.setItem('enable_task', data.enable_task);
|
localStorage.setItem('enable_task', data.enable_task);
|
||||||
localStorage.setItem('enable_data_export', data.enable_data_export);
|
localStorage.setItem('enable_data_export', data.enable_data_export);
|
||||||
|
localStorage.setItem('chats', JSON.stringify(data.chats));
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
'data_export_default_time',
|
'data_export_default_time',
|
||||||
data.data_export_default_time,
|
data.data_export_default_time,
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ export function renderText(text, limit) {
|
|||||||
export function renderGroup(group) {
|
export function renderGroup(group) {
|
||||||
if (group === '') {
|
if (group === '') {
|
||||||
return (
|
return (
|
||||||
<Tag size='large' key='default'>
|
<Tag size='large' key='default' color='orange'>
|
||||||
unknown
|
用户分组
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,12 @@ body {
|
|||||||
scrollbar-width: none;
|
scrollbar-width: none;
|
||||||
color: var(--semi-color-text-0) !important;
|
color: var(--semi-color-text-0) !important;
|
||||||
background-color: var(--semi-color-bg-0) !important;
|
background-color: var(--semi-color-bg-0) !important;
|
||||||
height: 100%;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
#root {
|
#root {
|
||||||
height: 100%;
|
height: 100vh;
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 767px) {
|
@media only screen and (max-width: 767px) {
|
||||||
@@ -50,14 +51,25 @@ body {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.semi-layout {
|
/*.semi-layout {*/
|
||||||
height: 100%;
|
/* height: 100%;*/
|
||||||
}
|
/*}*/
|
||||||
|
|
||||||
.tableShow {
|
.tableShow {
|
||||||
display: revert;
|
display: revert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.semi-chat {
|
||||||
|
padding-top: 0 !important;
|
||||||
|
padding-bottom: 0 !important;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.semi-chat-chatBox-content {
|
||||||
|
min-width: auto;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
.tableHiddle {
|
.tableHiddle {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import ReactDOM from 'react-dom/client';
|
|||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import HeaderBar from './components/HeaderBar';
|
import HeaderBar from './components/HeaderBar';
|
||||||
import Footer from './components/Footer';
|
|
||||||
import 'semantic-ui-offline/semantic.min.css';
|
import 'semantic-ui-offline/semantic.min.css';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
import { UserProvider } from './context/User';
|
import { UserProvider } from './context/User';
|
||||||
@@ -13,35 +12,40 @@ import { StatusProvider } from './context/Status';
|
|||||||
import { Layout } from '@douyinfe/semi-ui';
|
import { Layout } from '@douyinfe/semi-ui';
|
||||||
import SiderBar from './components/SiderBar';
|
import SiderBar from './components/SiderBar';
|
||||||
import { ThemeProvider } from './context/Theme';
|
import { ThemeProvider } from './context/Theme';
|
||||||
|
import FooterBar from './components/Footer';
|
||||||
|
|
||||||
// initialization
|
// initialization
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||||
const { Sider, Content, Header } = Layout;
|
const { Sider, Content, Header, Footer } = Layout;
|
||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<StatusProvider>
|
<StatusProvider>
|
||||||
<UserProvider>
|
<UserProvider>
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<ThemeProvider>
|
<ThemeProvider>
|
||||||
<Layout>
|
<Layout
|
||||||
<Sider>
|
style={{
|
||||||
<SiderBar />
|
height: '100vh',
|
||||||
</Sider>
|
display: 'flex',
|
||||||
<Layout>
|
flexDirection: 'column',
|
||||||
<Header>
|
}}
|
||||||
<HeaderBar />
|
>
|
||||||
</Header>
|
<Header>
|
||||||
<Content
|
<HeaderBar />
|
||||||
style={{
|
</Header>
|
||||||
padding: '24px',
|
<Layout style={{ flex: 1, overflow: 'hidden' }}>
|
||||||
}}
|
<Sider>
|
||||||
>
|
<SiderBar />
|
||||||
<App />
|
</Sider>
|
||||||
</Content>
|
<Layout>
|
||||||
<Layout.Footer>
|
<Content style={{ overflowY: 'auto', padding: '24px' }}>
|
||||||
<Footer></Footer>
|
<App />
|
||||||
</Layout.Footer>
|
</Content>
|
||||||
|
<Layout.Footer>
|
||||||
|
<FooterBar></FooterBar>
|
||||||
|
</Layout.Footer>
|
||||||
|
</Layout>
|
||||||
</Layout>
|
</Layout>
|
||||||
<ToastContainer />
|
<ToastContainer />
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|||||||
@@ -1,14 +1,51 @@
|
|||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
|
import { useTokenKeys } from '../../components/fetchTokenKeys';
|
||||||
|
import { Banner, Layout } from '@douyinfe/semi-ui';
|
||||||
|
import { useParams } from 'react-router-dom';
|
||||||
|
|
||||||
const Chat = () => {
|
const ChatPage = () => {
|
||||||
const chatLink = localStorage.getItem('chat_link');
|
const { id } = useParams();
|
||||||
|
const { keys, serverAddress, isLoading } = useTokenKeys(id);
|
||||||
|
|
||||||
return (
|
const comLink = (key) => {
|
||||||
|
// console.log('chatLink:', chatLink);
|
||||||
|
if (!serverAddress || !key) return '';
|
||||||
|
let link = localStorage.getItem('chat_link');
|
||||||
|
if (link) {
|
||||||
|
link = `${link}/#/?settings={"key":"sk-${key}","url":"${encodeURIComponent(serverAddress)}"}`;
|
||||||
|
} else if (id) {
|
||||||
|
let chats = localStorage.getItem('chats');
|
||||||
|
if (chats) {
|
||||||
|
chats = JSON.parse(chats);
|
||||||
|
if (Array.isArray(chats) && chats.length > 0) {
|
||||||
|
for (let k in chats[id]) {
|
||||||
|
link = chats[id][k];
|
||||||
|
link = link.replace('{address}', encodeURIComponent(serverAddress));
|
||||||
|
link = link.replace('{key}', 'sk-' + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return link;
|
||||||
|
};
|
||||||
|
|
||||||
|
const iframeSrc = keys.length > 0 ? comLink(keys[0]) : '';
|
||||||
|
|
||||||
|
return !isLoading && iframeSrc ? (
|
||||||
<iframe
|
<iframe
|
||||||
src={chatLink}
|
src={iframeSrc}
|
||||||
style={{ width: '100%', height: '85vh', border: 'none' }}
|
style={{ width: '100%', height: '85vh', border: 'none' }}
|
||||||
|
title='Token Frame'
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<div>
|
||||||
|
<Layout>
|
||||||
|
<Layout.Header>
|
||||||
|
<Banner description={'正在跳转......'} type={'warning'} />
|
||||||
|
</Layout.Header>
|
||||||
|
</Layout>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Chat;
|
export default ChatPage;
|
||||||
|
|||||||
26
web/src/pages/Chat2Link/index.js
Normal file
26
web/src/pages/Chat2Link/index.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useTokenKeys } from '../../components/fetchTokenKeys';
|
||||||
|
|
||||||
|
const chat2page = () => {
|
||||||
|
const { keys, chatLink, serverAddress, isLoading } = useTokenKeys();
|
||||||
|
|
||||||
|
const comLink = (key) => {
|
||||||
|
if (!chatLink || !serverAddress || !key) return '';
|
||||||
|
return `${chatLink}/#/?settings={"key":"sk-${key}","url":"${encodeURIComponent(serverAddress)}"}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (keys.length > 0) {
|
||||||
|
const redirectLink = comLink(keys[0]);
|
||||||
|
if (redirectLink) {
|
||||||
|
window.location.href = redirectLink;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h3>正在加载,请稍候...</h3>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default chat2page;
|
||||||
162
web/src/pages/Setting/Operation/SettingsChats.js
Normal file
162
web/src/pages/Setting/Operation/SettingsChats.js
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
import React, { useEffect, useState, useRef } from 'react';
|
||||||
|
import {
|
||||||
|
Banner,
|
||||||
|
Button,
|
||||||
|
Col,
|
||||||
|
Form,
|
||||||
|
Popconfirm,
|
||||||
|
Row,
|
||||||
|
Space,
|
||||||
|
Spin,
|
||||||
|
} from '@douyinfe/semi-ui';
|
||||||
|
import {
|
||||||
|
compareObjects,
|
||||||
|
API,
|
||||||
|
showError,
|
||||||
|
showSuccess,
|
||||||
|
showWarning,
|
||||||
|
verifyJSON,
|
||||||
|
verifyJSONPromise,
|
||||||
|
} from '../../../helpers';
|
||||||
|
|
||||||
|
export default function SettingsChats(props) {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [inputs, setInputs] = useState({
|
||||||
|
Chats: '[]',
|
||||||
|
});
|
||||||
|
const refForm = useRef();
|
||||||
|
const [inputsRow, setInputsRow] = useState(inputs);
|
||||||
|
|
||||||
|
async function onSubmit() {
|
||||||
|
try {
|
||||||
|
console.log('Starting validation...');
|
||||||
|
await refForm.current
|
||||||
|
.validate()
|
||||||
|
.then(() => {
|
||||||
|
console.log('Validation passed');
|
||||||
|
const updateArray = compareObjects(inputs, inputsRow);
|
||||||
|
if (!updateArray.length) return showWarning('你似乎并没有修改什么');
|
||||||
|
const requestQueue = updateArray.map((item) => {
|
||||||
|
let value = '';
|
||||||
|
if (typeof inputs[item.key] === 'boolean') {
|
||||||
|
value = String(inputs[item.key]);
|
||||||
|
} else {
|
||||||
|
value = inputs[item.key];
|
||||||
|
}
|
||||||
|
return API.put('/api/option/', {
|
||||||
|
key: item.key,
|
||||||
|
value,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
setLoading(true);
|
||||||
|
Promise.all(requestQueue)
|
||||||
|
.then((res) => {
|
||||||
|
if (requestQueue.length === 1) {
|
||||||
|
if (res.includes(undefined)) return;
|
||||||
|
} else if (requestQueue.length > 1) {
|
||||||
|
if (res.includes(undefined))
|
||||||
|
return showError('部分保存失败,请重试');
|
||||||
|
}
|
||||||
|
showSuccess('保存成功');
|
||||||
|
props.refresh();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
showError('保存失败,请重试');
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Validation failed:', error);
|
||||||
|
showError('请检查输入');
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
showError('请检查输入');
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resetModelRatio() {
|
||||||
|
try {
|
||||||
|
let res = await API.post(`/api/option/rest_model_ratio`);
|
||||||
|
// return {success, message}
|
||||||
|
if (res.data.success) {
|
||||||
|
showSuccess(res.data.message);
|
||||||
|
props.refresh();
|
||||||
|
} else {
|
||||||
|
showError(res.data.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
showError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const currentInputs = {};
|
||||||
|
for (let key in props.options) {
|
||||||
|
if (Object.keys(inputs).includes(key)) {
|
||||||
|
if (key === 'Chats') {
|
||||||
|
const obj = JSON.parse(props.options[key]);
|
||||||
|
currentInputs[key] = JSON.stringify(obj, null, 2);
|
||||||
|
} else {
|
||||||
|
currentInputs[key] = props.options[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setInputs(currentInputs);
|
||||||
|
setInputsRow(structuredClone(currentInputs));
|
||||||
|
refForm.current.setValues(currentInputs);
|
||||||
|
}, [props.options]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Spin spinning={loading}>
|
||||||
|
<Form
|
||||||
|
values={inputs}
|
||||||
|
getFormApi={(formAPI) => (refForm.current = formAPI)}
|
||||||
|
style={{ marginBottom: 15 }}
|
||||||
|
>
|
||||||
|
<Form.Section text={'令牌聊天设置'}>
|
||||||
|
<Banner
|
||||||
|
type='warning'
|
||||||
|
description={
|
||||||
|
'必须将上方聊天链接全部设置为空,才能使用下方聊天设置功能'
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Banner
|
||||||
|
type='info'
|
||||||
|
description={
|
||||||
|
'链接中的{key}将自动替换为sk-xxxx,{address}将自动替换为系统设置的服务器地址,末尾不带/和/v1'
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Form.TextArea
|
||||||
|
label={'聊天配置'}
|
||||||
|
extraText={''}
|
||||||
|
placeholder={'为一个 JSON 文本'}
|
||||||
|
field={'Chats'}
|
||||||
|
autosize={{ minRows: 6, maxRows: 12 }}
|
||||||
|
trigger='blur'
|
||||||
|
stopValidateWithError
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
validator: (rule, value) => {
|
||||||
|
return verifyJSON(value);
|
||||||
|
},
|
||||||
|
message: '不是合法的 JSON 字符串',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
onChange={(value) =>
|
||||||
|
setInputs({
|
||||||
|
...inputs,
|
||||||
|
Chats: value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Form.Section>
|
||||||
|
</Form>
|
||||||
|
<Space>
|
||||||
|
<Button onClick={onSubmit}>保存聊天设置</Button>
|
||||||
|
</Space>
|
||||||
|
</Spin>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect, useState, useRef } from 'react';
|
import React, { useEffect, useState, useRef } from 'react';
|
||||||
import { Button, Col, Form, Row, Spin } from '@douyinfe/semi-ui';
|
import { Banner, Button, Col, Form, Row, Spin } from '@douyinfe/semi-ui';
|
||||||
import {
|
import {
|
||||||
compareObjects,
|
compareObjects,
|
||||||
API,
|
API,
|
||||||
@@ -74,6 +74,10 @@ export default function GeneralSettings(props) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Spin spinning={loading}>
|
<Spin spinning={loading}>
|
||||||
|
<Banner
|
||||||
|
type='warning'
|
||||||
|
description={'聊天链接功能已经弃用,请使用下方聊天设置功能'}
|
||||||
|
/>
|
||||||
<Form
|
<Form
|
||||||
values={inputs}
|
values={inputs}
|
||||||
getFormApi={(formAPI) => (refForm.current = formAPI)}
|
getFormApi={(formAPI) => (refForm.current = formAPI)}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export default function SettingsMagnification(props) {
|
|||||||
ModelRatio: '',
|
ModelRatio: '',
|
||||||
CompletionRatio: '',
|
CompletionRatio: '',
|
||||||
GroupRatio: '',
|
GroupRatio: '',
|
||||||
|
UserUsableGroups: '',
|
||||||
});
|
});
|
||||||
const refForm = useRef();
|
const refForm = useRef();
|
||||||
const [inputsRow, setInputsRow] = useState(inputs);
|
const [inputsRow, setInputsRow] = useState(inputs);
|
||||||
@@ -224,6 +225,33 @@ export default function SettingsMagnification(props) {
|
|||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
<Row gutter={16}>
|
||||||
|
<Col span={16}>
|
||||||
|
<Form.TextArea
|
||||||
|
label={'用户可选分组'}
|
||||||
|
extraText={''}
|
||||||
|
placeholder={'为一个 JSON 文本,键为分组名称,值为倍率'}
|
||||||
|
field={'UserUsableGroups'}
|
||||||
|
autosize={{ minRows: 6, maxRows: 12 }}
|
||||||
|
trigger='blur'
|
||||||
|
stopValidateWithError
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
validator: (rule, value) => {
|
||||||
|
return verifyJSON(value);
|
||||||
|
},
|
||||||
|
message: '不是合法的 JSON 字符串',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
onChange={(value) =>
|
||||||
|
setInputs({
|
||||||
|
...inputs,
|
||||||
|
UserUsableGroups: value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
</Form.Section>
|
</Form.Section>
|
||||||
</Form>
|
</Form>
|
||||||
<Space>
|
<Space>
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
SideSheet,
|
SideSheet,
|
||||||
Space,
|
Space,
|
||||||
Spin,
|
Spin,
|
||||||
|
TextArea,
|
||||||
Typography,
|
Typography,
|
||||||
} from '@douyinfe/semi-ui';
|
} from '@douyinfe/semi-ui';
|
||||||
import Title from '@douyinfe/semi-ui/lib/es/typography/title';
|
import Title from '@douyinfe/semi-ui/lib/es/typography/title';
|
||||||
@@ -34,6 +35,8 @@ const EditToken = (props) => {
|
|||||||
unlimited_quota: false,
|
unlimited_quota: false,
|
||||||
model_limits_enabled: false,
|
model_limits_enabled: false,
|
||||||
model_limits: [],
|
model_limits: [],
|
||||||
|
allow_ips: '',
|
||||||
|
group: '',
|
||||||
};
|
};
|
||||||
const [inputs, setInputs] = useState(originInputs);
|
const [inputs, setInputs] = useState(originInputs);
|
||||||
const {
|
const {
|
||||||
@@ -43,9 +46,12 @@ const EditToken = (props) => {
|
|||||||
unlimited_quota,
|
unlimited_quota,
|
||||||
model_limits_enabled,
|
model_limits_enabled,
|
||||||
model_limits,
|
model_limits,
|
||||||
|
allow_ips,
|
||||||
|
group,
|
||||||
} = inputs;
|
} = inputs;
|
||||||
// const [visible, setVisible] = useState(false);
|
// const [visible, setVisible] = useState(false);
|
||||||
const [models, setModels] = useState({});
|
const [models, setModels] = useState([]);
|
||||||
|
const [groups, setGroups] = useState([]);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const handleInputChange = (name, value) => {
|
const handleInputChange = (name, value) => {
|
||||||
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
||||||
@@ -86,6 +92,22 @@ const EditToken = (props) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadGroups = async () => {
|
||||||
|
let res = await API.get(`/api/user/self/groups`);
|
||||||
|
const { success, message, data } = res.data;
|
||||||
|
if (success) {
|
||||||
|
// return data is a map, key is group name, value is group description
|
||||||
|
// label is group description, value is group name
|
||||||
|
let localGroupOptions = Object.keys(data).map((group) => ({
|
||||||
|
label: data[group],
|
||||||
|
value: group,
|
||||||
|
}));
|
||||||
|
setGroups(localGroupOptions);
|
||||||
|
} else {
|
||||||
|
showError(message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const loadToken = async () => {
|
const loadToken = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
let res = await API.get(`/api/token/${props.editingToken.id}`);
|
let res = await API.get(`/api/token/${props.editingToken.id}`);
|
||||||
@@ -118,6 +140,7 @@ const EditToken = (props) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
loadModels();
|
loadModels();
|
||||||
|
loadGroups();
|
||||||
}, [isEdit]);
|
}, [isEdit]);
|
||||||
|
|
||||||
// 新增 state 变量 tokenCount 来记录用户想要创建的令牌数量,默认为 1
|
// 新增 state 变量 tokenCount 来记录用户想要创建的令牌数量,默认为 1
|
||||||
@@ -374,6 +397,19 @@ const EditToken = (props) => {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
<div style={{ marginTop: 10 }}>
|
||||||
|
<Typography.Text>IP白名单(请勿过度信任此功能)</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<TextArea
|
||||||
|
label='IP白名单'
|
||||||
|
name='allow_ips'
|
||||||
|
placeholder={'允许的IP,一行一个'}
|
||||||
|
onChange={(value) => {
|
||||||
|
handleInputChange('allow_ips', value);
|
||||||
|
}}
|
||||||
|
value={inputs.allow_ips}
|
||||||
|
style={{ fontFamily: 'JetBrains Mono, Consolas' }}
|
||||||
|
/>
|
||||||
<div style={{ marginTop: 10, display: 'flex' }}>
|
<div style={{ marginTop: 10, display: 'flex' }}>
|
||||||
<Space>
|
<Space>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
@@ -404,6 +440,31 @@ const EditToken = (props) => {
|
|||||||
optionList={models}
|
optionList={models}
|
||||||
disabled={!model_limits_enabled}
|
disabled={!model_limits_enabled}
|
||||||
/>
|
/>
|
||||||
|
<div style={{ marginTop: 10 }}>
|
||||||
|
<Typography.Text>令牌分组,默认为用户的分组</Typography.Text>
|
||||||
|
</div>
|
||||||
|
{groups.length > 0 ? (
|
||||||
|
<Select
|
||||||
|
style={{ marginTop: 8 }}
|
||||||
|
placeholder={'令牌分组,默认为用户的分组'}
|
||||||
|
name='gruop'
|
||||||
|
required
|
||||||
|
selection
|
||||||
|
onChange={(value) => {
|
||||||
|
handleInputChange('group', value);
|
||||||
|
}}
|
||||||
|
value={inputs.group}
|
||||||
|
autoComplete='new-password'
|
||||||
|
optionList={groups}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Select
|
||||||
|
style={{ marginTop: 8 }}
|
||||||
|
placeholder={'管理员未设置用户可选分组'}
|
||||||
|
name='gruop'
|
||||||
|
disabled={true}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Spin>
|
</Spin>
|
||||||
</SideSheet>
|
</SideSheet>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ export default defineConfig({
|
|||||||
target: 'http://localhost:3000',
|
target: 'http://localhost:3000',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
|
'/pg': {
|
||||||
|
target: 'http://localhost:3000',
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
1725
web/yarn.lock
1725
web/yarn.lock
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user