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
f5f79049
Commit
f5f79049
authored
Jul 25, 2023
by
Mohit Gaur
Browse files
Incorporate code review improvements
parent
ed89da92
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
parser/parser.go
parser/parser.go
+8
-6
No files found.
parser/parser.go
View file @
f5f79049
...
@@ -2,14 +2,12 @@ package parser
...
@@ -2,14 +2,12 @@ package parser
import
(
import
(
"bufio"
"bufio"
"bytes"
"errors"
"errors"
"fmt"
"fmt"
"io"
"io"
"strings"
)
)
const
multilineString
=
`"""`
type
Command
struct
{
type
Command
struct
{
Name
string
Name
string
Args
string
Args
string
...
@@ -34,21 +32,23 @@ func Parse(reader io.Reader) ([]Command, error) {
...
@@ -34,21 +32,23 @@ func Parse(reader io.Reader) ([]Command, error) {
continue
continue
}
}
switch
strings
.
ToUpper
(
string
(
fields
[
0
]))
{
switch
string
(
byte
s
.
ToUpper
(
fields
[
0
]))
{
case
"FROM"
:
case
"FROM"
:
command
.
Name
=
"model"
command
.
Name
=
"model"
command
.
Args
=
string
(
fields
[
1
])
command
.
Args
=
string
(
fields
[
1
])
// copy command for validation
// copy command for validation
modelCommand
=
command
modelCommand
=
command
case
"LICENSE"
,
"TEMPLATE"
,
"SYSTEM"
,
"PROMPT"
:
case
"LICENSE"
,
"TEMPLATE"
,
"SYSTEM"
,
"PROMPT"
:
command
.
Name
=
strings
.
ToLower
(
string
(
fields
[
0
]))
command
.
Name
=
string
(
byte
s
.
ToLower
(
fields
[
0
]))
command
.
Args
=
string
(
fields
[
1
])
command
.
Args
=
string
(
fields
[
1
])
case
"PARAMETER"
:
case
"PARAMETER"
:
fields
=
bytes
.
SplitN
(
fields
[
1
],
[]
byte
(
" "
),
2
)
fields
=
bytes
.
SplitN
(
fields
[
1
],
[]
byte
(
" "
),
2
)
command
.
Name
=
string
(
fields
[
0
])
command
.
Name
=
string
(
fields
[
0
])
command
.
Args
=
string
(
fields
[
1
])
command
.
Args
=
string
(
fields
[
1
])
default
:
default
:
return
nil
,
fmt
.
Errorf
(
"unknown command: %s"
,
fields
[
0
])
// log a warning for unknown commands
fmt
.
Printf
(
"WARNING: Unknown command: %s
\n
"
,
fields
[
0
])
continue
}
}
commands
=
append
(
commands
,
command
)
commands
=
append
(
commands
,
command
)
...
@@ -63,6 +63,8 @@ func Parse(reader io.Reader) ([]Command, error) {
...
@@ -63,6 +63,8 @@ func Parse(reader io.Reader) ([]Command, error) {
}
}
func
scanModelfile
(
data
[]
byte
,
atEOF
bool
)
(
advance
int
,
token
[]
byte
,
err
error
)
{
func
scanModelfile
(
data
[]
byte
,
atEOF
bool
)
(
advance
int
,
token
[]
byte
,
err
error
)
{
const
multilineString
=
`"""`
newline
:=
bytes
.
IndexByte
(
data
,
'\n'
)
newline
:=
bytes
.
IndexByte
(
data
,
'\n'
)
if
start
:=
bytes
.
Index
(
data
,
[]
byte
(
multilineString
));
start
>=
0
&&
start
<
newline
{
if
start
:=
bytes
.
Index
(
data
,
[]
byte
(
multilineString
));
start
>=
0
&&
start
<
newline
{
...
...
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