Skip to content

Commit

Permalink
feat: support claude now (close #150)
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Jul 22, 2023
1 parent 4139a70 commit 2ff15ba
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 127 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用
## 功能
1. 支持多种 API 访问渠道:
+ [x] OpenAI 官方通道(支持配置镜像)
+ [x] [Anthropic Claude 系列模型](https://anthropic.com)
+ [x] **Azure OpenAI API**
+ [x] [API Distribute](https://api.gptjk.top/register?aff=QGxj)
+ [x] [OpenAI-SB](https://openai-sb.com)
Expand Down
2 changes: 2 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const (
ChannelTypePaLM = 11
ChannelTypeAPI2GPT = 12
ChannelTypeAIGC2D = 13
ChannelTypeAnthropic = 14
)

var ChannelBaseURLs = []string{
Expand All @@ -168,4 +169,5 @@ var ChannelBaseURLs = []string{
"", // 11
"https://api.api2gpt.com", // 12
"https://api.aigc2d.com", // 13
"https://api.anthropic.com", // 14
}
2 changes: 2 additions & 0 deletions common/model-ratio.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var ModelRatio = map[string]float64{
"text-moderation-stable": 0.1,
"text-moderation-latest": 0.1,
"dall-e": 8,
"claude-instant-1": 0.75,
"claude-2": 30,
}

func ModelRatio2JSONString() string {
Expand Down
18 changes: 18 additions & 0 deletions controller/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,24 @@ func init() {
Root: "ChatGLM2",
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)
for _, model := range openAIModels {
Expand Down
40 changes: 40 additions & 0 deletions controller/relay-claude.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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
}
}
Loading

0 comments on commit 2ff15ba

Please sign in to comment.