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
3379ea5e
authored
Jul 22, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support claude now (close #150)
parent
cfd220cf
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
90 additions
and
6 deletions
+90
-6
README.md
+1
-0
common/constants.go
+2
-0
common/model-ratio.go
+2
-0
controller/model.go
+18
-0
controller/relay-claude.go
+40
-0
controller/relay-text.go
+0
-0
controller/relay.go
+26
-6
web/src/constants/channel.constants.js
+1
-0
No files found.
README.md
View file @
3379ea5e
...
@@ -60,6 +60,7 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用
...
@@ -60,6 +60,7 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用
## 功能
## 功能
1.
支持多种 API 访问渠道:
1.
支持多种 API 访问渠道:
+
[
x
]
OpenAI 官方通道(支持配置镜像)
+
[
x
]
OpenAI 官方通道(支持配置镜像)
+
[
x
]
[
Anthropic Claude 系列模型
]
(https://anthropic.com)
+
[
x
]
**Azure OpenAI API**
+
[
x
]
**Azure OpenAI API**
+
[
x
]
[
API Distribute
]
(https://api.gptjk.top/register?aff=QGxj)
+
[
x
]
[
API Distribute
]
(https://api.gptjk.top/register?aff=QGxj)
+
[
x
]
[
OpenAI-SB
]
(https://openai-sb.com)
+
[
x
]
[
OpenAI-SB
]
(https://openai-sb.com)
...
...
common/constants.go
View file @
3379ea5e
...
@@ -151,6 +151,7 @@ const (
...
@@ -151,6 +151,7 @@ const (
ChannelTypePaLM
=
11
ChannelTypePaLM
=
11
ChannelTypeAPI2GPT
=
12
ChannelTypeAPI2GPT
=
12
ChannelTypeAIGC2D
=
13
ChannelTypeAIGC2D
=
13
ChannelTypeAnthropic
=
14
)
)
var
ChannelBaseURLs
=
[]
string
{
var
ChannelBaseURLs
=
[]
string
{
...
@@ -168,4 +169,5 @@ var ChannelBaseURLs = []string{
...
@@ -168,4 +169,5 @@ var ChannelBaseURLs = []string{
""
,
// 11
""
,
// 11
"https://api.api2gpt.com"
,
// 12
"https://api.api2gpt.com"
,
// 12
"https://api.aigc2d.com"
,
// 13
"https://api.aigc2d.com"
,
// 13
"https://api.anthropic.com"
,
// 14
}
}
common/model-ratio.go
View file @
3379ea5e
...
@@ -36,6 +36,8 @@ var ModelRatio = map[string]float64{
...
@@ -36,6 +36,8 @@ var ModelRatio = map[string]float64{
"text-moderation-stable"
:
0.1
,
"text-moderation-stable"
:
0.1
,
"text-moderation-latest"
:
0.1
,
"text-moderation-latest"
:
0.1
,
"dall-e"
:
8
,
"dall-e"
:
8
,
"claude-instant-1"
:
0.75
,
"claude-2"
:
30
,
}
}
func
ModelRatio2JSONString
()
string
{
func
ModelRatio2JSONString
()
string
{
...
...
controller/model.go
View file @
3379ea5e
...
@@ -270,6 +270,24 @@ func init() {
...
@@ -270,6 +270,24 @@ func init() {
Root
:
"ChatGLM2"
,
Root
:
"ChatGLM2"
,
Parent
:
nil
,
Parent
:
nil
,
},
},
{
Id
:
"claude-instant-1"
,
Object
:
"model"
,
Created
:
1677649963
,
OwnedBy
:
"anturopic"
,
Permission
:
permission
,
Root
:
"claude-instant-1"
,
Parent
:
nil
,
},
{
Id
:
"claude-2"
,
Object
:
"model"
,
Created
:
1677649963
,
OwnedBy
:
"anturopic"
,
Permission
:
permission
,
Root
:
"claude-2"
,
Parent
:
nil
,
},
}
}
openAIModelsMap
=
make
(
map
[
string
]
OpenAIModels
)
openAIModelsMap
=
make
(
map
[
string
]
OpenAIModels
)
for
_
,
model
:=
range
openAIModels
{
for
_
,
model
:=
range
openAIModels
{
...
...
controller/relay-claude.go
0 → 100644
View file @
3379ea5e
package
controller
type
ClaudeMetadata
struct
{
UserId
string
`json:"user_id"`
}
type
ClaudeRequest
struct
{
Model
string
`json:"model"`
Prompt
string
`json:"prompt"`
MaxTokensToSample
int
`json:"max_tokens_to_sample"`
StopSequences
[]
string
`json:"stop_sequences,omitempty"`
Temperature
float64
`json:"temperature,omitempty"`
TopP
float64
`json:"top_p,omitempty"`
TopK
int
`json:"top_k,omitempty"`
//ClaudeMetadata `json:"metadata,omitempty"`
Stream
bool
`json:"stream,omitempty"`
}
type
ClaudeError
struct
{
Type
string
`json:"type"`
Message
string
`json:"message"`
}
type
ClaudeResponse
struct
{
Completion
string
`json:"completion"`
StopReason
string
`json:"stop_reason"`
Model
string
`json:"model"`
Error
ClaudeError
`json:"error"`
}
func
stopReasonClaude2OpenAI
(
reason
string
)
string
{
switch
reason
{
case
"stop_sequence"
:
return
"stop"
case
"max_tokens"
:
return
"length"
default
:
return
reason
}
}
controller/relay-text.go
View file @
3379ea5e
This diff is collapsed.
Click to expand it.
controller/relay.go
View file @
3379ea5e
...
@@ -85,6 +85,20 @@ type TextResponse struct {
...
@@ -85,6 +85,20 @@ type TextResponse struct {
Error
OpenAIError
`json:"error"`
Error
OpenAIError
`json:"error"`
}
}
type
OpenAITextResponseChoice
struct
{
Index
int
`json:"index"`
Message
`json:"message"`
FinishReason
string
`json:"finish_reason"`
}
type
OpenAITextResponse
struct
{
Id
string
`json:"id"`
Object
string
`json:"object"`
Created
int64
`json:"created"`
Choices
[]
OpenAITextResponseChoice
`json:"choices"`
Usage
`json:"usage"`
}
type
ImageResponse
struct
{
type
ImageResponse
struct
{
Created
int
`json:"created"`
Created
int
`json:"created"`
Data
[]
struct
{
Data
[]
struct
{
...
@@ -92,13 +106,19 @@ type ImageResponse struct {
...
@@ -92,13 +106,19 @@ type ImageResponse struct {
}
}
}
}
type
ChatCompletionsStreamResponseChoice
struct
{
Delta
struct
{
Content
string
`json:"content"`
}
`json:"delta"`
FinishReason
string
`json:"finish_reason,omitempty"`
}
type
ChatCompletionsStreamResponse
struct
{
type
ChatCompletionsStreamResponse
struct
{
Choices
[]
struct
{
Id
string
`json:"id"`
Delta
struct
{
Object
string
`json:"object"`
Content
string
`json:"content"`
Created
int64
`json:"created"`
}
`json:"delta"`
Model
string
`json:"model"`
FinishReason
string
`json:"finish_reason"`
Choices
[]
ChatCompletionsStreamResponseChoice
`json:"choices"`
}
`json:"choices"`
}
}
type
CompletionsStreamResponse
struct
{
type
CompletionsStreamResponse
struct
{
...
...
web/src/constants/channel.constants.js
View file @
3379ea5e
export
const
CHANNEL_OPTIONS
=
[
export
const
CHANNEL_OPTIONS
=
[
{
key
:
1
,
text
:
'OpenAI'
,
value
:
1
,
color
:
'green'
},
{
key
:
1
,
text
:
'OpenAI'
,
value
:
1
,
color
:
'green'
},
{
key
:
14
,
text
:
'Anthropic'
,
value
:
14
,
color
:
'black'
},
{
key
:
8
,
text
:
'自定义'
,
value
:
8
,
color
:
'pink'
},
{
key
:
8
,
text
:
'自定义'
,
value
:
8
,
color
:
'pink'
},
{
key
:
3
,
text
:
'Azure'
,
value
:
3
,
color
:
'olive'
},
{
key
:
3
,
text
:
'Azure'
,
value
:
3
,
color
:
'olive'
},
{
key
:
2
,
text
:
'API2D'
,
value
:
2
,
color
:
'blue'
},
{
key
:
2
,
text
:
'API2D'
,
value
:
2
,
color
:
'blue'
},
...
...
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