-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.go
57 lines (46 loc) · 1.7 KB
/
api.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
package chatmodels
import (
"context"
"cloud.google.com/go/vertexai/genai"
"github.com/sashabaranov/go-openai"
"github.com/stretchr/testify/mock"
)
type GptAPI interface {
AutoComplete(context.Context, string) (openai.ChatCompletionResponse, error)
}
type GeminiAPI interface {
GeminiChat(context.Context, string) (*genai.GenerateContentResponse, error)
}
type CloudFlareAiWorkerAPI interface {
GenerateText(context.Context, string, string) (string, error)
GenerateImage(ctx context.Context, prompt string, model string) ([]byte, error)
GenerateTranslation(ctx context.Context, req *GenerateTranslationRequest) (string, error)
}
type mockAPI struct {
mock.Mock
}
func (api *mockAPI) AutoComplete(ctx context.Context, prompt string) (res openai.ChatCompletionResponse, err error) {
args := api.Called(ctx, prompt)
res = args.Get(0).(openai.ChatCompletionResponse)
return res, args.Error(1)
}
func (api *mockAPI) GeminiChat(ctx context.Context, prompt string) (res *genai.GenerateContentResponse, err error) {
args := api.Called(ctx, prompt)
res = args.Get(0).(*genai.GenerateContentResponse)
return res, args.Error(1)
}
func (api *mockAPI) GenerateText(ctx context.Context, prompt string, model string) (string, error) {
args := api.Called(ctx, prompt, model)
return args.String(0), args.Error(1)
}
func (api *mockAPI) GenerateImage(ctx context.Context, prompt string, model string) (res []byte, err error) {
args := api.Called(ctx, prompt, model)
if args.Get(0) != nil {
res = args.Get(0).([]byte)
}
return res, args.Error(1)
}
func (api *mockAPI) GenerateTranslation(ctx context.Context, req *GenerateTranslationRequest) (string, error) {
args := api.Called(ctx, req)
return args.String(0), args.Error(1)
}