Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3a14f51a
authored
Sep 08, 2024
by
GuoRuqiang
Committed by
GitHub
Sep 08, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'Calcium-Ion:main' into main
parents
134be1f4
89713975
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
20 additions
and
11 deletions
+20
-11
README.md
+1
-1
common/constants.go
+3
-0
common/email.go
+4
-1
relay/channel/cohere/dto.go
+1
-0
relay/channel/cohere/relay-cohere.go
+2
-0
service/token_counter.go
+1
-1
web/src/components/TokensTable.js
+8
-8
No files found.
README.md
View file @
3a14f51a
...
@@ -66,7 +66,7 @@
...
@@ -66,7 +66,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`
目录到宿主机)
...
...
common/constants.go
View file @
3a14f51a
...
@@ -112,6 +112,9 @@ var RelayTimeout = GetEnvOrDefault("RELAY_TIMEOUT", 0) // unit is second
...
@@ -112,6 +112,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"
)
)
...
...
common/email.go
View file @
3a14f51a
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
)
)
func
generateMessageID
()
string
{
func
generateMessageID
()
string
{
domain
:=
strings
.
Split
(
SMTP
From
,
"@"
)[
1
]
domain
:=
strings
.
Split
(
SMTP
Account
,
"@"
)[
1
]
return
fmt
.
Sprintf
(
"<%d.%s@%s>"
,
time
.
Now
()
.
UnixNano
(),
GetRandomString
(
12
),
domain
)
return
fmt
.
Sprintf
(
"<%d.%s@%s>"
,
time
.
Now
()
.
UnixNano
(),
GetRandomString
(
12
),
domain
)
}
}
...
@@ -18,6 +18,9 @@ func SendEmail(subject string, receiver string, content string) error {
...
@@ -18,6 +18,9 @@ func SendEmail(subject string, receiver string, content string) error {
if
SMTPFrom
==
""
{
// for compatibility
if
SMTPFrom
==
""
{
// for compatibility
SMTPFrom
=
SMTPAccount
SMTPFrom
=
SMTPAccount
}
}
if
SMTPServer
==
""
&&
SMTPAccount
==
""
{
return
fmt
.
Errorf
(
"SMTP 服务器未配置"
)
}
encodedSubject
:=
fmt
.
Sprintf
(
"=?UTF-8?B?%s?="
,
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
subject
)))
encodedSubject
:=
fmt
.
Sprintf
(
"=?UTF-8?B?%s?="
,
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
subject
)))
mail
:=
[]
byte
(
fmt
.
Sprintf
(
"To: %s
\r\n
"
+
mail
:=
[]
byte
(
fmt
.
Sprintf
(
"To: %s
\r\n
"
+
"From: %s<%s>
\r\n
"
+
"From: %s<%s>
\r\n
"
+
...
...
relay/channel/cohere/dto.go
View file @
3a14f51a
...
@@ -8,6 +8,7 @@ type CohereRequest struct {
...
@@ -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"`
}
}
type
ChatHistory
struct
{
type
ChatHistory
struct
{
...
...
relay/channel/cohere/relay-cohere.go
View file @
3a14f51a
...
@@ -22,6 +22,7 @@ func requestOpenAI2Cohere(textRequest dto.GeneralOpenAIRequest) *CohereRequest {
...
@@ -22,6 +22,7 @@ func requestOpenAI2Cohere(textRequest dto.GeneralOpenAIRequest) *CohereRequest {
Message
:
""
,
Message
:
""
,
Stream
:
textRequest
.
Stream
,
Stream
:
textRequest
.
Stream
,
MaxTokens
:
textRequest
.
GetMaxTokens
(),
MaxTokens
:
textRequest
.
GetMaxTokens
(),
SafetyMode
:
common
.
CohereSafetySetting
,
}
}
if
cohereReq
.
MaxTokens
==
0
{
if
cohereReq
.
MaxTokens
==
0
{
cohereReq
.
MaxTokens
=
4000
cohereReq
.
MaxTokens
=
4000
...
@@ -44,6 +45,7 @@ func requestOpenAI2Cohere(textRequest dto.GeneralOpenAIRequest) *CohereRequest {
...
@@ -44,6 +45,7 @@ func requestOpenAI2Cohere(textRequest dto.GeneralOpenAIRequest) *CohereRequest {
})
})
}
}
}
}
return
&
cohereReq
return
&
cohereReq
}
}
...
...
service/token_counter.go
View file @
3a14f51a
...
@@ -52,7 +52,7 @@ func InitTokenEncoders() {
...
@@ -52,7 +52,7 @@ func InitTokenEncoders() {
}
}
func
getModelDefaultTokenEncoder
(
model
string
)
*
tiktoken
.
Tiktoken
{
func
getModelDefaultTokenEncoder
(
model
string
)
*
tiktoken
.
Tiktoken
{
if
strings
.
HasPrefix
(
model
,
"gpt-4o"
)
{
if
strings
.
HasPrefix
(
model
,
"gpt-4o"
)
||
strings
.
HasPrefix
(
model
,
"chatgpt-4o"
)
{
return
cl200kTokenEncoder
return
cl200kTokenEncoder
}
}
return
defaultTokenEncoder
return
defaultTokenEncoder
...
...
web/src/components/TokensTable.js
View file @
3a14f51a
...
@@ -225,14 +225,14 @@ const TokensTable = () => {
...
@@ -225,14 +225,14 @@ const TokensTable = () => {
onOpenLink
(
'next-mj'
,
record
.
key
);
onOpenLink
(
'next-mj'
,
record
.
key
);
},
},
},
},
{
//
{
node
:
'item'
,
//
node: 'item',
key
:
'lobe'
,
//
key: 'lobe',
name
:
'Lobe Chat'
,
//
name: 'Lobe Chat',
onClick
:
()
=>
{
//
onClick: () => {
onOpenLink
(
'lobe'
,
record
.
key
);
//
onOpenLink('lobe', record.key);
},
//
},
},
//
},
{
{
node
:
'item'
,
node
:
'item'
,
key
:
'ama'
,
key
:
'ama'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment