@@ -15,6 +15,8 @@ import (
15
15
"github.com/danielmiessler/fabric/plugins"
16
16
)
17
17
18
+ const defaultBaseUrl = "http://localhost:11434"
19
+
18
20
func NewClient () (ret * Client ) {
19
21
vendorName := "Ollama"
20
22
ret = & Client {}
@@ -26,26 +28,41 @@ func NewClient() (ret *Client) {
26
28
}
27
29
28
30
ret .ApiUrl = ret .AddSetupQuestionCustom ("API URL" , true ,
29
- "Enter your Ollama URL (as a reminder, it is usually http://localhost:1234/v1')" )
31
+ "Enter your Ollama URL (as a reminder, it is usually http://localhost:11434')" )
32
+ ret .ApiUrl .Value = defaultBaseUrl
33
+ ret .ApiKey = ret .PluginBase .AddSetupQuestion ("API key" , false )
34
+ ret .ApiKey .Value = ""
30
35
31
36
return
32
37
}
33
38
34
39
type Client struct {
35
40
* plugins.PluginBase
36
41
ApiUrl * plugins.SetupQuestion
37
-
42
+ ApiKey * plugins. SetupQuestion
38
43
apiUrl * url.URL
39
44
client * ollamaapi.Client
40
45
}
41
46
47
+ type transport_sec struct {
48
+ underlyingTransport http.RoundTripper
49
+ ApiKey * plugins.SetupQuestion
50
+ }
51
+
52
+ func (t * transport_sec ) RoundTrip (req * http.Request ) (* http.Response , error ) {
53
+ if t .ApiKey .Value != "" {
54
+ req .Header .Add ("Authorization" , "Bearer " + t .ApiKey .Value )
55
+ }
56
+ return t .underlyingTransport .RoundTrip (req )
57
+ }
58
+
42
59
func (o * Client ) configure () (err error ) {
43
60
if o .apiUrl , err = url .Parse (o .ApiUrl .Value ); err != nil {
44
61
fmt .Printf ("cannot parse URL: %s: %v\n " , o .ApiUrl .Value , err )
45
62
return
46
63
}
47
64
48
- o .client = ollamaapi .NewClient (o .apiUrl , & http.Client {Timeout : 1200000 * time .Millisecond })
65
+ o .client = ollamaapi .NewClient (o .apiUrl , & http.Client {Timeout : 1200000 * time .Millisecond , Transport : & transport_sec { underlyingTransport : http . DefaultTransport , ApiKey : o . ApiKey } })
49
66
return
50
67
}
51
68
0 commit comments