Skip to content

Commit 1bb2e0b

Browse files
committed
refactor, Clarify API request attempts to conform to our terminology
1 parent 37c0f79 commit 1bb2e0b

File tree

7 files changed

+50
-50
lines changed

7 files changed

+50
-50
lines changed

cmd/eval-dev-quality/cmd/evaluate.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ type Evaluate struct {
5959
ProviderTokens map[string]string `long:"tokens" description:"API tokens for model providers (of the form '$provider:$token'). When using the environment variable, separate multiple definitions with ','." env:"PROVIDER_TOKEN" env-delim:","`
6060
// ProviderUrls holds all custom inference endpoint urls for the providers.
6161
ProviderUrls map[string]string `long:"urls" description:"Custom OpenAI API compatible inference endpoints (of the form '$provider:$url,...'). Use '$provider=custom-$name' to manually register a custom OpenAI API endpoint provider. Note that the models of a custom OpenAI API endpoint provider must be declared explicitly using the '--model' option. When using the environment variable, separate multiple definitions with ','." env:"PROVIDER_URL" env-delim:","`
62-
// QueryAttempts holds the number of query attempts to perform when a model request errors in the process of solving a task.
63-
QueryAttempts uint `long:"query-attempts" description:"Number of query attempts to perform when a model request errors in the process of solving a task." default:"3"`
64-
// QueryTimeout holds the timeout for model requests.
65-
QueryTimeout uint `long:"query-timeout" description:"Timeout of a model query in seconds. ('0' to disable)" default:"1200"`
62+
// APIRequestAttempts holds the number of allowed API requests per LLM query.
63+
APIRequestAttempts uint `long:"api-request-attempts" description:"Number of allowed API requests per LLM query." default:"3"`
64+
// APIRequestTimeout holds the timeout for API requests in seconds.
65+
APIRequestTimeout uint `long:"api-request-timeout" description:"Timeout of API requests in seconds. ('0' to disable)" default:"1200"`
6666

6767
// Repositories determines which repository should be used for the evaluation, or empty if all repositories should be used.
6868
Repositories []string `long:"repository" description:"Evaluate with this repository. By default all repositories are used."`
@@ -168,11 +168,11 @@ func (command *Evaluate) Initialize(args []string) (evaluationContext *evaluate.
168168
tools.SymflowerPath = command.SymflowerBinaryPath
169169
}
170170

171-
if command.QueryAttempts == 0 {
172-
command.logger.Panicf("number of configured query attempts must be greater than zero")
171+
if command.APIRequestAttempts == 0 {
172+
command.logger.Panicf("number of configured API requests must be greater than zero")
173173
}
174-
evaluationContext.QueryAttempts = command.QueryAttempts
175-
evaluationContext.QueryTimeout = command.QueryTimeout
174+
evaluationContext.APIReqestAttempts = command.APIRequestAttempts
175+
evaluationContext.APIRequestTimeout = command.APIRequestTimeout
176176

177177
if command.ExecutionTimeout == 0 {
178178
command.logger.Panicf("execution timeout for compilation and tests must be greater than zero")

cmd/eval-dev-quality/cmd/evaluate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ func TestEvaluateInitialize(t *testing.T) {
12721272
makeValidCommand := func(modify func(command *Evaluate)) *Evaluate {
12731273
c := &Evaluate{
12741274
ModelIDsWithProviderAndAttributes: []string{"symflower/smart-template"},
1275-
QueryAttempts: 1,
1275+
APIRequestAttempts: 1,
12761276

12771277
ResultPath: filepath.Join("$TEMP_PATH", "result-directory"),
12781278
TestdataPath: filepath.Join("..", "..", "..", "testdata"),
@@ -1530,7 +1530,7 @@ func TestEvaluateInitialize(t *testing.T) {
15301530
Name: "Attempts parameter hast to be greater then zero",
15311531

15321532
Command: makeValidCommand(func(command *Evaluate) {
1533-
command.QueryAttempts = 0
1533+
command.APIRequestAttempts = 0
15341534
}),
15351535

15361536
ValidatePanic: "number of configured query attempts must be greater than zero",

evaluate/evaluate.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ type Context struct {
2828
Models []evalmodel.Model
2929
// ProviderForModel holds the models and their associated provider.
3030
ProviderForModel map[evalmodel.Model]provider.Provider
31-
// QueryAttempts holds the number of query attempts to perform when a model request errors in the process of solving a task.
32-
QueryAttempts uint
33-
// QueryTimeout holds the timeout for model queries in seconds.
34-
QueryTimeout uint
31+
// APIReqestAttempts holds the number of allowed API requests per LLM query.
32+
APIReqestAttempts uint
33+
// APIRequestTimeout holds the timeout for API requests in seconds.
34+
APIRequestTimeout uint
3535

3636
// RepositoryPaths determines which relative repository paths should be used for the evaluation, or empty if all repositories should be used.
3737
RepositoryPaths []string
@@ -132,9 +132,9 @@ func Evaluate(ctx *Context) {
132132
modelSucceededBasicChecksOfLanguage[model] = map[evallanguage.Language]bool{}
133133
}
134134

135-
if r, ok := model.(evalmodel.SetQueryHandling); ok {
136-
r.SetQueryAttempts(ctx.QueryAttempts)
137-
r.SetQueryTimeout(ctx.QueryTimeout)
135+
if r, ok := model.(evalmodel.ConfigureAPIRequestHandling); ok {
136+
r.SetAPIRequestAttempts(ctx.APIReqestAttempts)
137+
r.SetAPIRequestTimeout(ctx.APIRequestTimeout)
138138
}
139139

140140
for _, taskIdentifier := range temporaryRepository.Configuration().Tasks {

evaluate/evaluate_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ func TestEvaluate(t *testing.T) {
105105
logger = logger.With(log.AttributeKeyResultPath, resultPath)
106106

107107
tc.Context.Log = logger
108-
if tc.Context.QueryAttempts == 0 {
109-
tc.Context.QueryAttempts = 1
108+
if tc.Context.APIReqestAttempts == 0 {
109+
tc.Context.APIReqestAttempts = 1
110110
}
111111
tc.Context.ResultPath = resultPath
112112
if tc.Context.TestdataPath == "" {
@@ -206,7 +206,7 @@ func TestEvaluate(t *testing.T) {
206206
Models: []evalmodel.Model{
207207
mockedModel,
208208
},
209-
QueryAttempts: 3,
209+
APIReqestAttempts: 3,
210210

211211
RepositoryPaths: []string{
212212
repositoryPath,
@@ -310,7 +310,7 @@ func TestEvaluate(t *testing.T) {
310310
Models: []evalmodel.Model{
311311
mockedModel,
312312
},
313-
QueryAttempts: 1,
313+
APIReqestAttempts: 1,
314314
},
315315

316316
ExpectedAssessments: []*metricstesting.AssessmentTuple{
@@ -397,7 +397,7 @@ func TestEvaluate(t *testing.T) {
397397
Models: []evalmodel.Model{
398398
mockedModel,
399399
},
400-
QueryAttempts: 3,
400+
APIReqestAttempts: 3,
401401

402402
RepositoryPaths: []string{
403403
repositoryPath,
@@ -500,7 +500,7 @@ func TestEvaluate(t *testing.T) {
500500
Models: []evalmodel.Model{
501501
mockedModel,
502502
},
503-
QueryAttempts: 3,
503+
APIReqestAttempts: 3,
504504

505505
RepositoryPaths: []string{
506506
repositoryPath,

model/llm/llm.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ type Model struct {
3333

3434
// attributes holds query attributes.
3535
attributes map[string]string
36-
// queryAttempts holds the number of query attempts to perform when a model request errors in the process of solving a task.
37-
queryAttempts uint
38-
// queryTimeout holds the timeout for model requests in seconds.
39-
queryTimeout uint
36+
// apiRequestAttempts holds the number of allowed API requests per LLM query.
37+
apiRequestAttempts uint
38+
// apiRequestTimeout holds the timeout for API requests in seconds.
39+
apiRequestTimeout uint
4040

4141
// metaInformation holds a model meta information.
4242
metaInformation *model.MetaInformation
@@ -48,8 +48,8 @@ func NewModel(provider provider.Query, modelIDWithAttributes string) (llmModel *
4848
id: modelIDWithAttributes,
4949
provider: provider,
5050

51-
queryAttempts: 1,
52-
queryTimeout: 0,
51+
apiRequestAttempts: 1,
52+
apiRequestTimeout: 0,
5353
}
5454
llmModel.modelID, llmModel.attributes = model.ParseModelID(modelIDWithAttributes)
5555

@@ -63,8 +63,8 @@ func NewModelWithMetaInformation(provider provider.Query, modelIdentifier string
6363
provider: provider,
6464
modelID: modelIdentifier,
6565

66-
queryAttempts: 1,
67-
queryTimeout: 0,
66+
apiRequestAttempts: 1,
67+
apiRequestTimeout: 0,
6868

6969
metaInformation: metaInformation,
7070
}
@@ -338,8 +338,8 @@ func (m *Model) query(logger *log.Logger, request string) (queryResult *provider
338338
func() error {
339339
logger.Info("querying model", "model", m.ID(), "query-id", id, "prompt", string(bytesutil.PrefixLines([]byte(request), []byte("\t"))))
340340
ctx := context.Background()
341-
if m.queryTimeout > 0 {
342-
c, cancel := context.WithTimeoutCause(ctx, time.Second*time.Duration(m.queryTimeout), pkgerrors.Errorf("request query timeout (%d seconds)", m.queryTimeout))
341+
if m.apiRequestTimeout > 0 {
342+
c, cancel := context.WithTimeoutCause(ctx, time.Second*time.Duration(m.apiRequestTimeout), pkgerrors.Errorf("API request timed out (%d seconds)", m.apiRequestTimeout))
343343
defer cancel()
344344
ctx = c
345345
}
@@ -360,12 +360,12 @@ func (m *Model) query(logger *log.Logger, request string) (queryResult *provider
360360

361361
return nil
362362
},
363-
retry.Attempts(m.queryAttempts),
363+
retry.Attempts(m.apiRequestAttempts),
364364
retry.Delay(5*time.Second),
365365
retry.DelayType(retry.BackOffDelay),
366366
retry.LastErrorOnly(true),
367367
retry.OnRetry(func(n uint, err error) {
368-
logger.Info("query retry", "count", n+1, "total", m.queryAttempts, "error", err)
368+
logger.Info("API request attempt failed", "count", n+1, "total", m.apiRequestAttempts, "error", err)
369369
}),
370370
); err != nil {
371371
return nil, err
@@ -533,14 +533,14 @@ func handleQueryResult(queryResult *provider.QueryResult, filePathAbsolute strin
533533
return assessment, nil
534534
}
535535

536-
var _ model.SetQueryHandling = (*Model)(nil)
536+
var _ model.ConfigureAPIRequestHandling = (*Model)(nil)
537537

538-
// SetQueryAttempts sets the number of query attempts to perform when a model request errors in the process of solving a task.
539-
func (m *Model) SetQueryAttempts(queryAttempts uint) {
540-
m.queryAttempts = queryAttempts
538+
// SetAPIRequestAttempts sets the number of allowed API requests per LLM query.
539+
func (m *Model) SetAPIRequestAttempts(queryAttempts uint) {
540+
m.apiRequestAttempts = queryAttempts
541541
}
542542

543-
// SetQueryTimeout sets the timeout for model requests in seconds.
544-
func (m *Model) SetQueryTimeout(timeout uint) {
545-
m.queryTimeout = timeout
543+
// SetAPIRequestTimeout sets the timeout for API requests in seconds.
544+
func (m *Model) SetAPIRequestTimeout(timeout uint) {
545+
m.apiRequestTimeout = timeout
546546
}

model/llm/llm_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ func TestModelQuery(t *testing.T) {
196196
tc.SetupMock(mock)
197197
}
198198
llm := NewModel(mock, "some-model")
199-
llm.SetQueryAttempts(tc.QueryAttempts)
200-
llm.SetQueryTimeout(tc.QueryTimeout)
199+
llm.SetAPIRequestAttempts(tc.QueryAttempts)
200+
llm.SetAPIRequestTimeout(tc.QueryTimeout)
201201

202202
queryResult, actualError := llm.query(logger, tc.Request)
203203

model/model.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ type Context struct {
8282
Logger *log.Logger
8383
}
8484

85-
// SetQueryHandling defines a model that can configure how API queries are handled.
86-
type SetQueryHandling interface {
87-
// SetQueryAttempts sets the number of query attempts to perform when a model request errors in the process of solving a task.
88-
SetQueryAttempts(attempts uint)
89-
// SetQueryTimeout sets the timeout for model requests in seconds.
90-
SetQueryTimeout(timeout uint)
85+
// ConfigureAPIRequestHandling defines a model that can configure how API requests are handled.
86+
type ConfigureAPIRequestHandling interface {
87+
// SetAPIRequestAttempts sets the number of allowed API requests per LLM query.
88+
SetAPIRequestAttempts(attempts uint)
89+
// SetAPIRequestTimeout sets the timeout for API requests in seconds.
90+
SetAPIRequestTimeout(timeout uint)
9191
}

0 commit comments

Comments
 (0)