mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-02 20:40:52 +08:00
feat(codex): enable instruction toggling and update role terminology
- Added conditional logic for Codex instruction injection based on configuration. - Updated role terminology from "user" to "developer" for better alignment with context.
This commit is contained in:
@@ -52,7 +52,7 @@ func ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool)
|
|||||||
systemsResult := rootResult.Get("system")
|
systemsResult := rootResult.Get("system")
|
||||||
if systemsResult.IsArray() {
|
if systemsResult.IsArray() {
|
||||||
systemResults := systemsResult.Array()
|
systemResults := systemsResult.Array()
|
||||||
message := `{"type":"message","role":"user","content":[]}`
|
message := `{"type":"message","role":"developer","content":[]}`
|
||||||
for i := 0; i < len(systemResults); i++ {
|
for i := 0; i < len(systemResults); i++ {
|
||||||
systemResult := systemResults[i]
|
systemResult := systemResults[i]
|
||||||
systemTypeResult := systemResult.Get("type")
|
systemTypeResult := systemResult.Get("type")
|
||||||
@@ -245,6 +245,7 @@ func ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool)
|
|||||||
template, _ = sjson.Set(template, "include", []string{"reasoning.encrypted_content"})
|
template, _ = sjson.Set(template, "include", []string{"reasoning.encrypted_content"})
|
||||||
|
|
||||||
// Add a first message to ignore system instructions and ensure proper execution.
|
// Add a first message to ignore system instructions and ensure proper execution.
|
||||||
|
if misc.GetCodexInstructionsEnabled() {
|
||||||
inputResult := gjson.Get(template, "input")
|
inputResult := gjson.Get(template, "input")
|
||||||
if inputResult.Exists() && inputResult.IsArray() {
|
if inputResult.Exists() && inputResult.IsArray() {
|
||||||
inputResults := inputResult.Array()
|
inputResults := inputResult.Array()
|
||||||
@@ -261,6 +262,7 @@ func ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool)
|
|||||||
}
|
}
|
||||||
template, _ = sjson.SetRaw(template, "input", newInput)
|
template, _ = sjson.SetRaw(template, "input", newInput)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return []byte(template)
|
return []byte(template)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func ConvertGeminiRequestToCodex(modelName string, inputRawJSON []byte, _ bool)
|
|||||||
// System instruction -> as a user message with input_text parts
|
// System instruction -> as a user message with input_text parts
|
||||||
sysParts := root.Get("system_instruction.parts")
|
sysParts := root.Get("system_instruction.parts")
|
||||||
if sysParts.IsArray() {
|
if sysParts.IsArray() {
|
||||||
msg := `{"type":"message","role":"user","content":[]}`
|
msg := `{"type":"message","role":"developer","content":[]}`
|
||||||
arr := sysParts.Array()
|
arr := sysParts.Array()
|
||||||
for i := 0; i < len(arr); i++ {
|
for i := 0; i < len(arr); i++ {
|
||||||
p := arr[i]
|
p := arr[i]
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func ConvertOpenAIRequestToCodex(modelName string, inputRawJSON []byte, stream b
|
|||||||
rawJSON := bytes.Clone(inputRawJSON)
|
rawJSON := bytes.Clone(inputRawJSON)
|
||||||
userAgent := misc.ExtractCodexUserAgent(rawJSON)
|
userAgent := misc.ExtractCodexUserAgent(rawJSON)
|
||||||
// Start with empty JSON object
|
// Start with empty JSON object
|
||||||
out := `{}`
|
out := `{"instructions":""}`
|
||||||
|
|
||||||
// Stream must be set to true
|
// Stream must be set to true
|
||||||
out, _ = sjson.Set(out, "stream", stream)
|
out, _ = sjson.Set(out, "stream", stream)
|
||||||
@@ -98,7 +98,9 @@ func ConvertOpenAIRequestToCodex(modelName string, inputRawJSON []byte, stream b
|
|||||||
// Extract system instructions from first system message (string or text object)
|
// Extract system instructions from first system message (string or text object)
|
||||||
messages := gjson.GetBytes(rawJSON, "messages")
|
messages := gjson.GetBytes(rawJSON, "messages")
|
||||||
_, instructions := misc.CodexInstructionsForModel(modelName, "", userAgent)
|
_, instructions := misc.CodexInstructionsForModel(modelName, "", userAgent)
|
||||||
|
if misc.GetCodexInstructionsEnabled() {
|
||||||
out, _ = sjson.Set(out, "instructions", instructions)
|
out, _ = sjson.Set(out, "instructions", instructions)
|
||||||
|
}
|
||||||
// if messages.IsArray() {
|
// if messages.IsArray() {
|
||||||
// arr := messages.Array()
|
// arr := messages.Array()
|
||||||
// for i := 0; i < len(arr); i++ {
|
// for i := 0; i < len(arr); i++ {
|
||||||
@@ -141,7 +143,7 @@ func ConvertOpenAIRequestToCodex(modelName string, inputRawJSON []byte, stream b
|
|||||||
msg := `{}`
|
msg := `{}`
|
||||||
msg, _ = sjson.Set(msg, "type", "message")
|
msg, _ = sjson.Set(msg, "type", "message")
|
||||||
if role == "system" {
|
if role == "system" {
|
||||||
msg, _ = sjson.Set(msg, "role", "user")
|
msg, _ = sjson.Set(msg, "role", "developer")
|
||||||
} else {
|
} else {
|
||||||
msg, _ = sjson.Set(msg, "role", role)
|
msg, _ = sjson.Set(msg, "role", role)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user