Support configuring effort alongside model
This commit is contained in:
@@ -28,6 +28,7 @@ import (
|
||||
type Options struct {
|
||||
Cwd string
|
||||
Model string
|
||||
Effort string
|
||||
Resume string
|
||||
ForkFrom string
|
||||
ForkAt string
|
||||
@@ -81,10 +82,12 @@ type Session struct {
|
||||
pendingMu sync.Mutex
|
||||
pending map[int64]chan rpcResult
|
||||
|
||||
stateMu sync.Mutex
|
||||
threadID string
|
||||
turnID string
|
||||
model string
|
||||
stateMu sync.Mutex
|
||||
threadID string
|
||||
turnID string
|
||||
model string
|
||||
effort string
|
||||
effortSet bool
|
||||
|
||||
servers map[string]*mcp.Server
|
||||
reminder string
|
||||
@@ -113,6 +116,9 @@ func Start(ctx context.Context, opts Options) (*Session, error) {
|
||||
|
||||
func (s *Session) serveHooks(opts Options) (map[string]any, error) {
|
||||
config := map[string]any{}
|
||||
if opts.Effort != "" {
|
||||
config["model_reasoning_effort"] = opts.Effort
|
||||
}
|
||||
if len(opts.StdioMCP) > 0 {
|
||||
config["mcp_servers"] = stdioConfig(opts.StdioMCP)
|
||||
}
|
||||
@@ -354,12 +360,44 @@ func (s *Session) ID() string {
|
||||
return s.threadID
|
||||
}
|
||||
|
||||
func (s *Session) SetModel(model string) {
|
||||
func (s *Session) SetModel(model, effort string) {
|
||||
s.stateMu.Lock()
|
||||
s.model = model
|
||||
s.effort = effort
|
||||
s.effortSet = true
|
||||
s.stateMu.Unlock()
|
||||
}
|
||||
|
||||
func (s *Session) defaultEffort(ctx context.Context, model string) (string, error) {
|
||||
cursor := ""
|
||||
for {
|
||||
resp := struct {
|
||||
Data []struct {
|
||||
Model string `json:"model"`
|
||||
DefaultReasoningEffort string `json:"defaultReasoningEffort"`
|
||||
} `json:"data"`
|
||||
NextCursor string `json:"nextCursor"`
|
||||
}{}
|
||||
params := map[string]any{"includeHidden": true}
|
||||
if cursor != "" {
|
||||
params["cursor"] = cursor
|
||||
}
|
||||
err := s.Call(ctx, "model/list", params, &resp)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("list models: %w", err)
|
||||
}
|
||||
for _, m := range resp.Data {
|
||||
if m.Model == model {
|
||||
return m.DefaultReasoningEffort, nil
|
||||
}
|
||||
}
|
||||
if resp.NextCursor == "" {
|
||||
return "", fmt.Errorf("codex lists no model %s to read its default effort from", model)
|
||||
}
|
||||
cursor = resp.NextCursor
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) Send(ctx context.Context, text string, images ...agentinput.Image) (Turn, error) {
|
||||
input := []UserInput{}
|
||||
for _, img := range images {
|
||||
@@ -373,9 +411,19 @@ func (s *Session) Send(ctx context.Context, text string, images ...agentinput.Im
|
||||
}
|
||||
|
||||
s.stateMu.Lock()
|
||||
params := TurnStartParams{ThreadID: s.threadID, Input: input, Model: s.model}
|
||||
params := TurnStartParams{ThreadID: s.threadID, Input: input, Model: s.model, Effort: ReasoningEffort(s.effort)}
|
||||
reset := s.effortSet && s.effort == ""
|
||||
s.model = ""
|
||||
s.effort = ""
|
||||
s.effortSet = false
|
||||
s.stateMu.Unlock()
|
||||
if reset {
|
||||
effort, err := s.defaultEffort(ctx, params.Model)
|
||||
if err != nil {
|
||||
return Turn{}, err
|
||||
}
|
||||
params.Effort = ReasoningEffort(effort)
|
||||
}
|
||||
if s.reminder != "" {
|
||||
params.AdditionalContext = map[string]AdditionalContextEntry{
|
||||
"byre": {Kind: AdditionalContextKindApplication, Value: s.reminder},
|
||||
|
||||
Reference in New Issue
Block a user