mirror of
https://github.com/BlueSkyXN/DeepAI.git
synced 2025-12-24 11:31:00 +08:00
0.0.5
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -23,3 +23,4 @@ go.work.sum
|
||||
|
||||
# env file
|
||||
.env
|
||||
/dist
|
||||
|
||||
@@ -3,7 +3,8 @@ thinking_services:
|
||||
# 主要思考服务 - DeepSeek
|
||||
- id: 1
|
||||
name: "deepseek-thinking"
|
||||
base_url: "https://api.deepseek.com"
|
||||
base_url: "https://api-inference.modelscope.cn"
|
||||
api_path: "/v1/chat/completions"
|
||||
api_key: "sk-xxxxxxxxxxxxxxxx"
|
||||
timeout: 10 # 秒
|
||||
retry: 3
|
||||
@@ -13,6 +14,7 @@ thinking_services:
|
||||
- id: 2
|
||||
name: "openai-thinking"
|
||||
base_url: "https://api.openai.com"
|
||||
api_path: "/v1/chat/completions"
|
||||
api_key: "sk-xxxxxxxxxxxxxxxx"
|
||||
timeout: 15
|
||||
retry: 2
|
||||
@@ -23,43 +25,30 @@ channels:
|
||||
# DeepSeek 通道
|
||||
"1":
|
||||
name: "deepseek-channel"
|
||||
base_url: "https://api.deepseek.com"
|
||||
key_prefix: "sk-deep"
|
||||
base_url: "https://api-inference.modelscope.cn"
|
||||
api_path: "/v1/chat/completions"
|
||||
timeout: 30
|
||||
models:
|
||||
- "deepseek-chat"
|
||||
- "deepseek-code"
|
||||
|
||||
# OpenAI 通道
|
||||
"2":
|
||||
name: "openai-channel"
|
||||
base_url: "https://api.openai.com"
|
||||
key_prefix: "sk-op"
|
||||
api_path: "/v1/chat/completions"
|
||||
timeout: 30
|
||||
models:
|
||||
- "gpt-3.5-turbo"
|
||||
- "gpt-4"
|
||||
|
||||
# Anthropic 通道
|
||||
"3":
|
||||
name: "anthropic-channel"
|
||||
base_url: "https://api.anthropic.com"
|
||||
key_prefix: "sk-ant"
|
||||
api_path: "/v1/messages"
|
||||
timeout: 30
|
||||
models:
|
||||
- "claude-3-opus"
|
||||
- "claude-3-sonnet"
|
||||
|
||||
# Moonshot 通道
|
||||
"4":
|
||||
name: "moonshot-channel"
|
||||
base_url: "https://api.moonshot.cn"
|
||||
key_prefix: "sk-moon"
|
||||
api_path: "/v1/chat/completions"
|
||||
timeout: 30
|
||||
models:
|
||||
- "moonshot-v1-8k"
|
||||
- "moonshot-v1-32k"
|
||||
- "moonshot-v1-128k"
|
||||
|
||||
# 全局配置
|
||||
global:
|
||||
@@ -85,7 +74,7 @@ global:
|
||||
|
||||
# 服务配置
|
||||
server:
|
||||
port: 8080
|
||||
port: 8888
|
||||
host: "0.0.0.0"
|
||||
read_timeout: 30
|
||||
write_timeout: 30
|
||||
|
||||
18
main.go
18
main.go
@@ -24,18 +24,28 @@ type ThinkingService struct {
|
||||
ID int `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
BaseURL string `mapstructure:"base_url"`
|
||||
APIPath string `mapstructure:"api_path"`
|
||||
APIKey string `mapstructure:"api_key"`
|
||||
Timeout int `mapstructure:"timeout"`
|
||||
Retry int `mapstructure:"retry"`
|
||||
Weight int `mapstructure:"weight"`
|
||||
}
|
||||
|
||||
// GetFullURL returns the complete API URL
|
||||
func (s *ThinkingService) GetFullURL() string {
|
||||
return s.BaseURL + s.APIPath
|
||||
}
|
||||
|
||||
type Channel struct {
|
||||
Name string `mapstructure:"name"`
|
||||
BaseURL string `mapstructure:"base_url"`
|
||||
KeyPrefix string `mapstructure:"key_prefix"`
|
||||
APIPath string `mapstructure:"api_path"`
|
||||
Timeout int `mapstructure:"timeout"`
|
||||
Models []string `mapstructure:"models"`
|
||||
}
|
||||
|
||||
// GetFullURL returns the complete API URL
|
||||
func (c *Channel) GetFullURL() string {
|
||||
return c.BaseURL + c.APIPath
|
||||
}
|
||||
|
||||
type GlobalConfig struct {
|
||||
@@ -190,7 +200,7 @@ func (h *StreamHandler) streamThinking(ctx context.Context, req *ChatCompletionR
|
||||
}
|
||||
|
||||
request, err := http.NewRequestWithContext(ctx, "POST",
|
||||
h.thinkingService.BaseURL+"/v1/chat/completions",
|
||||
h.thinkingService.GetFullURL(),
|
||||
bytes.NewBuffer(jsonData))
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -277,7 +287,7 @@ func (h *StreamHandler) streamFinalResponse(ctx context.Context, req *ChatComple
|
||||
|
||||
// 创建请求
|
||||
request, err := http.NewRequestWithContext(ctx, "POST",
|
||||
h.targetChannel.BaseURL+"/v1/chat/completions",
|
||||
h.targetChannel.GetFullURL(),
|
||||
bytes.NewBuffer(jsonData))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user