-
Notifications
You must be signed in to change notification settings - Fork 186
/
providers.go
71 lines (64 loc) · 1.81 KB
/
providers.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
69
70
71
package providers
import (
"fmt"
"os"
"github.com/aandrew-me/tgpt/v2/providers/blackboxai"
"github.com/aandrew-me/tgpt/v2/providers/duckduckgo"
"github.com/aandrew-me/tgpt/v2/providers/groq"
"github.com/aandrew-me/tgpt/v2/providers/koboldai"
"github.com/aandrew-me/tgpt/v2/providers/ollama"
"github.com/aandrew-me/tgpt/v2/providers/openai"
"github.com/aandrew-me/tgpt/v2/providers/phind"
"github.com/aandrew-me/tgpt/v2/structs"
http "github.com/bogdanfinn/fhttp"
)
var availableProviders = []string{
"", "blackboxai", "groq", "duckduckgo", "koboldai", "ollama", "openai", "phind",
}
func GetMainText(line string, provider string, input string) string {
switch provider {
case "blackboxai":
return blackboxai.GetMainText(line)
case "duckduckgo":
return duckduckgo.GetMainText(line)
case "groq":
return groq.GetMainText(line)
case "koboldai":
return koboldai.GetMainText(line)
case "ollama":
return ollama.GetMainText(line)
case "openai":
return openai.GetMainText(line)
default:
return phind.GetMainText(line)
}
}
func NewRequest(input string, params structs.Params, extraOptions structs.ExtraOptions) (*http.Response, error) {
validProvider := false
for _, str := range availableProviders {
if str == params.Provider {
validProvider = true
break
}
}
if !validProvider {
fmt.Fprintln(os.Stderr, "Invalid provider")
os.Exit(1)
}
switch params.Provider {
case "blackboxai":
return blackboxai.NewRequest(input, params)
case "duckduckgo":
return duckduckgo.NewRequest(input, params, params.PrevMessages)
case "groq":
return groq.NewRequest(input, params)
case "koboldai":
return koboldai.NewRequest(input, params)
case "ollama":
return ollama.NewRequest(input, params)
case "openai":
return openai.NewRequest(input, params)
default:
return phind.NewRequest(input, params)
}
}