History

fix(codex): only override instructions when upstream provides them

hkfires committed 10 months ago

Commit 220ca451 parent 70a82d81 file · +7 −3Browse files

Unified · Split

internal/translator/codex/openai/responses/codex_openai-responses_response.go+7−3
@@ -19,8 +19,10 @@ func ConvertCodexResponseToOpenAIResponses(ctx context.Context, modelName string · 18 unmodified lines
1919 if typeResult := gjson.GetBytes(rawJSON, "type"); typeResult.Exists() {
2020 typeStr := typeResult.String()
2121 if typeStr == "response.created" || typeStr == "response.in_progress" || typeStr == "response.completed" {
22− instructions := selectInstructions(originalRequestRawJSON, requestRawJSON)
23− rawJSON, _ = sjson.SetBytes(rawJSON, "response.instructions", instructions)
22+ if gjson.GetBytes(rawJSON, "response.instructions").Exists() {
23+ instructions := selectInstructions(originalRequestRawJSON, requestRawJSON)
24+ rawJSON, _ = sjson.SetBytes(rawJSON, "response.instructions", instructions)
25+ }
2426 }
2527 }
2628 out := fmt.Sprintf("data: %s", string(rawJSON))
@@ -39,7 +41,9 @@ func ConvertCodexResponseToOpenAIResponsesNonStream(_ context.Context, modelName · 12 unmodified lines
3941 }
4042 responseResult := rootResult.Get("response")
4143 template := responseResult.Raw
42− template, _ = sjson.Set(template, "instructions", selectInstructions(originalRequestRawJSON, requestRawJSON))
44+ if responseResult.Get("instructions").Exists() {
45+ template, _ = sjson.Set(template, "instructions", selectInstructions(originalRequestRawJSON, requestRawJSON))
46+ }
4347 return template
4448 }
4549