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
db550820
Commit
db550820
authored
Jun 28, 2023
by
Michael Yang
Browse files
interactive generate
parent
52beb0a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
4 deletions
+32
-4
ollama/cmd/cli.py
ollama/cmd/cli.py
+31
-3
ollama/engine.py
ollama/engine.py
+1
-1
No files found.
ollama/cmd/cli.py
View file @
db550820
import
os
import
sys
import
json
from
pathlib
import
Path
from
argparse
import
ArgumentParser
...
...
@@ -20,7 +21,7 @@ def main():
generate_parser
=
subparsers
.
add_parser
(
"generate"
)
generate_parser
.
add_argument
(
"model"
)
generate_parser
.
add_argument
(
"prompt"
)
generate_parser
.
add_argument
(
"prompt"
,
nargs
=
"?"
)
generate_parser
.
set_defaults
(
fn
=
generate
)
add_parser
=
subparsers
.
add_parser
(
"add"
)
...
...
@@ -37,6 +38,8 @@ def main():
try
:
fn
=
args
.
pop
(
"fn"
)
fn
(
**
args
)
except
KeyboardInterrupt
:
pass
except
KeyError
:
parser
.
print_help
()
except
Exception
as
e
:
...
...
@@ -49,12 +52,37 @@ def list_models(*args, **kwargs):
def
generate
(
*
args
,
**
kwargs
):
if
prompt
:
=
kwargs
.
get
(
'prompt'
):
print
(
'>>>'
,
prompt
,
flush
=
True
)
print
(
flush
=
True
)
generate_oneshot
(
*
args
,
**
kwargs
)
print
(
flush
=
True
)
return
return
generate_interactive
(
*
args
,
**
kwargs
)
def
generate_oneshot
(
*
args
,
**
kwargs
):
for
output
in
engine
.
generate
(
*
args
,
**
kwargs
):
output
=
json
.
loads
(
output
)
choices
=
output
.
get
(
"choices"
,
[])
if
len
(
choices
)
>
0
:
print
(
choices
[
0
].
get
(
"text"
,
""
),
end
=
""
)
print
(
choices
[
0
].
get
(
"text"
,
""
),
end
=
""
,
flush
=
True
)
print
()
def
generate_interactive
(
*
args
,
**
kwargs
):
print
(
'>>> '
,
end
=
''
,
flush
=
True
)
for
line
in
sys
.
stdin
:
if
not
sys
.
stdin
.
isatty
():
print
(
line
,
end
=
''
)
print
(
flush
=
True
)
kwargs
.
update
({
'prompt'
:
line
})
generate_oneshot
(
*
args
,
**
kwargs
)
print
(
flush
=
True
)
print
(
'>>> '
,
end
=
''
,
flush
=
True
)
def
add
(
model
,
models_home
):
...
...
ollama/engine.py
View file @
db550820
...
...
@@ -27,7 +27,7 @@ def generate(model, prompt, models_home=".", llms={}, *args, **kwargs):
kwargs
.
update
({
"max_tokens"
:
16384
})
if
"stop"
not
in
kwargs
:
kwargs
.
update
({
"stop"
:
[
"Q:"
,
"
\n
"
]})
kwargs
.
update
({
"stop"
:
[
"Q:"
]})
if
"stream"
not
in
kwargs
:
kwargs
.
update
({
"stream"
:
True
})
...
...
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