History

fix(codex): ensure instructions field exists

hkfires committed 10 months ago

Commit 902bea21 parent c3ef46f1 file · +9 −0Browse files

Unified · Split

internal/runtime/executor/codex_executor.go+9−0
@@ -106,6 +106,9 @@ func (e *CodexExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, re · 105 unmodified lines
106106 body, _ = sjson.SetBytes(body, "stream", true)
107107 body, _ = sjson.DeleteBytes(body, "previous_response_id")
108108 body, _ = sjson.DeleteBytes(body, "prompt_cache_retention")
109+ if !gjson.GetBytes(body, "instructions").Exists() {
110+ body, _ = sjson.SetBytes(body, "instructions", "")
111+ }
109112
110113 url := strings.TrimSuffix(baseURL, "/") + "/responses"
111114 httpReq, err := e.cacheHelper(ctx, from, url, req, body)
@@ -213,6 +216,9 @@ func (e *CodexExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Au · 101 unmodified lines
213216 body, _ = sjson.DeleteBytes(body, "previous_response_id")
214217 body, _ = sjson.DeleteBytes(body, "prompt_cache_retention")
215218 body, _ = sjson.SetBytes(body, "model", baseModel)
219+ if !gjson.GetBytes(body, "instructions").Exists() {
220+ body, _ = sjson.SetBytes(body, "instructions", "")
221+ }
216222
217223 url := strings.TrimSuffix(baseURL, "/") + "/responses"
218224 httpReq, err := e.cacheHelper(ctx, from, url, req, body)
@@ -317,6 +323,9 @@ func (e *CodexExecutor) CountTokens(ctx context.Context, auth *cliproxyauth.Auth · 98 unmodified lines
317323 body, _ = sjson.DeleteBytes(body, "previous_response_id")
318324 body, _ = sjson.DeleteBytes(body, "prompt_cache_retention")
319325 body, _ = sjson.SetBytes(body, "stream", false)
326+ if !gjson.GetBytes(body, "instructions").Exists() {
327+ body, _ = sjson.SetBytes(body, "instructions", "")
328+ }
320329
321330 enc, err := tokenizerForCodexModel(baseModel)
322331 if err != nil {