mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-18 07:07:32 +08:00
fix provider
This commit is contained in:
@@ -141,11 +141,13 @@ func (p *HTTPProvider) callResponses(ctx context.Context, messages []Message, to
|
|||||||
func toResponsesInputItems(msg Message) []map[string]interface{} {
|
func toResponsesInputItems(msg Message) []map[string]interface{} {
|
||||||
role := strings.ToLower(strings.TrimSpace(msg.Role))
|
role := strings.ToLower(strings.TrimSpace(msg.Role))
|
||||||
switch role {
|
switch role {
|
||||||
case "system", "developer", "assistant", "user":
|
case "system", "developer", "user":
|
||||||
return []map[string]interface{}{responsesMessageItem(role, msg.Content)}
|
return []map[string]interface{}{responsesMessageItem(role, msg.Content, "input_text")}
|
||||||
|
case "assistant":
|
||||||
|
return []map[string]interface{}{responsesMessageItem(role, msg.Content, "output_text")}
|
||||||
case "tool":
|
case "tool":
|
||||||
if strings.TrimSpace(msg.ToolCallID) == "" {
|
if strings.TrimSpace(msg.ToolCallID) == "" {
|
||||||
return []map[string]interface{}{responsesMessageItem("user", msg.Content)}
|
return []map[string]interface{}{responsesMessageItem("user", msg.Content, "input_text")}
|
||||||
}
|
}
|
||||||
return []map[string]interface{}{map[string]interface{}{
|
return []map[string]interface{}{map[string]interface{}{
|
||||||
"type": "function_call_output",
|
"type": "function_call_output",
|
||||||
@@ -153,17 +155,21 @@ func toResponsesInputItems(msg Message) []map[string]interface{} {
|
|||||||
"output": msg.Content,
|
"output": msg.Content,
|
||||||
}}
|
}}
|
||||||
default:
|
default:
|
||||||
return []map[string]interface{}{responsesMessageItem("user", msg.Content)}
|
return []map[string]interface{}{responsesMessageItem("user", msg.Content, "input_text")}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func responsesMessageItem(role, text string) map[string]interface{} {
|
func responsesMessageItem(role, text, contentType string) map[string]interface{} {
|
||||||
|
ct := strings.TrimSpace(contentType)
|
||||||
|
if ct == "" {
|
||||||
|
ct = "input_text"
|
||||||
|
}
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"type": "message",
|
"type": "message",
|
||||||
"role": role,
|
"role": role,
|
||||||
"content": []map[string]interface{}{
|
"content": []map[string]interface{}{
|
||||||
{
|
{
|
||||||
"type": "input_text",
|
"type": ct,
|
||||||
"text": text,
|
"text": text,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -523,7 +529,7 @@ func (p *HTTPProvider) BuildSummaryViaResponsesCompact(ctx context.Context, mode
|
|||||||
}
|
}
|
||||||
input := make([]map[string]interface{}, 0, len(messages)+1)
|
input := make([]map[string]interface{}, 0, len(messages)+1)
|
||||||
if strings.TrimSpace(existingSummary) != "" {
|
if strings.TrimSpace(existingSummary) != "" {
|
||||||
input = append(input, responsesMessageItem("system", "Existing summary:\n"+strings.TrimSpace(existingSummary)))
|
input = append(input, responsesMessageItem("system", "Existing summary:\n"+strings.TrimSpace(existingSummary), "input_text"))
|
||||||
}
|
}
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
input = append(input, toResponsesInputItems(msg)...)
|
input = append(input, toResponsesInputItems(msg)...)
|
||||||
|
|||||||
@@ -117,6 +117,24 @@ func TestEndpointForResponsesCompact(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestToResponsesInputItems_AssistantUsesOutputText(t *testing.T) {
|
||||||
|
items := toResponsesInputItems(Message{
|
||||||
|
Role: "assistant",
|
||||||
|
Content: "hello",
|
||||||
|
})
|
||||||
|
if len(items) != 1 {
|
||||||
|
t.Fatalf("expected 1 item, got %d", len(items))
|
||||||
|
}
|
||||||
|
content, ok := items[0]["content"].([]map[string]interface{})
|
||||||
|
if !ok || len(content) == 0 {
|
||||||
|
t.Fatalf("unexpected content shape: %#v", items[0]["content"])
|
||||||
|
}
|
||||||
|
gotType, _ := content[0]["type"].(string)
|
||||||
|
if gotType != "output_text" {
|
||||||
|
t.Fatalf("assistant content type = %q, want output_text", gotType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func containsFunctionCallMarkup(s string) bool {
|
func containsFunctionCallMarkup(s string) bool {
|
||||||
return len(s) > 0 && (strings.Contains(s, "<function_call>") || strings.Contains(s, "</function_call>"))
|
return len(s) > 0 && (strings.Contains(s, "<function_call>") || strings.Contains(s, "</function_call>"))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user