-
Notifications
You must be signed in to change notification settings - Fork 1
/
chat.go
45 lines (39 loc) · 1.73 KB
/
chat.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
package sdk
import (
"context"
"github.com/iimeta/fastapi-sdk/aliyun"
"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/xfyun"
"github.com/iimeta/fastapi-sdk/zhipuai"
)
type Chat 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)
}
func NewClient(ctx context.Context, corp, model, key, baseURL, path string, proxyURL ...string) Chat {
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, proxyURL...)
case consts.CORP_BAIDU:
return baidu.NewClient(ctx, model, key, baseURL, path, proxyURL...)
case consts.CORP_XFYUN:
return xfyun.NewClient(ctx, model, key, baseURL, path, proxyURL...)
case consts.CORP_ALIYUN:
return aliyun.NewClient(ctx, model, key, baseURL, path, proxyURL...)
case consts.CORP_ZHIPUAI:
return zhipuai.NewClient(ctx, model, key, baseURL, path, proxyURL...)
case consts.CORP_GOOGLE:
return google.NewClient(ctx, model, key, baseURL, path, proxyURL...)
case consts.CORP_DEEPSEEK:
return deepseek.NewClient(ctx, model, key, baseURL, path, proxyURL...)
}
return openai.NewClient(ctx, model, key, baseURL, path, proxyURL...)
}