Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
4d083635
Commit
4d083635
authored
Apr 26, 2024
by
Michael Yang
Browse files
comments
parent
8907bf51
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
2 deletions
+6
-2
parser/parser.go
parser/parser.go
+6
-2
No files found.
parser/parser.go
View file @
4d083635
...
@@ -53,22 +53,26 @@ func Parse(r io.Reader) (cmds []Command, err error) {
...
@@ -53,22 +53,26 @@ func Parse(r io.Reader) (cmds []Command, err error) {
return
nil
,
err
return
nil
,
err
}
}
// process the state transition, some transitions need to be intercepted and redirected
if
next
!=
curr
{
if
next
!=
curr
{
switch
curr
{
switch
curr
{
case
stateName
,
stateParameter
:
case
stateName
,
stateParameter
:
// next state sometimes depends on the current buffer value
switch
s
:=
strings
.
ToLower
(
b
.
String
());
s
{
switch
s
:=
strings
.
ToLower
(
b
.
String
());
s
{
case
"from"
:
case
"from"
:
cmd
.
Name
=
"model"
cmd
.
Name
=
"model"
case
"parameter"
:
case
"parameter"
:
// transition to stateParameter which sets command name
next
=
stateParameter
next
=
stateParameter
case
"message"
:
case
"message"
:
// transition to stateMessage which validates the message role
next
=
stateMessage
next
=
stateMessage
fallthrough
fallthrough
default
:
default
:
cmd
.
Name
=
s
cmd
.
Name
=
s
}
}
case
stateMessage
:
case
stateMessage
:
if
!
isValidRole
(
b
.
String
())
{
if
!
isValid
Message
Role
(
b
.
String
())
{
return
nil
,
errInvalidRole
return
nil
,
errInvalidRole
}
}
...
@@ -234,6 +238,6 @@ func isNewline(r rune) bool {
...
@@ -234,6 +238,6 @@ func isNewline(r rune) bool {
return
r
==
'\r'
||
r
==
'\n'
return
r
==
'\r'
||
r
==
'\n'
}
}
func
isValidRole
(
role
string
)
bool
{
func
isValid
Message
Role
(
role
string
)
bool
{
return
role
==
"system"
||
role
==
"user"
||
role
==
"assistant"
return
role
==
"system"
||
role
==
"user"
||
role
==
"assistant"
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment