72 lines
2.5 KiB
Go
72 lines
2.5 KiB
Go
package configuration
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"go.maximumdirect.net/promptkit/internal/backend"
|
|
"go.maximumdirect.net/promptkit/internal/domain"
|
|
"go.maximumdirect.net/promptkit/internal/profile"
|
|
)
|
|
|
|
// ProfileResource is the resolved profile before execution completion.
|
|
// Its fields borrow immutable configuration captured by the adapter.
|
|
type ProfileResource struct {
|
|
ID string
|
|
Backend, Endpoint, Model *string
|
|
Temperature, TopP *float64
|
|
MaxTokens, TimeoutSeconds *int
|
|
ServiceTier, ReasoningEffort *string
|
|
APIKeyEnv *string
|
|
APIKeyRequired *bool
|
|
ExtraParams map[string]any
|
|
}
|
|
|
|
// BackendResource is the resolved backend and its configured diagnostics.
|
|
// Its fields borrow immutable configuration captured by the adapter.
|
|
type BackendResource struct {
|
|
ID, Endpoint string
|
|
APIKeyEnv *string
|
|
ConcurrencyLimit, QueueCapacity *int
|
|
ExtraParams map[string]any
|
|
SmokeTests *domain.BackendSmokeTestConfig
|
|
}
|
|
|
|
func (state *loaded) InspectProfile(ctx context.Context, id string) (*ProfileResource, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
if state == nil {
|
|
return nil, fmt.Errorf("%w: %q", profile.ErrProfileNotFound, id)
|
|
}
|
|
config, ok := state.profileRecords[id]
|
|
if !ok {
|
|
return nil, fmt.Errorf("%w: %q", profile.ErrProfileNotFound, id)
|
|
}
|
|
return &ProfileResource{
|
|
ID: id, Backend: config.Backend, Endpoint: config.Endpoint, Model: config.Model,
|
|
Temperature: config.Temperature, TopP: config.TopP, MaxTokens: config.MaxTokens,
|
|
TimeoutSeconds: config.TimeoutSeconds, ServiceTier: config.ServiceTier,
|
|
ReasoningEffort: config.ReasoningEffort, APIKeyEnv: config.APIKeyEnv,
|
|
APIKeyRequired: config.APIKeyRequired, ExtraParams: config.ExtraParams,
|
|
}, nil
|
|
}
|
|
|
|
func (state *loaded) InspectBackend(ctx context.Context, id string) (*BackendResource, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
if state == nil {
|
|
return nil, fmt.Errorf("%w: %q", backend.ErrBackendNotFound, id)
|
|
}
|
|
config, ok := state.backendRecords[id]
|
|
if !ok {
|
|
return nil, fmt.Errorf("%w: %q", backend.ErrBackendNotFound, id)
|
|
}
|
|
return &BackendResource{
|
|
ID: id, Endpoint: valueOrZero(config.Endpoint), APIKeyEnv: config.APIKeyEnv,
|
|
ConcurrencyLimit: config.ConcurrencyLimit, QueueCapacity: config.QueueCapacity,
|
|
ExtraParams: config.ExtraParams, SmokeTests: captureBackend(id, config).SmokeTests,
|
|
}, nil
|
|
}
|