Commit 3379ea5e by JustSong

feat: support claude now (close #150)

parent cfd220cf
...@@ -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)
......
...@@ -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
} }
...@@ -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 {
......
...@@ -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 {
......
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
}
}
...@@ -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 {
......
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' },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment