"src/array/cuda/array_sort.hip" did not exist on "619d735df5dc2a62eca5a00e11e4290407169cb1"
Unverified Commit 00ebda8c authored by Parth Sareen's avatar Parth Sareen Committed by GitHub
Browse files

Revert "parser: remove role validation from Modelfile parser" (#9917)

This reverts commit ffbfe833.
parent d14ce75b
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log/slog"
"net/http" "net/http"
"os" "os"
"os/user" "os/user"
...@@ -301,8 +300,9 @@ const ( ...@@ -301,8 +300,9 @@ const (
) )
var ( var (
errMissingFrom = errors.New("no FROM line") errMissingFrom = errors.New("no FROM line")
errInvalidCommand = errors.New("command must be one of \"from\", \"license\", \"template\", \"system\", \"adapter\", \"parameter\", or \"message\"") 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\"")
) )
type ParserError struct { type ParserError struct {
...@@ -379,10 +379,14 @@ func ParseFile(r io.Reader) (*Modelfile, error) { ...@@ -379,10 +379,14 @@ func ParseFile(r io.Reader) (*Modelfile, error) {
case stateParameter: case stateParameter:
cmd.Name = b.String() cmd.Name = b.String()
case stateMessage: case stateMessage:
role = b.String() if !isValidMessageRole(b.String()) {
if !isKnownMessageRole(b.String()) { return nil, &ParserError{
slog.Warn("received non-standard role", "role", role) LineNumber: currLine,
Msg: errInvalidMessageRole.Error(),
}
} }
role = b.String()
case stateComment, stateNil: case stateComment, stateNil:
// pass // pass
case stateValue: case stateValue:
...@@ -552,7 +556,7 @@ func isNewline(r rune) bool { ...@@ -552,7 +556,7 @@ func isNewline(r rune) bool {
return r == '\r' || r == '\n' return r == '\r' || r == '\n'
} }
func isKnownMessageRole(role string) bool { func isValidMessageRole(role string) bool {
return role == "system" || role == "user" || role == "assistant" return role == "system" || role == "user" || role == "assistant"
} }
......
...@@ -256,13 +256,13 @@ You are a multiline file parser. Always parse things. ...@@ -256,13 +256,13 @@ You are a multiline file parser. Always parse things.
{ {
` `
FROM foo FROM foo
MESSAGE somerandomrole I'm ok with you adding any role message now! MESSAGE badguy I'm a bad guy!
`, `,
[]Command{
{Name: "model", Args: "foo"},
{Name: "message", Args: "somerandomrole: I'm ok with you adding any role message now!"},
},
nil, nil,
&ParserError{
LineNumber: 3,
Msg: errInvalidMessageRole.Error(),
},
}, },
{ {
` `
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment