@@ -87,7 +87,7 @@ func (o *Ollama) DefineModel(g *genkit.Genkit, model ModelDefinition, opts *ai.M
87
87
Supports : modelOpts .Supports ,
88
88
Versions : []string {},
89
89
}
90
- gen := & generator {model : model , serverAddress : o .ServerAddress }
90
+ gen := & generator {model : model , serverAddress : o .ServerAddress , timeout : o . Timeout }
91
91
return genkit .DefineModel (g , api .NewName (provider , model .Name ), meta , gen .generate )
92
92
}
93
93
@@ -111,6 +111,7 @@ type ModelDefinition struct {
111
111
type generator struct {
112
112
model ModelDefinition
113
113
serverAddress string
114
+ timeout int
114
115
}
115
116
116
117
type ollamaMessage struct {
@@ -196,6 +197,7 @@ type ollamaModelResponse struct {
196
197
// Ollama provides configuration options for the Init function.
197
198
type Ollama struct {
198
199
ServerAddress string // Server address of oLLama.
200
+ Timeout int // Response timeout in seconds (defaulted to 30 seconds)
199
201
200
202
mu sync.Mutex // Mutex to control access.
201
203
initted bool // Whether the plugin has been initialized.
@@ -218,6 +220,9 @@ func (o *Ollama) Init(ctx context.Context) []api.Action {
218
220
panic ("ollama: need ServerAddress" )
219
221
}
220
222
o .initted = true
223
+ if o .Timeout == 0 {
224
+ o .Timeout = 30
225
+ }
221
226
return []api.Action {}
222
227
}
223
228
@@ -274,7 +279,7 @@ func (g *generator) generate(ctx context.Context, input *ai.ModelRequest, cb fun
274
279
payload = chatReq
275
280
}
276
281
277
- client := & http.Client {Timeout : 30 * time .Second }
282
+ client := & http.Client {Timeout : time . Duration ( g . timeout ) * time .Second }
278
283
payloadBytes , err := json .Marshal (payload )
279
284
if err != nil {
280
285
return nil , err
0 commit comments