mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
refactor: remove redundant Codex instruction validation logic
- Eliminated unnecessary calls to `misc.CodexInstructions` and corresponding checks in response processing. - Streamlined instruction handling by directly updating "instructions" field from the original request payload.
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/luispater/CLIProxyAPI/v5/internal/misc"
|
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"github.com/tidwall/sjson"
|
"github.com/tidwall/sjson"
|
||||||
)
|
)
|
||||||
@@ -19,11 +18,7 @@ func ConvertCodexResponseToOpenAIResponses(ctx context.Context, modelName string
|
|||||||
if typeResult := gjson.GetBytes(rawJSON, "type"); typeResult.Exists() {
|
if typeResult := gjson.GetBytes(rawJSON, "type"); typeResult.Exists() {
|
||||||
typeStr := typeResult.String()
|
typeStr := typeResult.String()
|
||||||
if typeStr == "response.created" || typeStr == "response.in_progress" || typeStr == "response.completed" {
|
if typeStr == "response.created" || typeStr == "response.in_progress" || typeStr == "response.completed" {
|
||||||
instructions := misc.CodexInstructions(modelName)
|
rawJSON, _ = sjson.SetBytes(rawJSON, "response.instructions", gjson.GetBytes(originalRequestRawJSON, "instructions").String())
|
||||||
instructionsResult := gjson.GetBytes(rawJSON, "response.instructions")
|
|
||||||
if instructionsResult.Raw == instructions {
|
|
||||||
rawJSON, _ = sjson.SetBytes(rawJSON, "response.instructions", gjson.GetBytes(originalRequestRawJSON, "instructions").String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return []string{fmt.Sprintf("data: %s", string(rawJSON))}
|
return []string{fmt.Sprintf("data: %s", string(rawJSON))}
|
||||||
@@ -54,11 +49,7 @@ func ConvertCodexResponseToOpenAIResponsesNonStream(_ context.Context, modelName
|
|||||||
responseResult := rootResult.Get("response")
|
responseResult := rootResult.Get("response")
|
||||||
template := responseResult.Raw
|
template := responseResult.Raw
|
||||||
|
|
||||||
instructions := misc.CodexInstructions(modelName)
|
template, _ = sjson.Set(template, "instructions", gjson.GetBytes(originalRequestRawJSON, "instructions").String())
|
||||||
instructionsResult := gjson.Get(template, "instructions")
|
|
||||||
if instructionsResult.Raw == instructions {
|
|
||||||
template, _ = sjson.Set(template, "instructions", gjson.GetBytes(originalRequestRawJSON, "instructions").String())
|
|
||||||
}
|
|
||||||
return template
|
return template
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user