parser: remove role validation from Modelfile parser (#9874)

* updates parser/parser.go to allow arbitrary roles in Modelfile MESSAGE blocks
This commit is contained in:
rylativity 2025-03-20 16:11:17 -04:00 committed by GitHub
parent 42a14f7f63
commit ffbfe833da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 16 deletions

View file

@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"net/http"
"os"
"os/user"
@ -300,9 +301,8 @@ const (
)
var (
errMissingFrom = errors.New("no FROM line")
errInvalidMessageRole = errors.New("message role must be one of \"system\", \"user\", or \"assistant\"")
errInvalidCommand = errors.New("command must be one of \"from\", \"license\", \"template\", \"system\", \"adapter\", \"parameter\", or \"message\"")
errMissingFrom = errors.New("no FROM line")
errInvalidCommand = errors.New("command must be one of \"from\", \"license\", \"template\", \"system\", \"adapter\", \"parameter\", or \"message\"")
)
type ParserError struct {
@ -379,14 +379,10 @@ func ParseFile(r io.Reader) (*Modelfile, error) {
case stateParameter:
cmd.Name = b.String()
case stateMessage:
if !isValidMessageRole(b.String()) {
return nil, &ParserError{
LineNumber: currLine,
Msg: errInvalidMessageRole.Error(),
}
}
role = b.String()
if !isKnownMessageRole(b.String()) {
slog.Warn("received non-standard role", "role", role)
}
case stateComment, stateNil:
// pass
case stateValue:
@ -556,7 +552,7 @@ func isNewline(r rune) bool {
return r == '\r' || r == '\n'
}
func isValidMessageRole(role string) bool {
func isKnownMessageRole(role string) bool {
return role == "system" || role == "user" || role == "assistant"
}