Add llm message validate

This commit is contained in:
dwrz
2026-10-11 11:07:41 +00:00
parent 75040646e3
commit c8b7176978
+11
View File
@@ -4,6 +4,7 @@ package llm
import (
"encoding/json/v2"
"fmt"
"strings"
)
@@ -524,6 +525,16 @@ func (m *Message) Text() string {
return b.String()
}
// Validate checks conformance to the OpenAI API specification.
func (m *Message) Validate() error {
if len(m.ToolCalls) != 0 && m.Role != RoleAssistant {
return fmt.Errorf(
"%q message with tool calls", m.Role,
)
}
return nil
}
// UnmarshalJSON decodes a message while normalizing a string-valued content
// field to one text ContentPart. An array-valued content field is decoded in
// order. If reasoning_content is absent, reasoning is copied into