mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-02 20:40:52 +08:00
Compare commits
1 Commits
adedb16d35
...
v3.0.5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88ca21380b |
@@ -94,9 +94,10 @@ func ConvertOpenAIChatRequestToCli(rawJSON []byte) (string, *client.Content, []c
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
switch roleResult.String() {
|
role := roleResult.String()
|
||||||
|
|
||||||
|
if role == "system" && len(messagesResults) > 1 {
|
||||||
// System messages are converted to a user message followed by a model's acknowledgment.
|
// System messages are converted to a user message followed by a model's acknowledgment.
|
||||||
case "system":
|
|
||||||
if contentResult.Type == gjson.String {
|
if contentResult.Type == gjson.String {
|
||||||
systemInstruction = &client.Content{Role: "user", Parts: []client.Part{{Text: contentResult.String()}}}
|
systemInstruction = &client.Content{Role: "user", Parts: []client.Part{{Text: contentResult.String()}}}
|
||||||
} else if contentResult.IsObject() {
|
} else if contentResult.IsObject() {
|
||||||
@@ -105,8 +106,8 @@ func ConvertOpenAIChatRequestToCli(rawJSON []byte) (string, *client.Content, []c
|
|||||||
systemInstruction = &client.Content{Role: "user", Parts: []client.Part{{Text: contentResult.Get("text").String()}}}
|
systemInstruction = &client.Content{Role: "user", Parts: []client.Part{{Text: contentResult.Get("text").String()}}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if role == "user" || (role == "system" && len(messagesResults) == 1) { // If there's only a system message, treat it as a user message.
|
||||||
// User messages can contain simple text or a multi-part body.
|
// User messages can contain simple text or a multi-part body.
|
||||||
case "user":
|
|
||||||
if contentResult.Type == gjson.String {
|
if contentResult.Type == gjson.String {
|
||||||
contents = append(contents, client.Content{Role: "user", Parts: []client.Part{{Text: contentResult.String()}}})
|
contents = append(contents, client.Content{Role: "user", Parts: []client.Part{{Text: contentResult.String()}}})
|
||||||
} else if contentResult.IsArray() {
|
} else if contentResult.IsArray() {
|
||||||
@@ -151,9 +152,10 @@ func ConvertOpenAIChatRequestToCli(rawJSON []byte) (string, *client.Content, []c
|
|||||||
}
|
}
|
||||||
contents = append(contents, client.Content{Role: "user", Parts: parts})
|
contents = append(contents, client.Content{Role: "user", Parts: parts})
|
||||||
}
|
}
|
||||||
|
} else if role == "assistant" {
|
||||||
// Assistant messages can contain text responses or tool calls
|
// Assistant messages can contain text responses or tool calls
|
||||||
// In the internal format, assistant messages are converted to "model" role
|
// In the internal format, assistant messages are converted to "model" role
|
||||||
case "assistant":
|
|
||||||
if contentResult.Type == gjson.String {
|
if contentResult.Type == gjson.String {
|
||||||
// Simple text response from the assistant
|
// Simple text response from the assistant
|
||||||
contents = append(contents, client.Content{Role: "model", Parts: []client.Part{{Text: contentResult.String()}}})
|
contents = append(contents, client.Content{Role: "model", Parts: []client.Part{{Text: contentResult.String()}}})
|
||||||
|
|||||||
Reference in New Issue
Block a user