File tree Expand file tree Collapse file tree 5 files changed +15
-1
lines changed Expand file tree Collapse file tree 5 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ anyhow = "1.0.69"
21
21
async-openai = " 0.8.0"
22
22
async-std = " 1.12.0"
23
23
async-trait = " 0.1.64"
24
+ backoff = " 0.4.0"
24
25
clap = { version = " 4.1.8" , features = [" derive" ] }
25
26
colored = " 2.0.0"
26
27
config = { version = " 0.13.3" , features = [" toml" ] }
Original file line number Diff line number Diff line change @@ -32,7 +32,14 @@ impl OpenAIClient {
32
32
bail ! ( "No OpenAI model configured." )
33
33
}
34
34
35
- let client = Client :: new ( ) . with_api_key ( & api_key) ;
35
+ let mut client = Client :: new ( ) . with_api_key ( & api_key) ;
36
+
37
+ if settings. retries . unwrap_or_default ( ) > 0 {
38
+ let backoff = backoff:: ExponentialBackoffBuilder :: new ( )
39
+ . with_max_elapsed_time ( Some ( std:: time:: Duration :: from_secs ( 60 ) ) )
40
+ . build ( ) ;
41
+ client = client. with_backoff ( backoff) ;
42
+ }
36
43
Ok ( Self { model, client } )
37
44
}
38
45
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ impl<'de> serde::Deserialize<'de> for ModelProvider {
73
73
pub ( crate ) struct OpenAISettings {
74
74
pub api_key : Option < String > ,
75
75
pub model : Option < String > ,
76
+ pub retries : Option < u16 > ,
76
77
}
77
78
78
79
// implement the trait `From<OpenAISettings>` for `ValueKind`
@@ -81,6 +82,7 @@ impl From<OpenAISettings> for config::ValueKind {
81
82
let mut properties = HashMap :: new ( ) ;
82
83
properties. insert ( "api_key" . to_string ( ) , config:: Value :: from ( settings. api_key ) ) ;
83
84
properties. insert ( "model" . to_string ( ) , config:: Value :: from ( settings. model ) ) ;
85
+ properties. insert ( "retries" . to_string ( ) , config:: Value :: from ( settings. retries ) ) ;
84
86
Self :: Table ( properties)
85
87
}
86
88
}
@@ -198,6 +200,7 @@ impl Settings {
198
200
Some ( OpenAISettings {
199
201
api_key : None ,
200
202
model : Some ( DEFAULT_OPENAI_MODEL . to_string ( ) ) ,
203
+ retries : Some ( 2 ) ,
201
204
} ) ,
202
205
) ?
203
206
. set_default (
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ the-force = { value = "surrounds-you" }
87
87
"model_provider" ,
88
88
"openai.api_key" ,
89
89
"openai.model" ,
90
+ "openai.retries" ,
90
91
"output.lang" ,
91
92
"prompt.commit_summary" ,
92
93
"prompt.commit_title" ,
@@ -108,6 +109,7 @@ the-force = { value = "surrounds-you" }
108
109
"model_provider" ,
109
110
"openai.api_key" ,
110
111
"openai.model" ,
112
+ "openai.retries" ,
111
113
"output.lang" ,
112
114
"prompt.commit_summary" ,
113
115
"prompt.commit_title" ,
You can’t perform that action at this time.
0 commit comments