-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathclient.go
68 lines (62 loc) · 3.43 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package sdk
import (
"context"
"github.com/iimeta/fastapi-sdk/ai360"
"github.com/iimeta/fastapi-sdk/aliyun"
"github.com/iimeta/fastapi-sdk/anthropic"
"github.com/iimeta/fastapi-sdk/baidu"
"github.com/iimeta/fastapi-sdk/consts"
"github.com/iimeta/fastapi-sdk/deepseek"
"github.com/iimeta/fastapi-sdk/google"
"github.com/iimeta/fastapi-sdk/logger"
"github.com/iimeta/fastapi-sdk/model"
"github.com/iimeta/fastapi-sdk/openai"
"github.com/iimeta/fastapi-sdk/volcengine"
"github.com/iimeta/fastapi-sdk/xfyun"
"github.com/iimeta/fastapi-sdk/zhipuai"
)
type Client interface {
ChatCompletion(ctx context.Context, request model.ChatCompletionRequest) (res model.ChatCompletionResponse, err error)
ChatCompletionStream(ctx context.Context, request model.ChatCompletionRequest) (responseChan chan *model.ChatCompletionResponse, err error)
Image(ctx context.Context, request model.ImageRequest) (res model.ImageResponse, err error)
Speech(ctx context.Context, request model.SpeechRequest) (res model.SpeechResponse, err error)
Transcription(ctx context.Context, request model.AudioRequest) (res model.AudioResponse, err error)
Embeddings(ctx context.Context, request model.EmbeddingRequest) (res model.EmbeddingResponse, err error)
Moderations(ctx context.Context, request model.ModerationRequest) (res model.ModerationResponse, err error)
}
func NewClient(ctx context.Context, corp, model, key, baseURL, path string, isSupportSystemRole *bool, proxyURL ...string) Client {
logger.Infof(ctx, "NewClient corp: %s, model: %s, key: %s", corp, model, key)
switch corp {
case consts.CORP_OPENAI:
return openai.NewClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_AZURE:
return openai.NewAzureClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_BAIDU:
return baidu.NewClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_XFYUN:
return xfyun.NewClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_ALIYUN:
return aliyun.NewClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_ZHIPUAI:
return zhipuai.NewClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_GOOGLE:
return google.NewClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_GCP_GEMINI:
return google.NewGcpClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_DEEPSEEK:
return deepseek.NewClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_DEEPSEEK_BAIDU:
return deepseek.NewClientBaidu(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_360AI:
return ai360.NewClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_ANTHROPIC:
return anthropic.NewClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_GCP_CLAUDE:
return anthropic.NewGcpClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_AWS_CLAUDE:
return anthropic.NewAwsClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
case consts.CORP_VOLC_ENGINE:
return volcengine.NewClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
}
return openai.NewClient(ctx, model, key, baseURL, path, isSupportSystemRole, proxyURL...)
}