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
af98a177
Commit
af98a177
authored
Aug 14, 2023
by
Bruce MacDonald
Browse files
update python example
parent
648f0974
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
6 deletions
+4
-6
examples/python/client.py
examples/python/client.py
+4
-6
No files found.
doc
s/python/
examples/
client.py
→
example
s/python/client.py
View file @
af98a177
...
@@ -3,10 +3,8 @@ import requests
...
@@ -3,10 +3,8 @@ import requests
# NOTE: ollama must be running for this to work, start the ollama app or run `ollama serve`
# NOTE: ollama must be running for this to work, start the ollama app or run `ollama serve`
model
=
'llama2'
# TODO: update this for whatever model you wish to use
model
=
'llama2'
# TODO: update this for whatever model you wish to use
context
=
[]
# the context stores a conversation history, you can use this to make the model more context aware
def
generate
(
prompt
):
def
generate
(
prompt
,
context
):
global
context
r
=
requests
.
post
(
'http://localhost:11434/api/generate'
,
r
=
requests
.
post
(
'http://localhost:11434/api/generate'
,
json
=
{
json
=
{
'model'
:
model
,
'model'
:
model
,
...
@@ -26,14 +24,14 @@ def generate(prompt):
...
@@ -26,14 +24,14 @@ def generate(prompt):
raise
Exception
(
body
[
'error'
])
raise
Exception
(
body
[
'error'
])
if
body
.
get
(
'done'
,
False
):
if
body
.
get
(
'done'
,
False
):
context
=
body
[
'context'
]
return
body
[
'context'
]
return
def
main
():
def
main
():
context
=
[]
# the context stores a conversation history, you can use this to make the model more context aware
while
True
:
while
True
:
user_input
=
input
(
"Enter a prompt: "
)
user_input
=
input
(
"Enter a prompt: "
)
print
()
print
()
generate
(
user_input
)
context
=
generate
(
user_input
,
context
)
print
()
print
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
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