Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ func ConvertOpenAIResponsesRequestToCodex(modelName string, inputRawJSON []byte,
rawJSON, _ = sjson.SetBytes(rawJSON, "store", false)
rawJSON, _ = sjson.SetBytes(rawJSON, "parallel_tool_calls", true)
rawJSON, _ = sjson.SetBytes(rawJSON, "include", []string{"reasoning.encrypted_content"})
// Codex Responses rejects token limit fields, so strip them out before forwarding.
if v := gjson.GetBytes(rawJSON, "service_tier"); v.Exists() && v.String() == "fast" {
rawJSON, _ = sjson.SetBytes(rawJSON, "service_tier", "priority")
}
Comment on lines +23 to +25

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve readability and maintainability, consider extracting the magic strings "service_tier", "fast", and "priority" into named constants defined at the package level.

For example:

const (
    serviceTierField         = "service_tier"
    openAIServiceTierFast    = "fast"
    codexServiceTierPriority = "priority"
)

Then you can use these constants here:

if v := gjson.GetBytes(rawJSON, serviceTierField); v.Exists() && v.String() == openAIServiceTierFast {
    rawJSON, _ = sjson.SetBytes(rawJSON, serviceTierField, codexServiceTierPriority)
}

// Codex Responses rejects token limit and sampling fields, so strip them out before forwarding.
rawJSON, _ = sjson.DeleteBytes(rawJSON, "max_output_tokens")
rawJSON, _ = sjson.DeleteBytes(rawJSON, "max_completion_tokens")
rawJSON, _ = sjson.DeleteBytes(rawJSON, "temperature")
rawJSON, _ = sjson.DeleteBytes(rawJSON, "top_p")
rawJSON, _ = sjson.DeleteBytes(rawJSON, "service_tier")
rawJSON, _ = sjson.DeleteBytes(rawJSON, "truncation")
rawJSON = applyResponsesCompactionCompatibility(rawJSON)

Expand Down