mirror of
https://github.com/songquanpeng/one-api.git
synced 2026-03-06 19:54:25 +08:00
Compare commits
11 Commits
v0.6.9-alp
...
3ce3716334
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ce3716334 | ||
|
|
7e51b04221 | ||
|
|
f75a17f8eb | ||
|
|
6f13a3bb3c | ||
|
|
f092eed1db | ||
|
|
629378691b | ||
|
|
3716e1b0e6 | ||
|
|
a4d6e7a886 | ||
|
|
cb772e5d06 | ||
|
|
e32cb0b844 | ||
|
|
3f06711501 |
@@ -76,9 +76,9 @@ func testChannel(channel *model.Channel, request *relaymodel.GeneralOpenAIReques
|
|||||||
if len(modelNames) > 0 {
|
if len(modelNames) > 0 {
|
||||||
modelName = modelNames[0]
|
modelName = modelNames[0]
|
||||||
}
|
}
|
||||||
if modelMap != nil && modelMap[modelName] != "" {
|
}
|
||||||
modelName = modelMap[modelName]
|
if modelMap != nil && modelMap[modelName] != "" {
|
||||||
}
|
modelName = modelMap[modelName]
|
||||||
}
|
}
|
||||||
meta.OriginModelName, meta.ActualModelName = request.Model, modelName
|
meta.OriginModelName, meta.ActualModelName = request.Model, modelName
|
||||||
request.Model = modelName
|
request.Model = modelName
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ var ModelList = []string{
|
|||||||
"claude-3-sonnet-20240229",
|
"claude-3-sonnet-20240229",
|
||||||
"claude-3-opus-20240229",
|
"claude-3-opus-20240229",
|
||||||
"claude-3-5-sonnet-20240620",
|
"claude-3-5-sonnet-20240620",
|
||||||
|
"claude-3-5-sonnet-20241022",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ var AwsModelIDMap = map[string]string{
|
|||||||
"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-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",
|
||||||
"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",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/songquanpeng/one-api/common/render"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/songquanpeng/one-api/common/render"
|
||||||
|
|
||||||
"github.com/songquanpeng/one-api/common"
|
"github.com/songquanpeng/one-api/common"
|
||||||
"github.com/songquanpeng/one-api/common/config"
|
"github.com/songquanpeng/one-api/common/config"
|
||||||
"github.com/songquanpeng/one-api/common/helper"
|
"github.com/songquanpeng/one-api/common/helper"
|
||||||
@@ -28,6 +29,11 @@ const (
|
|||||||
VisionMaxImageNum = 16
|
VisionMaxImageNum = 16
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var mimeTypeMap = map[string]string{
|
||||||
|
"json_object": "application/json",
|
||||||
|
"text": "text/plain",
|
||||||
|
}
|
||||||
|
|
||||||
// Setting safety to the lowest possible values since Gemini is already powerless enough
|
// Setting safety to the lowest possible values since Gemini is already powerless enough
|
||||||
func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
|
func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
|
||||||
geminiRequest := ChatRequest{
|
geminiRequest := ChatRequest{
|
||||||
@@ -56,6 +62,15 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
|
|||||||
MaxOutputTokens: textRequest.MaxTokens,
|
MaxOutputTokens: textRequest.MaxTokens,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
if textRequest.ResponseFormat != nil {
|
||||||
|
if mimeType, ok := mimeTypeMap[textRequest.ResponseFormat.Type]; ok {
|
||||||
|
geminiRequest.GenerationConfig.ResponseMimeType = mimeType
|
||||||
|
}
|
||||||
|
if textRequest.ResponseFormat.JsonSchema != nil {
|
||||||
|
geminiRequest.GenerationConfig.ResponseSchema = textRequest.ResponseFormat.JsonSchema.Schema
|
||||||
|
geminiRequest.GenerationConfig.ResponseMimeType = mimeTypeMap["json_object"]
|
||||||
|
}
|
||||||
|
}
|
||||||
if textRequest.Tools != nil {
|
if textRequest.Tools != nil {
|
||||||
functions := make([]model.Function, 0, len(textRequest.Tools))
|
functions := make([]model.Function, 0, len(textRequest.Tools))
|
||||||
for _, tool := range textRequest.Tools {
|
for _, tool := range textRequest.Tools {
|
||||||
|
|||||||
@@ -65,10 +65,12 @@ type ChatTools struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ChatGenerationConfig struct {
|
type ChatGenerationConfig struct {
|
||||||
Temperature float64 `json:"temperature,omitempty"`
|
ResponseMimeType string `json:"responseMimeType,omitempty"`
|
||||||
TopP float64 `json:"topP,omitempty"`
|
ResponseSchema any `json:"responseSchema,omitempty"`
|
||||||
TopK float64 `json:"topK,omitempty"`
|
Temperature float64 `json:"temperature,omitempty"`
|
||||||
MaxOutputTokens int `json:"maxOutputTokens,omitempty"`
|
TopP float64 `json:"topP,omitempty"`
|
||||||
CandidateCount int `json:"candidateCount,omitempty"`
|
TopK float64 `json:"topK,omitempty"`
|
||||||
StopSequences []string `json:"stopSequences,omitempty"`
|
MaxOutputTokens int `json:"maxOutputTokens,omitempty"`
|
||||||
|
CandidateCount int `json:"candidateCount,omitempty"`
|
||||||
|
StopSequences []string `json:"stopSequences,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,21 @@ package groq
|
|||||||
|
|
||||||
var ModelList = []string{
|
var ModelList = []string{
|
||||||
"gemma-7b-it",
|
"gemma-7b-it",
|
||||||
"mixtral-8x7b-32768",
|
|
||||||
"llama3-8b-8192",
|
|
||||||
"llama3-70b-8192",
|
|
||||||
"gemma2-9b-it",
|
"gemma2-9b-it",
|
||||||
"llama-3.1-405b-reasoning",
|
|
||||||
"llama-3.1-70b-versatile",
|
"llama-3.1-70b-versatile",
|
||||||
"llama-3.1-8b-instant",
|
"llama-3.1-8b-instant",
|
||||||
|
"llama-3.2-11b-text-preview",
|
||||||
|
"llama-3.2-11b-vision-preview",
|
||||||
|
"llama-3.2-1b-preview",
|
||||||
|
"llama-3.2-3b-preview",
|
||||||
|
"llama-3.2-90b-text-preview",
|
||||||
|
"llama-guard-3-8b",
|
||||||
|
"llama3-70b-8192",
|
||||||
|
"llama3-8b-8192",
|
||||||
"llama3-groq-70b-8192-tool-use-preview",
|
"llama3-groq-70b-8192-tool-use-preview",
|
||||||
"llama3-groq-8b-8192-tool-use-preview",
|
"llama3-groq-8b-8192-tool-use-preview",
|
||||||
|
"llava-v1.5-7b-4096-preview",
|
||||||
|
"mixtral-8x7b-32768",
|
||||||
|
"distil-whisper-large-v3-en",
|
||||||
"whisper-large-v3",
|
"whisper-large-v3",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,13 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.G
|
|||||||
if request == nil {
|
if request == nil {
|
||||||
return nil, errors.New("request is nil")
|
return nil, errors.New("request is nil")
|
||||||
}
|
}
|
||||||
|
if request.Stream {
|
||||||
|
// always return usage in stream mode
|
||||||
|
if request.StreamOptions == nil {
|
||||||
|
request.StreamOptions = &model.StreamOptions{}
|
||||||
|
}
|
||||||
|
request.StreamOptions.IncludeUsage = true
|
||||||
|
}
|
||||||
return request, nil
|
return request, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var ModelList = []string{
|
var ModelList = []string{
|
||||||
"gemini-1.5-pro-001", "gemini-1.5-flash-001", "gemini-pro", "gemini-pro-vision",
|
"gemini-1.5-pro-001", "gemini-1.5-flash-001", "gemini-pro", "gemini-pro-vision", "gemini-1.5-pro-002", "gemini-1.5-flash-002",
|
||||||
}
|
}
|
||||||
|
|
||||||
type Adaptor struct {
|
type Adaptor struct {
|
||||||
|
|||||||
@@ -7,5 +7,6 @@ var ModelList = []string{
|
|||||||
"SparkDesk-v3.1",
|
"SparkDesk-v3.1",
|
||||||
"SparkDesk-v3.1-128K",
|
"SparkDesk-v3.1-128K",
|
||||||
"SparkDesk-v3.5",
|
"SparkDesk-v3.5",
|
||||||
|
"SparkDesk-v3.5-32K",
|
||||||
"SparkDesk-v4.0",
|
"SparkDesk-v4.0",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -292,6 +292,8 @@ func apiVersion2domain(apiVersion string) string {
|
|||||||
return "pro-128k"
|
return "pro-128k"
|
||||||
case "v3.5":
|
case "v3.5":
|
||||||
return "generalv3.5"
|
return "generalv3.5"
|
||||||
|
case "v3.5-32K":
|
||||||
|
return "max-32k"
|
||||||
case "v4.0":
|
case "v4.0":
|
||||||
return "4.0Ultra"
|
return "4.0Ultra"
|
||||||
}
|
}
|
||||||
@@ -303,7 +305,10 @@ func getXunfeiAuthUrl(apiVersion string, apiKey string, apiSecret string) (strin
|
|||||||
domain := apiVersion2domain(apiVersion)
|
domain := apiVersion2domain(apiVersion)
|
||||||
switch apiVersion {
|
switch apiVersion {
|
||||||
case "v3.1-128K":
|
case "v3.1-128K":
|
||||||
authUrl = buildXunfeiAuthUrl(fmt.Sprintf("wss://spark-api.xf-yun.com/%s/pro-128k", apiVersion), apiKey, apiSecret)
|
authUrl = buildXunfeiAuthUrl(fmt.Sprintf("wss://spark-api.xf-yun.com/chat/pro-128k"), apiKey, apiSecret)
|
||||||
|
break
|
||||||
|
case "v3.5-32K":
|
||||||
|
authUrl = buildXunfeiAuthUrl(fmt.Sprintf("wss://spark-api.xf-yun.com/chat/max-32k"), apiKey, apiSecret)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
authUrl = buildXunfeiAuthUrl(fmt.Sprintf("wss://spark-api.xf-yun.com/%s/chat", apiVersion), apiKey, apiSecret)
|
authUrl = buildXunfeiAuthUrl(fmt.Sprintf("wss://spark-api.xf-yun.com/%s/chat", apiVersion), apiKey, apiSecret)
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ var ModelRatio = map[string]float64{
|
|||||||
"claude-3-haiku-20240307": 0.25 / 1000 * USD,
|
"claude-3-haiku-20240307": 0.25 / 1000 * USD,
|
||||||
"claude-3-sonnet-20240229": 3.0 / 1000 * USD,
|
"claude-3-sonnet-20240229": 3.0 / 1000 * USD,
|
||||||
"claude-3-5-sonnet-20240620": 3.0 / 1000 * USD,
|
"claude-3-5-sonnet-20240620": 3.0 / 1000 * USD,
|
||||||
|
"claude-3-5-sonnet-20241022": 3.0 / 1000 * USD,
|
||||||
"claude-3-opus-20240229": 15.0 / 1000 * USD,
|
"claude-3-opus-20240229": 15.0 / 1000 * USD,
|
||||||
// https://cloud.baidu.com/doc/WENXINWORKSHOP/s/hlrk4akp7
|
// https://cloud.baidu.com/doc/WENXINWORKSHOP/s/hlrk4akp7
|
||||||
"ERNIE-4.0-8K": 0.120 * RMB,
|
"ERNIE-4.0-8K": 0.120 * RMB,
|
||||||
@@ -130,6 +131,7 @@ var ModelRatio = map[string]float64{
|
|||||||
"SparkDesk-v3.1": 1.2858, // ¥0.018 / 1k tokens
|
"SparkDesk-v3.1": 1.2858, // ¥0.018 / 1k tokens
|
||||||
"SparkDesk-v3.1-128K": 1.2858, // ¥0.018 / 1k tokens
|
"SparkDesk-v3.1-128K": 1.2858, // ¥0.018 / 1k tokens
|
||||||
"SparkDesk-v3.5": 1.2858, // ¥0.018 / 1k tokens
|
"SparkDesk-v3.5": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v3.5-32K": 1.2858, // ¥0.018 / 1k tokens
|
||||||
"SparkDesk-v4.0": 1.2858, // ¥0.018 / 1k tokens
|
"SparkDesk-v4.0": 1.2858, // ¥0.018 / 1k tokens
|
||||||
"360GPT_S2_V9": 0.8572, // ¥0.012 / 1k tokens
|
"360GPT_S2_V9": 0.8572, // ¥0.012 / 1k tokens
|
||||||
"embedding-bert-512-v1": 0.0715, // ¥0.001 / 1k tokens
|
"embedding-bert-512-v1": 0.0715, // ¥0.001 / 1k tokens
|
||||||
@@ -161,15 +163,21 @@ var ModelRatio = map[string]float64{
|
|||||||
"mistral-embed": 0.1 / 1000 * USD,
|
"mistral-embed": 0.1 / 1000 * USD,
|
||||||
// https://wow.groq.com/#:~:text=inquiries%C2%A0here.-,Model,-Current%20Speed
|
// https://wow.groq.com/#:~:text=inquiries%C2%A0here.-,Model,-Current%20Speed
|
||||||
"gemma-7b-it": 0.07 / 1000000 * USD,
|
"gemma-7b-it": 0.07 / 1000000 * USD,
|
||||||
"mixtral-8x7b-32768": 0.24 / 1000000 * USD,
|
|
||||||
"llama3-8b-8192": 0.05 / 1000000 * USD,
|
|
||||||
"llama3-70b-8192": 0.59 / 1000000 * USD,
|
|
||||||
"gemma2-9b-it": 0.20 / 1000000 * USD,
|
"gemma2-9b-it": 0.20 / 1000000 * USD,
|
||||||
"llama-3.1-405b-reasoning": 0.89 / 1000000 * USD,
|
|
||||||
"llama-3.1-70b-versatile": 0.59 / 1000000 * USD,
|
"llama-3.1-70b-versatile": 0.59 / 1000000 * USD,
|
||||||
"llama-3.1-8b-instant": 0.05 / 1000000 * USD,
|
"llama-3.1-8b-instant": 0.05 / 1000000 * USD,
|
||||||
|
"llama-3.2-11b-text-preview": 0.05 / 1000000 * USD,
|
||||||
|
"llama-3.2-11b-vision-preview": 0.05 / 1000000 * USD,
|
||||||
|
"llama-3.2-1b-preview": 0.05 / 1000000 * USD,
|
||||||
|
"llama-3.2-3b-preview": 0.05 / 1000000 * USD,
|
||||||
|
"llama-3.2-90b-text-preview": 0.59 / 1000000 * USD,
|
||||||
|
"llama-guard-3-8b": 0.05 / 1000000 * USD,
|
||||||
|
"llama3-70b-8192": 0.59 / 1000000 * USD,
|
||||||
|
"llama3-8b-8192": 0.05 / 1000000 * USD,
|
||||||
"llama3-groq-70b-8192-tool-use-preview": 0.89 / 1000000 * USD,
|
"llama3-groq-70b-8192-tool-use-preview": 0.89 / 1000000 * USD,
|
||||||
"llama3-groq-8b-8192-tool-use-preview": 0.19 / 1000000 * USD,
|
"llama3-groq-8b-8192-tool-use-preview": 0.19 / 1000000 * USD,
|
||||||
|
"mixtral-8x7b-32768": 0.24 / 1000000 * USD,
|
||||||
|
|
||||||
// https://platform.lingyiwanwu.com/docs#-计费单元
|
// https://platform.lingyiwanwu.com/docs#-计费单元
|
||||||
"yi-34b-chat-0205": 2.5 / 1000 * RMB,
|
"yi-34b-chat-0205": 2.5 / 1000 * RMB,
|
||||||
"yi-34b-chat-200k": 12.0 / 1000 * RMB,
|
"yi-34b-chat-200k": 12.0 / 1000 * RMB,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ContentTypeText = "text"
|
ContentTypeText = "text"
|
||||||
ContentTypeImageURL = "image_url"
|
ContentTypeImageURL = "image_url"
|
||||||
|
ContentTypeInputAudio = "input_audio"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,9 +12,20 @@ type JSONSchema struct {
|
|||||||
Strict *bool `json:"strict,omitempty"`
|
Strict *bool `json:"strict,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Audio struct {
|
||||||
|
Voice string `json:"voice,omitempty"`
|
||||||
|
Format string `json:"format,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type StreamOptions struct {
|
||||||
|
IncludeUsage bool `json:"include_usage,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type GeneralOpenAIRequest struct {
|
type GeneralOpenAIRequest struct {
|
||||||
Messages []Message `json:"messages,omitempty"`
|
Messages []Message `json:"messages,omitempty"`
|
||||||
Model string `json:"model,omitempty"`
|
Model string `json:"model,omitempty"`
|
||||||
|
Modalities []string `json:"modalities,omitempty"`
|
||||||
|
Audio *Audio `json:"audio,omitempty"`
|
||||||
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
|
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
|
||||||
MaxTokens int `json:"max_tokens,omitempty"`
|
MaxTokens int `json:"max_tokens,omitempty"`
|
||||||
N int `json:"n,omitempty"`
|
N int `json:"n,omitempty"`
|
||||||
@@ -23,6 +34,7 @@ type GeneralOpenAIRequest struct {
|
|||||||
Seed float64 `json:"seed,omitempty"`
|
Seed float64 `json:"seed,omitempty"`
|
||||||
Stop any `json:"stop,omitempty"`
|
Stop any `json:"stop,omitempty"`
|
||||||
Stream bool `json:"stream,omitempty"`
|
Stream bool `json:"stream,omitempty"`
|
||||||
|
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
|
||||||
Temperature float64 `json:"temperature,omitempty"`
|
Temperature float64 `json:"temperature,omitempty"`
|
||||||
TopP float64 `json:"top_p,omitempty"`
|
TopP float64 `json:"top_p,omitempty"`
|
||||||
TopK int `json:"top_k,omitempty"`
|
TopK int `json:"top_k,omitempty"`
|
||||||
@@ -37,7 +49,7 @@ type GeneralOpenAIRequest struct {
|
|||||||
Dimensions int `json:"dimensions,omitempty"`
|
Dimensions int `json:"dimensions,omitempty"`
|
||||||
Instruction string `json:"instruction,omitempty"`
|
Instruction string `json:"instruction,omitempty"`
|
||||||
Size string `json:"size,omitempty"`
|
Size string `json:"size,omitempty"`
|
||||||
NumCtx int `json:"num_ctx,omitempty"`
|
NumCtx int `json:"num_ctx,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r GeneralOpenAIRequest) ParseInput() []string {
|
func (r GeneralOpenAIRequest) ParseInput() []string {
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ const TokensTable = () => {
|
|||||||
url = mjLink + `/#/?settings={"key":"sk-${key}","url":"${serverAddress}"}`;
|
url = mjLink + `/#/?settings={"key":"sk-${key}","url":"${serverAddress}"}`;
|
||||||
break;
|
break;
|
||||||
case 'lobechat':
|
case 'lobechat':
|
||||||
url = chatLink + `/?settings={"keyVaults":{"openai":{"apiKey":"sk-${key}","baseURL":"${serverAddress}"/v1"}}}`;
|
url = chatLink + `/?settings={"keyVaults":{"openai":{"apiKey":"sk-${key}","baseURL":"${serverAddress}/v1"}}}`;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!chatLink) {
|
if (!chatLink) {
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ const EditChannel = (props) => {
|
|||||||
let localModels = [];
|
let localModels = [];
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 14:
|
case 14:
|
||||||
localModels = ["claude-instant-1.2", "claude-2", "claude-2.0", "claude-2.1", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", "claude-3-5-sonnet-20240620"];
|
localModels = ["claude-instant-1.2", "claude-2", "claude-2.0", "claude-2.1", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", "claude-3-5-sonnet-20240620", "claude-3-5-sonnet-20241022"];
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
localModels = ['PaLM-2'];
|
localModels = ['PaLM-2'];
|
||||||
@@ -78,7 +78,7 @@ const EditChannel = (props) => {
|
|||||||
localModels = ['chatglm_pro', 'chatglm_std', 'chatglm_lite'];
|
localModels = ['chatglm_pro', 'chatglm_std', 'chatglm_lite'];
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
localModels = ['SparkDesk', 'SparkDesk-v1.1', 'SparkDesk-v2.1', 'SparkDesk-v3.1', 'SparkDesk-v3.1-128K', 'SparkDesk-v3.5', 'SparkDesk-v4.0'];
|
localModels = ['SparkDesk', 'SparkDesk-v1.1', 'SparkDesk-v2.1', 'SparkDesk-v3.1', 'SparkDesk-v3.1-128K', 'SparkDesk-v3.5', 'SparkDesk-v3.5-32K', 'SparkDesk-v4.0'];
|
||||||
break;
|
break;
|
||||||
case 19:
|
case 19:
|
||||||
localModels = ['360GPT_S2_V9', 'embedding-bert-512-v1', 'embedding_s1_v1', 'semantic_similarity_s1_v1'];
|
localModels = ['360GPT_S2_V9', 'embedding-bert-512-v1', 'embedding_s1_v1', 'semantic_similarity_s1_v1'];
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import { useSelector } from 'react-redux';
|
|||||||
import useRegister from 'hooks/useRegister';
|
import useRegister from 'hooks/useRegister';
|
||||||
import Turnstile from 'react-turnstile';
|
import Turnstile from 'react-turnstile';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
// import { useSelector } from 'react-redux';
|
|
||||||
|
|
||||||
// material-ui
|
// material-ui
|
||||||
import { useTheme } from '@mui/material/styles';
|
import { useTheme } from '@mui/material/styles';
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
|
CircularProgress,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormHelperText,
|
FormHelperText,
|
||||||
Grid,
|
Grid,
|
||||||
@@ -50,6 +50,9 @@ const RegisterForm = ({ ...others }) => {
|
|||||||
const [strength, setStrength] = useState(0);
|
const [strength, setStrength] = useState(0);
|
||||||
const [level, setLevel] = useState();
|
const [level, setLevel] = useState();
|
||||||
|
|
||||||
|
const [timer, setTimer] = useState(0);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const handleClickShowPassword = () => {
|
const handleClickShowPassword = () => {
|
||||||
setShowPassword(!showPassword);
|
setShowPassword(!showPassword);
|
||||||
};
|
};
|
||||||
@@ -74,11 +77,17 @@ const RegisterForm = ({ ...others }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setLoading(true); // Start loading
|
||||||
|
|
||||||
const { success, message } = await sendVerificationCode(email, turnstileToken);
|
const { success, message } = await sendVerificationCode(email, turnstileToken);
|
||||||
|
setLoading(false); // Stop loading
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
showError(message);
|
showError(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTimer(60); // Start the 60-second timer
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -94,217 +103,233 @@ const RegisterForm = ({ ...others }) => {
|
|||||||
}
|
}
|
||||||
}, [siteInfo]);
|
}, [siteInfo]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let interval;
|
||||||
|
if (timer > 0) {
|
||||||
|
interval = setInterval(() => {
|
||||||
|
setTimer((prevTimer) => prevTimer - 1);
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, [timer]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Formik
|
<Formik
|
||||||
initialValues={{
|
initialValues={{
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
confirmPassword: '',
|
confirmPassword: '',
|
||||||
email: showEmailVerification ? '' : undefined,
|
email: showEmailVerification ? '' : undefined,
|
||||||
verification_code: showEmailVerification ? '' : undefined,
|
verification_code: showEmailVerification ? '' : undefined,
|
||||||
submit: null
|
submit: null
|
||||||
}}
|
}}
|
||||||
validationSchema={Yup.object().shape({
|
validationSchema={Yup.object().shape({
|
||||||
username: Yup.string().max(255).required('用户名是必填项'),
|
username: Yup.string().max(255).required('用户名是必填项'),
|
||||||
password: Yup.string().max(255).required('密码是必填项'),
|
password: Yup.string().max(255).required('密码是必填项'),
|
||||||
confirmPassword: Yup.string()
|
confirmPassword: Yup.string()
|
||||||
.required('确认密码是必填项')
|
.required('确认密码是必填项')
|
||||||
.oneOf([Yup.ref('password'), null], '两次输入的密码不一致'),
|
.oneOf([Yup.ref('password'), null], '两次输入的密码不一致'),
|
||||||
email: showEmailVerification ? Yup.string().email('必须是有效的Email地址').max(255).required('Email是必填项') : Yup.mixed(),
|
email: showEmailVerification ? Yup.string().email('必须是有效的Email地址').max(255).required('Email是必填项') : Yup.mixed(),
|
||||||
verification_code: showEmailVerification ? Yup.string().max(255).required('验证码是必填项') : Yup.mixed()
|
verification_code: showEmailVerification ? Yup.string().max(255).required('验证码是必填项') : Yup.mixed()
|
||||||
})}
|
})}
|
||||||
onSubmit={async (values, { setErrors, setStatus, setSubmitting }) => {
|
onSubmit={async (values, { setErrors, setStatus, setSubmitting }) => {
|
||||||
if (turnstileEnabled && turnstileToken === '') {
|
if (turnstileEnabled && turnstileToken === '') {
|
||||||
showInfo('请稍后几秒重试,Turnstile 正在检查用户环境!');
|
showInfo('请稍后几秒重试,Turnstile 正在检查用户环境!');
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { success, message } = await register(values, turnstileToken);
|
const { success, message } = await register(values, turnstileToken);
|
||||||
if (success) {
|
if (success) {
|
||||||
setStatus({ success: true });
|
setStatus({ success: true });
|
||||||
} else {
|
} else {
|
||||||
setStatus({ success: false });
|
setStatus({ success: false });
|
||||||
if (message) {
|
if (message) {
|
||||||
setErrors({ submit: message });
|
setErrors({ submit: message });
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{({ errors, handleBlur, handleChange, handleSubmit, isSubmitting, touched, values }) => (
|
|
||||||
<form noValidate onSubmit={handleSubmit} {...others}>
|
|
||||||
<FormControl fullWidth error={Boolean(touched.username && errors.username)} sx={{ ...theme.typography.customInput }}>
|
|
||||||
<InputLabel htmlFor="outlined-adornment-username-register">用户名</InputLabel>
|
|
||||||
<OutlinedInput
|
|
||||||
id="outlined-adornment-username-register"
|
|
||||||
type="text"
|
|
||||||
value={values.username}
|
|
||||||
name="username"
|
|
||||||
onBlur={handleBlur}
|
|
||||||
onChange={handleChange}
|
|
||||||
inputProps={{ autoComplete: 'username' }}
|
|
||||||
/>
|
|
||||||
{touched.username && errors.username && (
|
|
||||||
<FormHelperText error id="standard-weight-helper-text--register">
|
|
||||||
{errors.username}
|
|
||||||
</FormHelperText>
|
|
||||||
)}
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
<FormControl fullWidth error={Boolean(touched.password && errors.password)} sx={{ ...theme.typography.customInput }}>
|
|
||||||
<InputLabel htmlFor="outlined-adornment-password-register">密码</InputLabel>
|
|
||||||
<OutlinedInput
|
|
||||||
id="outlined-adornment-password-register"
|
|
||||||
type={showPassword ? 'text' : 'password'}
|
|
||||||
value={values.password}
|
|
||||||
name="password"
|
|
||||||
label="Password"
|
|
||||||
onBlur={handleBlur}
|
|
||||||
onChange={(e) => {
|
|
||||||
handleChange(e);
|
|
||||||
changePassword(e.target.value);
|
|
||||||
}}
|
|
||||||
endAdornment={
|
|
||||||
<InputAdornment position="end">
|
|
||||||
<IconButton
|
|
||||||
aria-label="toggle password visibility"
|
|
||||||
onClick={handleClickShowPassword}
|
|
||||||
onMouseDown={handleMouseDownPassword}
|
|
||||||
edge="end"
|
|
||||||
size="large"
|
|
||||||
color={'primary'}
|
|
||||||
>
|
|
||||||
{showPassword ? <Visibility /> : <VisibilityOff />}
|
|
||||||
</IconButton>
|
|
||||||
</InputAdornment>
|
|
||||||
}
|
}
|
||||||
inputProps={{}}
|
}
|
||||||
/>
|
}}
|
||||||
{touched.password && errors.password && (
|
>
|
||||||
<FormHelperText error id="standard-weight-helper-text-password-register">
|
{({ errors, handleBlur, handleChange, handleSubmit, isSubmitting, touched, values }) => (
|
||||||
{errors.password}
|
<form noValidate onSubmit={handleSubmit} {...others}>
|
||||||
</FormHelperText>
|
<FormControl fullWidth error={Boolean(touched.username && errors.username)} sx={{ ...theme.typography.customInput }}>
|
||||||
)}
|
<InputLabel htmlFor="outlined-adornment-username-register">用户名</InputLabel>
|
||||||
</FormControl>
|
|
||||||
<FormControl
|
|
||||||
fullWidth
|
|
||||||
error={Boolean(touched.confirmPassword && errors.confirmPassword)}
|
|
||||||
sx={{ ...theme.typography.customInput }}
|
|
||||||
>
|
|
||||||
<InputLabel htmlFor="outlined-adornment-confirm-password-register">确认密码</InputLabel>
|
|
||||||
<OutlinedInput
|
|
||||||
id="outlined-adornment-confirm-password-register"
|
|
||||||
type={showPassword ? 'text' : 'password'}
|
|
||||||
value={values.confirmPassword}
|
|
||||||
name="confirmPassword"
|
|
||||||
label="Confirm Password"
|
|
||||||
onBlur={handleBlur}
|
|
||||||
onChange={handleChange}
|
|
||||||
inputProps={{}}
|
|
||||||
/>
|
|
||||||
{touched.confirmPassword && errors.confirmPassword && (
|
|
||||||
<FormHelperText error id="standard-weight-helper-text-confirm-password-register">
|
|
||||||
{errors.confirmPassword}
|
|
||||||
</FormHelperText>
|
|
||||||
)}
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
{strength !== 0 && (
|
|
||||||
<FormControl fullWidth>
|
|
||||||
<Box sx={{ mb: 2 }}>
|
|
||||||
<Grid container spacing={2} alignItems="center">
|
|
||||||
<Grid item>
|
|
||||||
<Box style={{ backgroundColor: level?.color }} sx={{ width: 85, height: 8, borderRadius: '7px' }} />
|
|
||||||
</Grid>
|
|
||||||
<Grid item>
|
|
||||||
<Typography variant="subtitle1" fontSize="0.75rem">
|
|
||||||
{level?.label}
|
|
||||||
</Typography>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
</Box>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{showEmailVerification && (
|
|
||||||
<>
|
|
||||||
<FormControl fullWidth error={Boolean(touched.email && errors.email)} sx={{ ...theme.typography.customInput }}>
|
|
||||||
<InputLabel htmlFor="outlined-adornment-email-register">Email</InputLabel>
|
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
id="outlined-adornment-email-register"
|
id="outlined-adornment-username-register"
|
||||||
type="text"
|
type="text"
|
||||||
value={values.email}
|
value={values.username}
|
||||||
name="email"
|
name="username"
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
endAdornment={
|
inputProps={{ autoComplete: 'username' }}
|
||||||
<InputAdornment position="end">
|
|
||||||
<Button variant="contained" color="primary" onClick={() => handleSendCode(values.email)}>
|
|
||||||
发送验证码
|
|
||||||
</Button>
|
|
||||||
</InputAdornment>
|
|
||||||
}
|
|
||||||
inputProps={{}}
|
|
||||||
/>
|
/>
|
||||||
{touched.email && errors.email && (
|
{touched.username && errors.username && (
|
||||||
<FormHelperText error id="standard-weight-helper-text--register">
|
<FormHelperText error id="standard-weight-helper-text--register">
|
||||||
{errors.email}
|
{errors.username}
|
||||||
</FormHelperText>
|
</FormHelperText>
|
||||||
|
)}
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<FormControl fullWidth error={Boolean(touched.password && errors.password)} sx={{ ...theme.typography.customInput }}>
|
||||||
|
<InputLabel htmlFor="outlined-adornment-password-register">密码</InputLabel>
|
||||||
|
<OutlinedInput
|
||||||
|
id="outlined-adornment-password-register"
|
||||||
|
type={showPassword ? 'text' : 'password'}
|
||||||
|
value={values.password}
|
||||||
|
name="password"
|
||||||
|
label="Password"
|
||||||
|
onBlur={handleBlur}
|
||||||
|
onChange={(e) => {
|
||||||
|
handleChange(e);
|
||||||
|
changePassword(e.target.value);
|
||||||
|
}}
|
||||||
|
endAdornment={
|
||||||
|
<InputAdornment position="end">
|
||||||
|
<IconButton
|
||||||
|
aria-label="toggle password visibility"
|
||||||
|
onClick={handleClickShowPassword}
|
||||||
|
onMouseDown={handleMouseDownPassword}
|
||||||
|
edge="end"
|
||||||
|
size="large"
|
||||||
|
color={'primary'}
|
||||||
|
>
|
||||||
|
{showPassword ? <Visibility /> : <VisibilityOff />}
|
||||||
|
</IconButton>
|
||||||
|
</InputAdornment>
|
||||||
|
}
|
||||||
|
inputProps={{}}
|
||||||
|
/>
|
||||||
|
{touched.password && errors.password && (
|
||||||
|
<FormHelperText error id="standard-weight-helper-text-password-register">
|
||||||
|
{errors.password}
|
||||||
|
</FormHelperText>
|
||||||
)}
|
)}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormControl
|
<FormControl
|
||||||
fullWidth
|
fullWidth
|
||||||
error={Boolean(touched.verification_code && errors.verification_code)}
|
error={Boolean(touched.confirmPassword && errors.confirmPassword)}
|
||||||
sx={{ ...theme.typography.customInput }}
|
sx={{ ...theme.typography.customInput }}
|
||||||
>
|
>
|
||||||
<InputLabel htmlFor="outlined-adornment-verification_code-register">验证码</InputLabel>
|
<InputLabel htmlFor="outlined-adornment-confirm-password-register">确认密码</InputLabel>
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
id="outlined-adornment-verification_code-register"
|
id="outlined-adornment-confirm-password-register"
|
||||||
type="text"
|
type={showPassword ? 'text' : 'password'}
|
||||||
value={values.verification_code}
|
value={values.confirmPassword}
|
||||||
name="verification_code"
|
name="confirmPassword"
|
||||||
onBlur={handleBlur}
|
label="Confirm Password"
|
||||||
onChange={handleChange}
|
onBlur={handleBlur}
|
||||||
inputProps={{}}
|
onChange={handleChange}
|
||||||
|
inputProps={{}}
|
||||||
/>
|
/>
|
||||||
{touched.verification_code && errors.verification_code && (
|
{touched.confirmPassword && errors.confirmPassword && (
|
||||||
<FormHelperText error id="standard-weight-helper-text--register">
|
<FormHelperText error id="standard-weight-helper-text-confirm-password-register">
|
||||||
{errors.verification_code}
|
{errors.confirmPassword}
|
||||||
</FormHelperText>
|
</FormHelperText>
|
||||||
)}
|
)}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{errors.submit && (
|
{strength !== 0 && (
|
||||||
<Box sx={{ mt: 3 }}>
|
<FormControl fullWidth>
|
||||||
<FormHelperText error>{errors.submit}</FormHelperText>
|
<Box sx={{ mb: 2 }}>
|
||||||
</Box>
|
<Grid container spacing={2} alignItems="center">
|
||||||
)}
|
<Grid item>
|
||||||
{turnstileEnabled ? (
|
<Box style={{ backgroundColor: level?.color }} sx={{ width: 85, height: 8, borderRadius: '7px' }} />
|
||||||
<Turnstile
|
</Grid>
|
||||||
sitekey={turnstileSiteKey}
|
<Grid item>
|
||||||
onVerify={(token) => {
|
<Typography variant="subtitle1" fontSize="0.75rem">
|
||||||
setTurnstileToken(token);
|
{level?.label}
|
||||||
}}
|
</Typography>
|
||||||
/>
|
</Grid>
|
||||||
) : (
|
</Grid>
|
||||||
<></>
|
</Box>
|
||||||
)}
|
</FormControl>
|
||||||
|
)}
|
||||||
|
|
||||||
<Box sx={{ mt: 2 }}>
|
{showEmailVerification && (
|
||||||
<AnimateButton>
|
<>
|
||||||
<Button disableElevation disabled={isSubmitting} fullWidth size="large" type="submit" variant="contained" color="primary">
|
<FormControl fullWidth error={Boolean(touched.email && errors.email)} sx={{ ...theme.typography.customInput }}>
|
||||||
注册
|
<InputLabel htmlFor="outlined-adornment-email-register">Email</InputLabel>
|
||||||
</Button>
|
<OutlinedInput
|
||||||
</AnimateButton>
|
id="outlined-adornment-email-register"
|
||||||
</Box>
|
type="text"
|
||||||
</form>
|
value={values.email}
|
||||||
)}
|
name="email"
|
||||||
</Formik>
|
onBlur={handleBlur}
|
||||||
</>
|
onChange={handleChange}
|
||||||
|
endAdornment={
|
||||||
|
<InputAdornment position="end">
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={() => handleSendCode(values.email)}
|
||||||
|
disabled={timer > 0 || loading}
|
||||||
|
>
|
||||||
|
{loading ? <CircularProgress size={24} /> : timer > 0 ? `${timer}s` : '发送验证码'}
|
||||||
|
</Button>
|
||||||
|
</InputAdornment>
|
||||||
|
}
|
||||||
|
inputProps={{}}
|
||||||
|
/>
|
||||||
|
{touched.email && errors.email && (
|
||||||
|
<FormHelperText error id="standard-weight-helper-text--register">
|
||||||
|
{errors.email}
|
||||||
|
</FormHelperText>
|
||||||
|
)}
|
||||||
|
</FormControl>
|
||||||
|
<FormControl
|
||||||
|
fullWidth
|
||||||
|
error={Boolean(touched.verification_code && errors.verification_code)}
|
||||||
|
sx={{ ...theme.typography.customInput }}
|
||||||
|
>
|
||||||
|
<InputLabel htmlFor="outlined-adornment-verification_code-register">验证码</InputLabel>
|
||||||
|
<OutlinedInput
|
||||||
|
id="outlined-adornment-verification_code-register"
|
||||||
|
type="text"
|
||||||
|
value={values.verification_code}
|
||||||
|
name="verification_code"
|
||||||
|
onBlur={handleBlur}
|
||||||
|
onChange={handleChange}
|
||||||
|
inputProps={{}}
|
||||||
|
/>
|
||||||
|
{touched.verification_code && errors.verification_code && (
|
||||||
|
<FormHelperText error id="standard-weight-helper-text--register">
|
||||||
|
{errors.verification_code}
|
||||||
|
</FormHelperText>
|
||||||
|
)}
|
||||||
|
</FormControl>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{errors.submit && (
|
||||||
|
<Box sx={{ mt: 3 }}>
|
||||||
|
<FormHelperText error>{errors.submit}</FormHelperText>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
{turnstileEnabled ? (
|
||||||
|
<Turnstile
|
||||||
|
sitekey={turnstileSiteKey}
|
||||||
|
onVerify={(token) => {
|
||||||
|
setTurnstileToken(token);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Box sx={{ mt: 2 }}>
|
||||||
|
<AnimateButton>
|
||||||
|
<Button disableElevation disabled={isSubmitting} fullWidth size="large" type="submit" variant="contained" color="primary">
|
||||||
|
注册
|
||||||
|
</Button>
|
||||||
|
</AnimateButton>
|
||||||
|
</Box>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
</Formik>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default RegisterForm;
|
export default RegisterForm;
|
||||||
@@ -91,7 +91,7 @@ const typeConfig = {
|
|||||||
other: '版本号'
|
other: '版本号'
|
||||||
},
|
},
|
||||||
input: {
|
input: {
|
||||||
models: ['SparkDesk', 'SparkDesk-v1.1', 'SparkDesk-v2.1', 'SparkDesk-v3.1', 'SparkDesk-v3.1-128K', 'SparkDesk-v3.5', 'SparkDesk-v4.0']
|
models: ['SparkDesk', 'SparkDesk-v1.1', 'SparkDesk-v2.1', 'SparkDesk-v3.1', 'SparkDesk-v3.1-128K', 'SparkDesk-v3.5', 'SparkDesk-v3.5-32K', 'SparkDesk-v4.0']
|
||||||
},
|
},
|
||||||
prompt: {
|
prompt: {
|
||||||
key: '按照如下格式输入:APPID|APISecret|APIKey',
|
key: '按照如下格式输入:APPID|APISecret|APIKey',
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const COPY_OPTIONS = [
|
|||||||
},
|
},
|
||||||
{ key: 'ama', text: 'BotGem', url: 'ama://set-api-key?server={serverAddress}&key=sk-{key}', encode: true },
|
{ key: 'ama', text: 'BotGem', url: 'ama://set-api-key?server={serverAddress}&key=sk-{key}', encode: true },
|
||||||
{ key: 'opencat', text: 'OpenCat', url: 'opencat://team/join?domain={serverAddress}&token=sk-{key}', encode: true },
|
{ key: 'opencat', text: 'OpenCat', url: 'opencat://team/join?domain={serverAddress}&token=sk-{key}', encode: true },
|
||||||
{ key: 'lobechat', text: 'LobeChat', url: 'https://lobehub.com/?settings={"keyVaults":{"openai":{"apiKey":"user-key","baseURL":"https://your-proxy.com/v1"}}}', encode: true }
|
{ key: 'lobechat', text: 'LobeChat', url: 'https://lobehub.com/?settings={"keyVaults":{"openai":{"apiKey":"sk-{key}","baseURL":"{serverAddress}"}}}', encode: true }
|
||||||
];
|
];
|
||||||
|
|
||||||
function replacePlaceholders(text, key, serverAddress) {
|
function replacePlaceholders(text, key, serverAddress) {
|
||||||
|
|||||||
@@ -59,6 +59,12 @@ function renderBalance(type, balance) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isShowDetail() {
|
||||||
|
return localStorage.getItem("show_detail") === "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
const promptID = "detail"
|
||||||
|
|
||||||
const ChannelsTable = () => {
|
const ChannelsTable = () => {
|
||||||
const [channels, setChannels] = useState([]);
|
const [channels, setChannels] = useState([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -66,7 +72,8 @@ const ChannelsTable = () => {
|
|||||||
const [searchKeyword, setSearchKeyword] = useState('');
|
const [searchKeyword, setSearchKeyword] = useState('');
|
||||||
const [searching, setSearching] = useState(false);
|
const [searching, setSearching] = useState(false);
|
||||||
const [updatingBalance, setUpdatingBalance] = useState(false);
|
const [updatingBalance, setUpdatingBalance] = useState(false);
|
||||||
const [showPrompt, setShowPrompt] = useState(shouldShowPrompt("channel-test"));
|
const [showPrompt, setShowPrompt] = useState(shouldShowPrompt(promptID));
|
||||||
|
const [showDetail, setShowDetail] = useState(isShowDetail());
|
||||||
|
|
||||||
const loadChannels = async (startIdx) => {
|
const loadChannels = async (startIdx) => {
|
||||||
const res = await API.get(`/api/channel/?p=${startIdx}`);
|
const res = await API.get(`/api/channel/?p=${startIdx}`);
|
||||||
@@ -120,6 +127,11 @@ const ChannelsTable = () => {
|
|||||||
await loadChannels(activePage - 1);
|
await loadChannels(activePage - 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleShowDetail = () => {
|
||||||
|
setShowDetail(!showDetail);
|
||||||
|
localStorage.setItem("show_detail", (!showDetail).toString());
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadChannels(0)
|
loadChannels(0)
|
||||||
.then()
|
.then()
|
||||||
@@ -364,11 +376,13 @@ const ChannelsTable = () => {
|
|||||||
showPrompt && (
|
showPrompt && (
|
||||||
<Message onDismiss={() => {
|
<Message onDismiss={() => {
|
||||||
setShowPrompt(false);
|
setShowPrompt(false);
|
||||||
setPromptShown("channel-test");
|
setPromptShown(promptID);
|
||||||
}}>
|
}}>
|
||||||
OpenAI 渠道已经不再支持通过 key 获取余额,因此余额显示为 0。对于支持的渠道类型,请点击余额进行刷新。
|
OpenAI 渠道已经不再支持通过 key 获取余额,因此余额显示为 0。对于支持的渠道类型,请点击余额进行刷新。
|
||||||
<br/>
|
<br/>
|
||||||
渠道测试仅支持 chat 模型,优先使用 gpt-3.5-turbo,如果该模型不可用则使用你所配置的模型列表中的第一个模型。
|
渠道测试仅支持 chat 模型,优先使用 gpt-3.5-turbo,如果该模型不可用则使用你所配置的模型列表中的第一个模型。
|
||||||
|
<br/>
|
||||||
|
点击下方详情按钮可以显示余额以及设置额外的测试模型。
|
||||||
</Message>
|
</Message>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -428,6 +442,7 @@ const ChannelsTable = () => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
sortChannel('balance');
|
sortChannel('balance');
|
||||||
}}
|
}}
|
||||||
|
hidden={!showDetail}
|
||||||
>
|
>
|
||||||
余额
|
余额
|
||||||
</Table.HeaderCell>
|
</Table.HeaderCell>
|
||||||
@@ -439,7 +454,7 @@ const ChannelsTable = () => {
|
|||||||
>
|
>
|
||||||
优先级
|
优先级
|
||||||
</Table.HeaderCell>
|
</Table.HeaderCell>
|
||||||
<Table.HeaderCell>测试模型</Table.HeaderCell>
|
<Table.HeaderCell hidden={!showDetail}>测试模型</Table.HeaderCell>
|
||||||
<Table.HeaderCell>操作</Table.HeaderCell>
|
<Table.HeaderCell>操作</Table.HeaderCell>
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
</Table.Header>
|
</Table.Header>
|
||||||
@@ -467,7 +482,7 @@ const ChannelsTable = () => {
|
|||||||
basic
|
basic
|
||||||
/>
|
/>
|
||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
<Table.Cell>
|
<Table.Cell hidden={!showDetail}>
|
||||||
<Popup
|
<Popup
|
||||||
trigger={<span onClick={() => {
|
trigger={<span onClick={() => {
|
||||||
updateChannelBalance(channel.id, channel.name, idx);
|
updateChannelBalance(channel.id, channel.name, idx);
|
||||||
@@ -494,7 +509,7 @@ const ChannelsTable = () => {
|
|||||||
basic
|
basic
|
||||||
/>
|
/>
|
||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
<Table.Cell>
|
<Table.Cell hidden={!showDetail}>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
placeholder='请选择测试模型'
|
placeholder='请选择测试模型'
|
||||||
selection
|
selection
|
||||||
@@ -573,7 +588,7 @@ const ChannelsTable = () => {
|
|||||||
|
|
||||||
<Table.Footer>
|
<Table.Footer>
|
||||||
<Table.Row>
|
<Table.Row>
|
||||||
<Table.HeaderCell colSpan='9'>
|
<Table.HeaderCell colSpan={showDetail ? "10" : "8"}>
|
||||||
<Button size='small' as={Link} to='/channel/add' loading={loading}>
|
<Button size='small' as={Link} to='/channel/add' loading={loading}>
|
||||||
添加新的渠道
|
添加新的渠道
|
||||||
</Button>
|
</Button>
|
||||||
@@ -611,6 +626,7 @@ const ChannelsTable = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Button size='small' onClick={refresh} loading={loading}>刷新</Button>
|
<Button size='small' onClick={refresh} loading={loading}>刷新</Button>
|
||||||
|
<Button size='small' onClick={toggleShowDetail}>{showDetail ? "隐藏详情" : "详情"}</Button>
|
||||||
</Table.HeaderCell>
|
</Table.HeaderCell>
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
</Table.Footer>
|
</Table.Footer>
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ const TokensTable = () => {
|
|||||||
url = nextUrl;
|
url = nextUrl;
|
||||||
break;
|
break;
|
||||||
case 'lobechat':
|
case 'lobechat':
|
||||||
url = nextLink + `/?settings={"keyVaults":{"openai":{"apiKey":"sk-${key}","baseURL":"${serverAddress}"/v1"}}}`;
|
url = nextLink + `/?settings={"keyVaults":{"openai":{"apiKey":"sk-${key}","baseURL":"${serverAddress}/v1"}}}`;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
url = `sk-${key}`;
|
url = `sk-${key}`;
|
||||||
@@ -160,7 +160,7 @@ const TokensTable = () => {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'lobechat':
|
case 'lobechat':
|
||||||
url = chatLink + `/?settings={"keyVaults":{"openai":{"apiKey":"sk-${key}","baseURL":"${serverAddress}"/v1"}}}`;
|
url = chatLink + `/?settings={"keyVaults":{"openai":{"apiKey":"sk-${key}","baseURL":"${serverAddress}/v1"}}}`;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import { Header, Segment } from 'semantic-ui-react';
|
import { Header, Segment } from 'semantic-ui-react';
|
||||||
import ChannelsTable from '../../components/ChannelsTable';
|
import ChannelsTable from '../../components/ChannelsTable';
|
||||||
|
|
||||||
const File = () => (
|
const Channel = () => (
|
||||||
<>
|
<>
|
||||||
<Segment>
|
<Segment>
|
||||||
<Header as='h3'>管理渠道</Header>
|
<Header as='h3'>管理渠道</Header>
|
||||||
@@ -11,4 +11,4 @@ const File = () => (
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
export default File;
|
export default Channel;
|
||||||
|
|||||||
Reference in New Issue
Block a user