Add llm message validate
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user